コード例 #1
0
ファイル: examples.py プロジェクト: Anton495/peano
def get_morton_curve():
    chain_code = 'i','Ij','i'
    bases = ['ij'] * 4
    return FractalCurve(
        proto=chain2proto(chain_code),
        base_maps=[basis2base_map(b) for b in bases],
    )
コード例 #2
0
    def test_junc(self):
        for num, curve in enumerate(self.curves):
            if num == 0:
                pcurve = curve.forget(allow_time_rev=True)
            else:
                pcurve = curve.forget()

            junc_info = pcurve.get_junctions_info()
            for junc in junc_info:
                if any(dx not in set([0, 1, -1]) for dx in junc.delta_x):
                    raise Exception("Bad delta!")

            for curve in FractalCurve.gen_possible_curves(pcurve):
                juncs = curve.get_junctions()
                # проверяем, что для каждого найденного стыка есть порождающая кривая
                for junc in juncs:
                    if junc not in junc_info:
                        raise Exception("Unknown junc!")
                    if not any(
                            curve.is_specialization(tmpl)
                            for tmpl in junc_info[junc]):
                        raise Exception("Can't found consistent curve!")

                # проверяем, что для каждого не найденного стыка нет порождающих кривых
                for junc, curves in junc_info.items():
                    if junc in juncs:
                        continue
                    if any(
                            curve.is_specialization(tmpl)
                            for tmpl in junc_info[junc]):
                        raise Exception(
                            "Found consistent curve for wrong junc!")
コード例 #3
0
ファイル: examples.py プロジェクト: Anton495/peano
def get_serpentine_curve():

    chain_code = 'jjiJJijj'
    bases = ['ij','Ji','ji','iJ','JI','iJ','ji','Ji','ij']
    return FractalCurve(
        proto=chain2proto(chain_code),
        base_maps=[basis2base_map(b) for b in bases],
    )
コード例 #4
0
ファイル: examples.py プロジェクト: Anton495/peano
def get_tokarev_curve():
    """3-D curve."""
    chain_code = 'kjKikJK'
    bases = ['jki', 'kij', 'kij', 'iJK', 'iJK', 'KIj', 'KIj', 'JkI']
    return FractalCurve(
        proto=chain2proto(chain_code),
        base_maps=[basis2base_map(b) for b in bases],
    )
コード例 #5
0
ファイル: examples.py プロジェクト: Anton495/peano
def get_haverkort_curve_2():
    """3-D curve with time reversal."""
    chain_code = 'kjKikJK'
    bases = ['KIJ1','KJI1','KjI0','Jki1','jki0','kjI1','kJI0','iKJ0']
    return FractalCurve(
        proto=chain2proto(chain_code),
        base_maps=[basis2base_map(b) for b in bases],
    )
コード例 #6
0
ファイル: examples.py プロジェクト: Anton495/peano
def get_coil_curve():

    chain_code = 'jjiJJijj'
    bases = ['ji','Ji','ji','jI','JI','jI','ji','Ji','ji']
    return FractalCurve(
        proto=chain2proto(chain_code),
        base_maps=[basis2base_map(b) for b in bases],
    )
コード例 #7
0
ファイル: examples.py プロジェクト: Anton495/peano
def get_haverkort_curve_1():
    """3-D curve with time reversal."""
    chain_code = 'kjKikJK'
    bases = ['kji0','jik0','kIj1','iKJ0','IKJ1','KIj0','Kij1','Jki1']
    return FractalCurve(
        proto=chain2proto(chain_code),
        base_maps=[basis2base_map(b) for b in bases],
    )
コード例 #8
0
ファイル: examples.py プロジェクト: Anton495/peano
def get_R_curve():

    chain_code = 'jjiiJIJi'
    bases = ['ji','ji','ij','ij','ij','IJ','JI','JI','ij']
    return FractalCurve(
        proto=chain2proto(chain_code),
        base_maps=[basis2base_map(b) for b in bases],
    )
コード例 #9
0
ファイル: examples.py プロジェクト: Anton495/peano
def get_rev3_curve():
    """Curve with time reversal at last cube."""
    return FractalCurve(
        proto=[(0, 0), (0, 1), (1, 1), (1, 0)],
        base_maps=[
            BaseMap([1, 0], [False, False]),                # (x,y)->(y,x)
            BaseMap.id_map(2),                              # (x,y)->(x,y)
            BaseMap.id_map(2),                              # (x,y)->(x,y)
            BaseMap([1, 0], [True, False], time_rev=True),  # (x,y)->(1-y,x), t->1-t
        ],
    )
コード例 #10
0
ファイル: examples.py プロジェクト: Anton495/peano
def get_hilbert_curve():
    """Example of fractal curve due to D.Hilbert."""
    return FractalCurve(
        proto=[(0, 0), (0, 1), (1, 1), (1, 0)],
        base_maps=[
            BaseMap([1, 0], [False, False]),  # (x,y)->(y,x)
            BaseMap.id_map(2),                # (x,y)->(x,y)
            BaseMap.id_map(2),                # (x,y)->(x,y)
            BaseMap([1, 0], [True, True]),    # (x,y)->(1-y,1-x)
        ],
    )
コード例 #11
0
    def test_curves(self):
        for curve in self.curves:
            pcurve = curve.forget()
            rrcurve = pcurve.reverse().reverse()
            self.assertEqual(pcurve.proto, rrcurve.proto)
            self.assertEqual(pcurve.bm_info(), rrcurve.bm_info())

        for curve in self.curves:
            pcurve = curve.forget(allow_time_rev=True)
            cnum = 0
            for bm in pcurve.gen_allowed_maps(cnum):
                scurve = pcurve.specify(cnum, bm)
                piece = scurve.get_fraction(cnum)

        curve0 = self.curves[0].forget()
        for c in FractalCurve.gen_possible_curves(curve0):
            c.check()

        curve0 = self.curves[0].forget(allow_time_rev=True)
        for c in FractalCurve.gen_possible_curves(curve0):
            c.check()
コード例 #12
0
ファイル: gen-partial.py プロジェクト: Anton495/peano
def bauman():
    proto = ((0, 0), (0, 1), (0, 2), (1, 2), (1, 1), (1, 0), (2, 0), (2, 1),
             (2, 2))
    base_maps = [
        BaseMap(perm=[1, 0], flip=[False, False]),
        BaseMap(perm=[1, 0], flip=[True, False]),
        BaseMap.id_map(dim=2),
        BaseMap(perm=[1, 0], flip=[False, True]),
        BaseMap(perm=[1, 0], flip=[True, True]),
        BaseMap(perm=[0, 1], flip=[False, True]),
        BaseMap(perm=[1, 0], flip=[False, False]),
        BaseMap(perm=[1, 0], flip=[True, False]),
        BaseMap.id_map(dim=2),
    ]
    bauman = FractalCurve(dim=2, div=3, proto=proto, base_maps=base_maps)
    bauman.estimate_ratio_vertex_brkline(ratio_l2, 3)

    #good.estimate_ratio(ratio, rel_tol=0.002, verbose=1)
    bauman = bauman.get_subdivision(1)
    pcurve = bauman.forget()
    pcurve = pcurve.changed(allow_time_rev=True)
    pcurve.estimate_ratio(ratio_l2,
                          lower_bound=32.2,
                          upper_bound=32.1,
                          sat_pack=1000,
                          find_model=True)
コード例 #13
0
ファイル: examples.py プロジェクト: Anton495/peano
def get_peano_curve():
    """Example of fractal curve due to G.Peano."""
    id_map = BaseMap.id_map(2)
    x_map = BaseMap([0, 1], [True, False])  # (x,y)->(1-x,y)
    y_map = BaseMap([0, 1], [False, True])  # (x,y)->(x,1-y)
    xy_map = BaseMap([0, 1], [True, True])  # (x,y)->(1-x,1-y)
    return FractalCurve(
        proto=[(0, 0), (0, 1), (0, 2), (1, 2), (1, 1), (1, 0), (2, 0), (2, 1), (2, 2)],
        base_maps=[
            id_map, x_map, id_map,
            y_map, xy_map, y_map,
            id_map, x_map, id_map,
        ],
    )
コード例 #14
0
ファイル: examples.py プロジェクト: Anton495/peano
def get_haverkort_curve_A26():
    """3-D curve with time reversal."""
    proto = [(0,0,0), (0,0,1), (0,1,1), (0,1,0), (1,1,0), (1,1,1), (1,0,1), (1,0,0)]
    base_maps = [
        BaseMap([2, 1, 0], [False, False, False]),
        BaseMap([2, 0, 1], [False, False, False]),
        BaseMap([2, 0, 1], [False, True, False], time_rev=True),
        BaseMap([0, 2, 1], [False, True, True]),
        BaseMap([0, 2, 1], [True, True, True], time_rev=True),
        BaseMap([2, 0, 1], [True, True, False]),
        BaseMap([2, 0, 1], [True, False, False], time_rev=True),
        BaseMap([1, 2, 0], [True, False, False], time_rev=True),
    ]
    return FractalCurve(
        proto=proto,
        base_maps=base_maps,
    )
コード例 #15
0
    def test_curves(self):
        for pcurve in self.curves:
            for curve in FractalCurve.gen_possible_curves(pcurve):
                adapter = CurveSATAdapter(dim=pcurve.dim)
                adapter.init_curve(pcurve)
                model = adapter.get_model_from_curve(curve)
                juncs = curve.get_junctions()
                for junc in juncs:
                    junc_var = adapter.get_junc_var(junc)
                    if not model[junc_var]:
                        raise Exception("Bad junc_var: False for existent junc!")
#                for junc in junc_info:
#                    if junc not in juncs:
#                        junc_var = adapter.get_junc_var(junc)
#                        if model[junc_var]:
#                            raise Exception("Bad junc_var: True for non-existent junc!")
                print('.', end='', flush=True)

            print('*', flush=True)
コード例 #16
0
ファイル: examples.py プロジェクト: Anton495/peano
def get_scepin_bauman_curve():
    proto = (
        (0, 0), (0, 1), (0, 2),
        (1, 2), (1, 1), (1, 0),
        (2, 0), (2, 1), (2, 2),
    )
    base_maps = [
        BaseMap.id_map(dim=2),
        BaseMap([1,0],[True,False]),  # rot(90)
        BaseMap([1,0],[False,False]),  # (x,y)->(y,x)

        BaseMap([0,1],[False,True]),  # (x,y)->(x,1-y)
        BaseMap([1,0],[True,True]),  # (x,y)->(1-y,1-x)
        BaseMap([1,0],[False,True]),  # rot(-90)

        BaseMap.id_map(dim=2),
        BaseMap(perm=[1,0],flip=[True,False]),  # rot(90)
        BaseMap(perm=[1,0],flip=[False,False]),  # (x,y)->(y,x)
    ]
    return FractalCurve(dim=2, div=3, proto=proto, base_maps=base_maps)
コード例 #17
0
    def generate_curves_for_brkline(self, brkline):
        global_entrance = (0, ) * self.dim
        global_exit = self.exit
        bms_variants = []
        proto = []
        for cube, entrance, exit in brkline:
            constr = {
                global_entrance: entrance,
                global_exit: exit,
            }
            bms_for_cube = base_map.gen_constraint_base_maps(self.dim, constr)
            if self.oriented:
                bms_for_cube = (bm for bm in bms_for_cube if bm.is_oriented())
            bms_variants.append(bms_for_cube)
            proto.append(cube)

        for bms in itertools.product(*bms_variants):
            curve = FractalCurve(dim=self.dim,
                                 div=self.div,
                                 proto=proto,
                                 base_maps=bms)
            yield curve
コード例 #18
0
ファイル: examples.py プロジェクト: Anton495/peano
def get_peano5_curve():
    id_map = BaseMap.id_map(2)
    x_map = BaseMap([0, 1], [True, False])  # (x,y)->(1-x,y)
    y_map = BaseMap([0, 1], [False, True])  # (x,y)->(x,1-y)
    xy_map = BaseMap([0, 1], [True, True])  # (x,y)->(1-x,1-y)
    return FractalCurve(
        dim=2, div=5,
        proto=[
            (0, 0), (0, 1), (0, 2), (0, 3), (0, 4),
            (1, 4), (1, 3), (1, 2), (1, 1), (1, 0),
            (2, 0), (2, 1), (2, 2), (2, 3), (2, 4),
            (3, 4), (3, 3), (3, 2), (3, 1), (3, 0),
            (4, 0), (4, 1), (4, 2), (4, 3), (4, 4),
        ],
        base_maps=[
            id_map, x_map, id_map, x_map, id_map,
            y_map, xy_map, y_map, xy_map, y_map,
            id_map, x_map, id_map, x_map, id_map,
            y_map, xy_map, y_map, xy_map, y_map,
            id_map, x_map, id_map, x_map, id_map,
        ],
    )
コード例 #19
0
ファイル: gen-partial.py プロジェクト: Anton495/peano
def pristalno():
    proto = [
        (0, 0),
        (1, 0),
        (1, 1),
        (0, 1),
        (0, 2),
        (1, 2),
        (1, 3),
        (0, 3),
        (0, 4),
        (1, 4),
        (2, 4),
        (2, 3),
        (3, 3),
        (3, 4),
        (4, 4),
        (4, 3),
        (4, 2),
        (3, 2),
        (2, 2),
        (2, 1),
        (2, 0),
        (3, 0),
        (3, 1),
        (4, 1),
        (4, 0),
    ]
    bmstrs = [
        '(x,y)->(x,y)',
        '(x,y)->(y,1-x),t->1-t',
        '(x,y)->(y,1-x),t->1-t',
        '(x,y)->(1-x,1-y)',
        '(x,y)->(x,y)',
        '(x,y)->(y,1-x),t->1-t',
        '(x,y)->(y,1-x),t->1-t',
        '(x,y)->(1-x,1-y)',
        '(x,y)->(x,y)',
        '(x,y)->(x,y)',
        '(x,y)->(x,y)',
        '(x,y)->(1-y,x),t->1-t',
        '(x,y)->(y,1-x),t->1-t',
        '(x,y)->(x,y)',
        '(x,y)->(x,y)',
        '(x,y)->(1-y,x),t->1-t',
        '(x,y)->(1-x,1-y)',
        '(x,y)->(1-x,1-y)',
        '(x,y)->(1-y,x),t->1-t',
        '(x,y)->(1-y,x),t->1-t',
        '(x,y)->(1-y,x),t->1-t',
        '(x,y)->(y,1-x),t->1-t',
        '(x,y)->(x,y)',
        '(x,y)->(x,y)',
        '(x,y)->(1-y,x),t->1-t',
    ]
    base_maps = [bmstr2base_map(x) for x in bmstrs]

    curve = FractalCurve(dim=2, div=5, proto=proto, base_maps=base_maps)
    curve.check()
    print(curve.get_junctions())
    print('entr:', curve.get_entrance())
    print('exit:', curve.get_exit())

    curve.estimate_ratio_new(ratio_l2, rel_tol=0.001, max_iter=1000)

    pcurve = curve.forget()
    pcurve.allow_time_rev = True
    result = pcurve.estimate_ratio(ratio_l2,
                                   lower_bound=31.2,
                                   upper_bound=31.3,
                                   find_model=True)
    if result:
        print('found:', result.proto, result.base_maps)
    else:
        print('NOT FOUND')
コード例 #20
0
ファイル: examples.py プロジェクト: Anton495/peano
def get_discontinuous_curve():
    return FractalCurve(
        proto=[(1, 1), (0, 1), (0, 0), (1, 0), (2, 0), (2, 1), (2, 2), (1, 2), (0, 2)],
        base_maps=[BaseMap.id_map(2)] * 9,
    )