Esempio n. 1
0
    def test_three_seg_belts(self):
        """ There segmented belts crossing each other if drawn straight.
        Total length is minified by iterative tightening of constaint """

        belt1 = SegmentedBelt()
        belt2 = SegmentedBelt()
        belt3 = SegmentedBelt()

        SOL.add(non_intersecting_seg_belts(belt1, belt2))
        SOL.add(non_intersecting_seg_belts(belt1, belt3))
        SOL.add(non_intersecting_seg_belts(belt2, belt3))

        belt1.fix_ends((0,0), (20, 20))
        belt2.fix_ends((0,10), (20, 10))
        belt3.fix_ends((0,20), (20, 0))

        sz = IntVal()
        SOL.add(sz.v == belt1.num_segs + belt2.num_segs + belt3.num_segs)

        t0 = time()
        dts = []
        sizes = []

        for cur_sz in SOL.shrinker_loop(sz, init=38, restore=False):
            t1 = time()
            dts.append(t1 - t0)
            t0 = time()
            sizes.append(cur_sz)

        self.assertGreater(len(sizes), 0)
        self.assertEqual(9, sizes[-1])  # number got from experiments with visualization
Esempio n. 2
0
 def test_seg_belt_shrink(self):
     sbelt = SegmentedBelt()
     sbelt.fix_ends(source=(10,10), sink=(15,15))
     seg_nums = []
     for l in SOL.shrinker_loop(sbelt.num_segs, init=10):
         seg_nums.append(l)
     self.assertEqual(seg_nums[-1], 2)
Esempio n. 3
0
    def test_three_belts(self):
        """ Three belts crossing each other if drawn straight. Minifying total length """
        belt1 = Belt()
        belt2 = Belt()
        belt3 = Belt()

        SOL.add(no_intersections(belt1, belt2))
        SOL.add(no_intersections(belt1, belt3))
        SOL.add(no_intersections(belt2, belt3))

        belt1.fix_ends((0, 0), (4, 4))
        belt2.fix_ends((0, 2), (4, 2))
        belt3.fix_ends((0, 4), (4, 0))

        sz = IntVal()
        SOL.add(sz.v == belt1.belt_len + belt2.belt_len + belt3.belt_len)

        t0 = time()
        dts = []
        sizes = []
        for cur_sz in SOL.shrinker_loop(sz, init=38, restore=False):
            t1 = time()
            dts.append(t1 - t0)
            t0 = time()

            sizes.append(cur_sz)

        self.assertGreater(len(sizes), 0)
        self.assertEqual(sizes[-1], 29)  # number got from experiments with visualization
Esempio n. 4
0
 def test_seg_belt_contains(self):
     sb = SegmentedBelt()
     SOL.add(sb.contains(Point2D(0, 0)))
     SOL.add(sb.contains(Point2D(10, 10)))
     d = None
     for d in SOL.shrinker_loop(sb.num_segs):
         pass
     self.assertEqual(2, d)
Esempio n. 5
0
    def test_belt_shrink(self):
        belt = Belt()
        belt.fix_ends(source=(1,1), sink=(5,5))
        lens = []
        for l in SOL.shrinker_loop(belt.belt_len):
            lens.append(l)

        self.assertEqual(lens[-1], 9)
Esempio n. 6
0
    def test_shrinker(self):
        p1 = Point2D()
        dst = IntVal()
        SOL.add(dst.v == Abs(p1.x - 2) + Abs(p1.y - 3))
        dists = []
        for d in SOL.shrinker_loop(dst):
            dists.append(d)

        p1c = p1.eval_as_tuple()
        self.assertEqual(dists[-1], 0)
        self.assertEqual(p1c, (2,3))
Esempio n. 7
0
    def test_unit_inserter_connection(self):
        in1 = Inserter(unit_len_only=True)
        in2 = Inserter(unit_len_only=True)
        disp = IntVal()

        SOL.add(in1.source() == (0,0))
        SOL.add(in1.sink() == in2.source())
        x2 = in2.sink().x
        SOL.add(disp.v == -z3.If(x2 > 0, x2, -x2))

        for res in SOL.shrinker_loop(disp.v):
            pass
        self.assertEqual(-4, res)
Esempio n. 8
0
    def test_long_inserter_connection(self):
        in1 = Inserter(unit_len_only=False)
        in2 = Inserter(unit_len_only=False)
        disp = IntVal()

        SOL.add(in1.source() == (0, 0))
        SOL.add(in1.sink() == in2.source())
        x2 = in2.sink().x
        SOL.add(disp.v == -z3.If(x2 > 0, x2, -x2))

        for res in SOL.shrinker_loop(disp.v):
            pass
        print('arm', in1.arm_len.eval())
        self.assertEqual(-8, res)
Esempio n. 9
0
 def test_intersecting_segbelt_and_dseg(self):
     sb = SegmentedBelt()
     SOL.add(sb.corner(0) == Point2D(0, 0))
     SOL.add(sb.corner(1) == Point2D(10, 0))
     SOL.add(sb.sink() == Point2D(20, 0))
     SOL.add(sb.num_segs >= 2)
     ds = Segment(Point2D(), Point2D(), is_diag=True)
     SOL.add(ds.p1 == Point2D(12, 0))
     SOL.add(ds.p2 == Point2D(15, 3))
     SOL.add(non_intersecting_seg_belt_diag_seg(sb, ds))
     d = None
     for d in SOL.shrinker_loop(sb.num_segs):
         pass
     self.assertEqual(4, d)
Esempio n. 10
0
    def test_seg_belt_enumerate(self):
        sb = SegmentedBelt()
        SOL.add(sb.source() == (0,0))
        SOL.add(sb.sink() == (5,5))
        SOL.add(sb.num_segs < 5)
        ln = sb.len(5)

        for d in SOL.shrinker_loop(ln):
            pass

        self.assertEqual(11, d)

        p0 = None
        for p in sb.enumerate_points():
            if p0:
                dx = p.x - p0.x
                dy = p.y - p0.y
                self.assertTrue(dx == 0 and dy == 1 or dx == 1 and dy == 0)
            p0 = p