Ejemplo n.º 1
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)
Ejemplo n.º 2
0
    def test_one_seg_belt(self):
        sbelt = SegmentedBelt()
        sbelt.fix_ends(source=(10, 10), sink=(15, 10))
        SOL.add(sbelt.num_segs == 1)
        m = SOL.model()
        self.assertIsNotNone(m)

        s = sbelt.segment(0)
        self.assertEqual(s.p1.eval_as_tuple(), (10,10))
        self.assertEqual(s.p2.eval_as_tuple(), (15,10))
Ejemplo n.º 3
0
    def test_two_seg_belt(self):
        sbelt = SegmentedBelt()
        sbelt.fix_ends(source=(10, 10), sink=(15, 15))
        SOL.add(sbelt.num_segs == 2)
        m = SOL.model()
        self.assertIsNotNone(m)

        s = sbelt.segment(0)
        p1 = s.p1
        p2 = s.p2

        self.assertEqual(p1.eval_as_tuple(), (10,10))
        self.assertTrue(p2.eval_as_tuple() in [(15,10), (10,15)])

        s = sbelt.segment(1)
        p2 = s.p2
        self.assertEqual(p2.eval_as_tuple(), (15,15))
Ejemplo n.º 4
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