예제 #1
0
    def _test_obj_fun(self):
        m = 3
        n = 1

        e1 = Ship(player_id=1,
                  ship_id=1,
                  x=100,
                  y=100,
                  hp=100,
                  vel_x=0,
                  vel_y=0,
                  docking_status=0,
                  planet=None,
                  progress=0,
                  cooldown=0)
        e2 = Planet(planet_id=1,
                    x=100,
                    y=150,
                    hp=100,
                    radius=15,
                    docking_spots=2,
                    current=0,
                    remaining=5,
                    owned=0,
                    owner=0,
                    docked_ships=0)
        e3 = Planet(planet_id=2,
                    x=30,
                    y=75,
                    hp=100,
                    radius=10,
                    docking_spots=7,
                    current=0,
                    remaining=5,
                    owned=0,
                    owner=0,
                    docked_ships=0)
        all_entities = [e1, e2, e3]
        params = map_parameters(map_parameters([]).values())

        for e in all_entities:
            e.augment(1, params)

        fun_grad, hess = nav.objective_function(n, m, all_entities)

        unit_vec, apex, rad, all_pos, dist = constraints_pre(
            n, m, all_entities)

        x = self.entities[0].x
        y = self.entities[0].y

        img = [[fun_grad([i - x, j - y])[0] for i in range(200)]
               for j in range(200)]

        img = fit_255(np.array(img))

        img = np.dstack((img, img, img))

        draw_entities(img, all_entities, unit_vec=unit_vec)
예제 #2
0
 def _test_constraints_pre(self):
     m = 2
     n = 1
     all_entities = self.entities[:m]
     unit_vec, apex, rad, all_pos, dist = constraints_pre(
         n, m, all_entities)
     for e in all_entities:
         print(e)
     print("unit_vec", unit_vec)
     print("apex", apex[0, 1])
     print("rad", rad)
     print("all_pos", all_pos)
     print("dist ", dist)
예제 #3
0
    def _test_RVO_constraints_1call(self):
        m = 2
        n = 1
        e1 = Entity(100, 100, 5, 10, 1, 1)
        e2 = Entity(100, 150, 10, 10, 1, 2)
        all_entities = [e1, e2]
        unit_vec, apex, rad, all_pos, dist = constraints_pre(
            n, m, all_entities)

        cons = const_RVO(n, m, unit_vec, dist, rad, self.max_speed**2)

        print("value before apex", cons([0, 30]))
        print("value at apex", cons([0, 35]))
        print("value after apex", cons([0, 40]))
예제 #4
0
    def _test_RVO_jac_1call(self):
        m = 2
        n = 1
        e1 = Entity(100, 100, 5, 10, 1, 1)
        e2 = Entity(100, 150, 10, 10, 1, 2)
        all_entities = [e1, e2]
        unit_vec, apex, rad, all_pos, dist = constraints_pre(
            n, m, all_entities)

        jac = jac_RVO(n, m, unit_vec, rad)

        print("grad value before apex", jac([0, 30])[0])
        print("grad value at apex", jac([0, 35])[0])
        print("grad value after apex", jac([0, 40])[0])
        print("#######")
        print("grad value before apex", jac([15, 35])[0])
        print("grad value at apex", jac([0, 35])[0])
        print("grad value after apex", jac([-5, 40])[0])
예제 #5
0
    def _test_compute_1RVO_constraint(self):
        m = 4
        n = 1
        all_entities = self.entities[:m]
        unit_vec, apex, rad, all_pos, dist = constraints_pre(
            n, m, all_entities)

        cons = const_RVO(n, m, unit_vec, dist, rad, self.max_speed**2)

        x = self.entities[0].x
        y = self.entities[0].y

        n_cons = len(cons([0, 0]))
        img = [[
            all([cons([i - x, j - y])[k] < 0 for k in range(n_cons)])
            for i in range(200)
        ] for j in range(200)]

        img = np.array(img, dtype=np.uint8)
        img = img * 255
        img = np.dstack((img, img, img))

        draw_entities(img, all_entities, unit_vec=unit_vec)
예제 #6
0
    def _test_grad_cons(self):
        m = 2
        n = 1
        all_entities = self.entities[:m]
        unit_vec, apex, rad, all_pos, dist = constraints_pre(
            n, m, all_entities)

        jac = jac_RVO(n, m, unit_vec, rad)

        x = self.entities[0].x
        y = self.entities[0].y
        r = self.entities[0].radius

        grad = [[jac([i - x, j - y])[0] for i in range(200)]
                for j in range(200)]
        grad = np.array(grad)
        grad[:, :, 0] = fit_255(grad[:, :, 0])
        grad[:, :, 1] = fit_255(grad[:, :, 1])

        img = np.zeros((200, 200, 3))
        img[:, :, :2] = np.array(grad)
        img = np.uint8(img)

        draw_entities(img, all_entities, unit_vec=unit_vec)