예제 #1
0
 def test_extract_02(self):
     p = Point(0, 0)
     p_list = point.extract(p, 1, d_min=1)
     exp = [Point(-1, 0), Point(0, -1), Point(1, 0), Point(0, 1)]
     self.assertEqual(4, len(p_list))
     for ep in exp:
         self.assertTrue(ep in p_list)
예제 #2
0
 def test_cross(self):
     # 表示用
     from simulator.oldmodels import Point
     from simulator.dataset import devices
     ds = devices.cross(Point(0, 0), Point(30, 30), 30, r_num=4, density=2)
     print([d.plan[0] for d in ds])
     print([d.use_resource for d in ds])
     print([d.startup_time for d in ds])
예제 #3
0
 def test_scope_01(self):
     from simulator.oldmodels import Point
     p1 = Point(2, 2)
     scp = oldutility.scope(p1,
                            distance_min=0,
                            distance_max=0,
                            x_max=100,
                            x_min=-100,
                            y_max=100,
                            y_min=-100)
     self.assertEqual(1, len(scp), msg=scp)
     self.assertTrue(Point(2, 2) in scp)
예제 #4
0
 def test_is_valid_point(self):
     from simulator.oldmodels import Cloudlet
     cs = [
         [Cloudlet(), Cloudlet(), Cloudlet()],
         [Cloudlet(), Cloudlet(), Cloudlet()],
         [Cloudlet(), Cloudlet(), Cloudlet()],
     ]
     self.assertTrue(cloudlet.is_valid_point(cs, Point(0, 0)),
                     msg="x=0, y=0")
     self.assertTrue(cloudlet.is_valid_point(cs, Point(2, 2)),
                     msg="x=2, y=2")
     self.assertFalse(cloudlet.is_valid_point(cs, Point(-1, -1)),
                      msg="x=-1, y=-1")
     self.assertFalse(cloudlet.is_valid_point(cs, Point(3, 3)),
                      msg="x=3, y=3")
예제 #5
0
 def test_near_cloudlets_02(self):
     from simulator.oldmodels import Cloudlet
     cs = [[
         Cloudlet(name="d1"),
         Cloudlet(name="d2"),
         Cloudlet(name="d3"),
         Cloudlet(name="d4")
     ],
           [
               Cloudlet(name="d5"),
               Cloudlet(name="d6"),
               Cloudlet(name="d7"),
               Cloudlet(name="d8")
           ],
           [
               Cloudlet(name="d9"),
               Cloudlet(name="d10"),
               Cloudlet(name="d11"),
               Cloudlet(name="d12")
           ],
           [
               Cloudlet(name="d13"),
               Cloudlet(name="d14"),
               Cloudlet(name="d15"),
               Cloudlet(name="d16")
           ]]
     ncs = cloudlet.near_cloudlets(cs, Point(0, 0), 2, 2)
     self.assertEqual(len(ncs), 3, msg=[c.name for c in ncs])
     names = [c.name for c in ncs]
     self.assertTrue("d3" in names, msg=[c.name for c in ncs])
     self.assertTrue("d6" in names, msg=[c.name for c in ncs])
     self.assertTrue("d9" in names, msg=[c.name for c in ncs])
예제 #6
0
def get_udrl_cloudlet(cloudlets: Cloudlets, x: int, y: int) -> List[Cloudlet]:
    pts = [
        Point(xx, yy) for xx in [x - 1, x, x + 1] for yy in [y - 1, y, y + 1]
        if is_udrl(xx, yy, x, y)
    ]
    return [
        cloudlets[p.y][p.x] for p in pts if is_valid_cell(cloudlets, p.x, p.y)
    ]
예제 #7
0
def get_cloudlet_point_from_cloudlets(name: str,
                                      cloudlets: Cloudlets) -> Point:
    for y, row in enumerate(cloudlets):
        for x, c in enumerate(row):
            if c.name == name:
                return Point(x, y)
    else:
        return None
예제 #8
0
def near_cloudlets(cloudlets: Cloudlets, p: Point, d_max: int,
                   d_min: int) -> List[Cloudlet]:
    """
    近隣のCloudletを取得する。
    pからの距離がd_min以上でd_max以下のCloudletを取得する。
    :param cloudlets: 検索するCloudlets 
    :param p: 中心座標
    :param d_max: 最大距離
    :param d_min: 最小距離
    :return: 条件を満たす近隣Cloudletのリスト
    """
    near = []  # type: List[Cloudlet]
    for y in range(p.y - d_max, p.y + d_max + 1):
        for x in range(p.x - d_max, p.x + d_max + 1):
            if d_min <= distance(Point(x, y), p) <= d_max and is_valid_point(
                    cloudlets, Point(x, y)):
                near.append(cloudlets[y][x])
    return near
예제 #9
0
 def test_scope_04(self):
     from simulator.oldmodels import Point
     p1 = Point(0, 0)
     scp = oldutility.scope(p1,
                            distance_min=2,
                            distance_max=2,
                            x_max=100,
                            x_min=-100,
                            y_max=100,
                            y_min=-100)
     self.assertEqual(8, len(scp), msg=scp)
     self.assertTrue(Point(2, 0) in scp)
     self.assertTrue(Point(1, 1) in scp)
     self.assertTrue(Point(0, 2) in scp)
     self.assertTrue(Point(-1, 1) in scp)
     self.assertTrue(Point(-2, 0) in scp)
     self.assertTrue(Point(-1, -1) in scp)
     self.assertTrue(Point(0, 2) in scp)
     self.assertTrue(Point(1, -1) in scp)
예제 #10
0
def scope(center: Point,
          distance_max: int,
          x_max: int,
          y_max: int,
          distance_min: int = 0,
          x_min: int = 0,
          y_min: int = 0) -> List[Point]:
    ret = []  # type:List[Point]
    for y in range(y_min, y_max + 1):
        for x in range(x_min, x_max + 1):
            point = Point(x, y)
            if distance_min <= dist(center, point) <= distance_max:
                ret.append(point)
    return ret
예제 #11
0
 def test_continuity_02(self):
     p1 = Point(0, 0)
     p2 = Point(1, 1)
     p3 = Point(2, 1)
     p4 = Point(3, 1)
     p5 = Point(2, 0)
     p6 = Point(1, 0)
     p_list = [p1, p2, p3, p4, p5, p6]
     self.assertFalse(point.continuity(p_list))
예제 #12
0
 def test_adjacency_05(self):
     p1 = Point(0, 0)
     p2 = Point(1, 1)
     self.assertFalse(point.adjacency(p1, p2))
예제 #13
0
 def test_extract_03(self):
     p = Point(0, 0)
     p_list = point.extract(p, 3, d_min=3)
     exp = [Point(3, 0), Point(2, 1), Point(1, 2), Point(0, 3),
            Point(-3, 0), Point(-2, -1), Point(-1, -2), Point(0, -3),
            Point(-2, 1), Point(-1, 2), Point(2, -1), Point(1, -2)]
     self.assertEqual(12, len(p_list), msg=p_list)
     for ep in exp:
         self.assertTrue(ep in p_list)
예제 #14
0
 def setUp(self):
     self.all_time_cloudlets = oldutility.create_all_time_cloudlets(
         t_len=5, x_len=5, y_len=5, max_resource=5)
     d1 = Device(name="d1",
                 startup_time=0,
                 plan=[Point(0, 0), Point(0, 1),
                       Point(0, 2)])
     d1.use_resource = 5
     d2 = Device(name="d2",
                 startup_time=1,
                 plan=[Point(0, 0), Point(0, 1),
                       Point(0, 2)])
     d2.use_resource = 5
     d3 = Device(name="d3",
                 startup_time=1,
                 plan=[Point(1, 0), Point(2, 0),
                       Point(3, 0)])
     d3.use_resource = 5
     d4 = Device(name="d4",
                 startup_time=1,
                 plan=[Point(0, 0), Point(0, 1),
                       Point(0, 2)])
     d4.use_resource = 5
     self.devices = [d1, d2, d3, d4]
예제 #15
0
 def test_distance_03(self):
     p1 = Point(0, 0)
     p2 = Point(0, 0)
     self.assertEqual(0, point.distance(p1, p2))
예제 #16
0
 def test_random_two_points_01(self):
     p1, p2 = point.random_two_point(3, Point(0, 0), Point(5, 5))
     self.assertEqual(3, point.distance(p1, p2))
예제 #17
0
 def test_distance_02(self):
     p1 = Point(0, 0)
     p2 = Point(-3, -5)
     self.assertEqual(8, point.distance(p1, p2))
예제 #18
0
 def test_distance_01(self):
     p1 = Point(0, 0)
     p2 = Point(5, 3)
     self.assertEqual(8, point.distance(p1, p2))
예제 #19
0
 def test_scope_03(self):
     from simulator.oldmodels import Point
     p1 = Point(2, 2)
     scp = oldutility.scope(p1,
                            distance_min=0,
                            distance_max=2,
                            x_max=100,
                            x_min=-100,
                            y_max=100,
                            y_min=-100)
     self.assertEqual(13, len(scp), msg=scp)
     self.assertTrue(Point(2, 2) in scp)
     self.assertTrue(Point(2, 1) in scp)
     self.assertTrue(Point(2, 3) in scp)
     self.assertTrue(Point(1, 2) in scp)
     self.assertTrue(Point(3, 2) in scp)
     self.assertTrue(Point(2, 4) in scp)
     self.assertTrue(Point(2, 0) in scp)
     self.assertTrue(Point(4, 2) in scp)
     self.assertTrue(Point(0, 2) in scp)
     self.assertTrue(Point(3, 3) in scp)
     self.assertTrue(Point(1, 1) in scp)
     self.assertTrue(Point(1, 3) in scp)
     self.assertTrue(Point(3, 1) in scp)
예제 #20
0
 def test_random_two_points_02(self):
     self.assertRaises(Exception, lambda: point.random_two_point(3, Point(0, 0), Point(0, 0)))
예제 #21
0
 def test_route_01(self):
     p1 = Point(0, 0)
     p2 = Point(2, 2)
     r = point.route(p1, p2)
     self.assertTrue(point.continuity(r))
     self.assertEqual(5, len(r))
예제 #22
0
 def test_adjacency_04(self):
     p1 = Point(0, 0)
     p2 = Point(-1, 0)
     self.assertTrue(point.adjacency(p1, p2))
예제 #23
0
 def test_continuity_02(self):
     from simulator.oldmodels import Point
     target = [Point(0, 0), Point(1, 1), Point(1, 2)]
     self.assertFalse(oldutility.continuity(target))