def display_graph(self):
     gui = GUI()
     for edge in self.G.edges():
         s = conversions.point_2_to_xy(edge[0])
         t = conversions.point_2_to_xy(edge[1])
         gui.add_segment(*s, *t)
     gui.MainWindow.show()
Exemple #2
0
 def set_up_animation(self):
     self.draw_scene()
     animations = []
     if OPTIONS['re/draw']:
         for e in self.all_edges:
             for ee in e.sampled_edges:
                 gui.add_segment(*(ee.previous_edge.target), *(ee.target),
                                 Qt.lightGray)
     if len(self.path) == 0:
         return
     if len(self.path) == 1:
         for i in range(self.number_of_robots):
             start = point_2_to_xy(self.path[0][i] + offset)
             animations.append(
                 gui.linear_translation_animation(self.gui_robots[i],
                                                  *start, *start))
         anim = gui.parallel_animation(*animations)
         gui.queue_animation(anim)
     else:
         for i in range(len(self.path) - 1):
             animations = []
             start = point_2_to_xy(self.path[i])
             end = point_2_to_xy(self.path[i + 1])
             s = gui.add_segment(*start, *end, Qt.red)
             start = point_2_to_xy(self.path[i])
             end = point_2_to_xy(self.path[i + 1])
             s.line.setZValue(2)
             gui.add_disc(0.02, *end, fill_color=Qt.blue)
             animations.append(
                 gui.linear_translation_animation(self.gui_robots[0],
                                                  *start, *end))
             anim = gui.parallel_animation(*animations)
             gui.queue_animation(anim)
Exemple #3
0
 def set_destinations(self, destinations):
   self.destinations = destinations
   for i in range(len(self.gui_destinations)):
     if self.gui_destinations[i] == None:
       self.gui_destinations[i] = gui.add_disc(0.0005, *point_2_to_xy(destinations[i]), Qt.green)
     else:
       self.gui_destinations[i].pos = QPointF(*point_2_to_xy(destinations[i]))
    def display_cspace(self):
        gui = GUI()
        for he in self.cspace.edges():
            s = conversions.point_2_to_xy(he.source().point())
            t = conversions.point_2_to_xy(he.target().point())
            gui.add_segment(*s, *t)

        gui.MainWindow.show()
    def process_turn(self):
        robots = None
        gui_robots = None
        d = self.D
        if (self.turn % 2 == 0):
            robots = self.red_robots
            gui_robots = self.gui_red_robots
        else:
            robots = self.blue_robots
            gui_robots = self.gui_blue_robots
        for step in self.path:
            edges = []
            for i in range(len(robots)):
                edges.append(Segment_2(robots[i][0], step[i]))

            if (self.is_step_valid(edges, d)):
                #Update d
                s = 0
                for edge in edges:
                    s += (edge.squared_length().to_double())**0.5
                d -= s

                #Collect bonuses
                bonus_anims = []
                for i in range(len(robots)):
                    edge = edges[i]
                    for expanded_bonus in self.expanded_bonuses:
                        bonus = self.bonuses[expanded_bonus[1]]
                        if not bonus[1] == 0:
                            if not expanded_bonus[0].is_edge_valid(edge):
                                robots[i][1] += bonus[1]
                                bonus[1] = 0
                                bonus_anims.append(
                                    gui.visibility_animation(
                                        self.gui_bonuses[expanded_bonus[1]],
                                        False))

                #Queue animations
                for i in range(len(robots)):
                    robots[i][0] = step[i]
                anims = []
                for i in range(len(robots)):
                    edge = edges[i]
                    anims.append(
                        gui.linear_translation_animation(
                            gui_robots[i], *point_2_to_xy(edge.source()),
                            *point_2_to_xy(edge.target())))
                anim = gui.parallel_animation(*anims)
                gui.queue_animation(anim)
                anim = gui.parallel_animation(*bonus_anims)
                gui.queue_animation(anim)
        #gui.play_queue()
        #gui.empty_queue()
        self.turn += 1
        print("Done processing turn for player", 2 - (self.turn % 2))
Exemple #6
0
def is_point_valid_robot_robot(p, team_robots, radius):

    point_x, point_y = conversions.point_2_to_xy(p)
    for team_robot in team_robots:
        robot_x, robot_y = conversions.point_2_to_xy(team_robot)
        distX = point_x - robot_x
        distY = point_y - robot_y
        distance = ((distX * distX) + (distY * distY))**0.5
        if distance < 2 * radius.to_double():
            return False
    return True
Exemple #7
0
 def draw_scene(self):
   gui.clear_scene()
   colors = [Qt.yellow, Qt.green, Qt.black, Qt.blue, Qt.darkGreen, Qt.red, Qt.magenta, Qt.darkMagenta, Qt.darkGreen, Qt.darkCyan, Qt.cyan]
   for i in range(len(self.robots)):
     if (self.robots[i] != None):
       self.gui_robots[i] = gui.add_disc(self.radius, *point_2_to_xy(self.robots[i]), colors[i])
   for obstacle in self.obstacles:
     self.gui_obstacles = []
     self.gui_obstacles.append(gui.add_polygon([point_2_to_xy(p) for p in obstacle], Qt.darkGray))
   for i in range(len(self.destinations)):
     if(self.destinations[i] != None):
       self.gui_destinations[i] = gui.add_disc(0.005, *point_2_to_xy(self.destinations[i]), colors[i])
Exemple #8
0
    def is_path_valid(self):
        if self.path == None: return False
        if len(self.path) == 0: return False
        robot_polygon = tuples_list_to_polygon_2(self.robot)
        path_polygons = []
        if len(self.path) > 1:
            for i in range(len(self.path) - 1):
                source = self.path[i]
                target = self.path[i + 1]
                s = Segment_2(source, target)
                pwh = ms_polygon_segment.minkowski_sum_polygon_segment(
                    robot_polygon, s)
                path_polygons.append(pwh)

        obstacle_polygons = []
        for obs in self.obstacles:
            p = tuples_list_to_polygon_2(obs)
            obstacle_polygons.append(p)

        path_set = Polygon_set_2()
        path_set.join_polygons_with_holes(path_polygons)
        obstacles_set = Polygon_set_2()
        obstacles_set.join_polygons(obstacle_polygons)

        lst = []
        path_set.polygons_with_holes(lst)
        for pwh in lst:
            p = pwh.outer_boundary()
            lst = polygon_2_to_tuples_list(p)
            gui.add_polygon(lst, Qt.lightGray).polygon.setZValue(-3)
            for p in pwh.holes():
                lst = polygon_2_to_tuples_list(p)
                gui.add_polygon(lst, Qt.white).polygon.setZValue(-2)

        # check that the origin matches the first point in the path
        check0 = True if self.robot[0] == point_2_to_xy(
            self.path[0]) else False
        # check that the destination matches the last point in the path
        check1 = True if self.destination == point_2_to_xy(
            self.path[-1]) else False
        #check that there are no collisions
        check2 = True if not path_set.do_intersect(obstacles_set) else False
        res = (check0 and check1 and check2)
        print("Valid path: ", res)
        if check0 == False:
            print("Origin mismatch")
        if check1 == False:
            print("Destination mismatch")
        if check2 == False:
            print("Movement along path intersects with obstacles")
        return res
Exemple #9
0
 def initialize(self, N, start):
     self.path = [[nx.DiGraph(), Dynamic_kd_tree()] for i in range(N)]
     robot_in_6d = [0 for i in range(N)]
     for i in range(N):
         robot_i_x, robot_i_y = conversions.point_2_to_xy(start[i])
         robot_in_6d[i] = Point_d(
             6, [FT(robot_i_x),
                 FT(robot_i_y),
                 FT(0),
                 FT(0),
                 FT(0),
                 FT(0)])
         self.path[i][0].add_node(robot_in_6d[i])
         self.path[i][0].add_weighted_edges_from([(robot_in_6d[i],
                                                   robot_in_6d[i], 0)])
         self.path[i][1].insert(
             robot_in_6d[i]
         )  # inserting the starting position of each robot
         self.node_configs[i][robot_in_6d[i]] = [self.confg_cnt]
     self.configs[self.confg_cnt] = {
         'nodes': robot_in_6d,
         'cost': 0,
         'parent': None
     }
     self.confg_cnt += 1
Exemple #10
0
 def draw_scene(self):
     gui.clear_scene()
     self.gui_robots = []
     self.gui_robots.append(
         gui.add_polygon([point_2_to_xy(p) for p in self.robots[0]],
                         Qt.yellow))
     self.gui_obstacles = []
     for obstacle in self.obstacles:
         self.gui_obstacles.append(
             gui.add_polygon([point_2_to_xy(p) for p in obstacle],
                             Qt.darkGray))
     self.gui_destinations = []
     for i in range(len(self.destinations)):
         self.gui_destinations.append(
             gui.add_disc(0.05, *point_2_to_xy(self.destinations[i]),
                          Qt.green))
Exemple #11
0
 def set_up_animation(self):
     self.draw_scene()
     if len(self.path) == 0:
         return
     if len(self.path) == 1:
         start = point_2_to_xy(self.path[0])
         anim = gui.linear_translation_animation(self.gui_robot, *start,
                                                 *start)
         gui.queue_animation(anim)
     else:
         for i in range(len(self.path) - 1):
             start = point_2_to_xy(self.path[i])
             end = point_2_to_xy(self.path[i + 1])
             s = gui.add_segment(*start, *end, Qt.red)
             s.line.setZValue(-1)
             anim = gui.linear_translation_animation(
                 self.gui_robot, *start, *end)
             gui.queue_animation(anim)
Exemple #12
0
 def set_up_animation(self):
   self.draw_scene()
   colors = [Qt.yellow, Qt.green, Qt.black, Qt.blue, Qt.darkGreen, Qt.red, Qt.magenta, Qt.darkMagenta, Qt.darkGreen,
             Qt.darkCyan, Qt.cyan]
   if len(self.path) == 0:
     return
   if len(self.path) == 1:
     return
   else:
     for i in range(len(self.path) - 1):
       anim_l = [None for i in range(self.robot_num)]
       for r_i in range(self.robot_num):
         start = point_2_to_xy(self.path[i][r_i])
         end = point_2_to_xy(self.path[i+1][r_i])
         s = gui.add_segment(*start, *end, colors[r_i])
         start = point_2_to_xy(self.path[i][r_i] + offset)
         end = point_2_to_xy(self.path[i + 1][r_i] + offset)
         s.line.setZValue(2)
         anim_l[r_i] = gui.linear_translation_animation(self.gui_robots[r_i], *start, *end)
       anim = gui.parallel_animation(anim_l)
       gui.queue_animation(anim)
 def draw_scene(self):
     gui.empty_queue()
     gui.clear_scene()
     self.gui_robots = []
     for robot in self.red_robots:
         self.gui_red_robots.append(
             gui.add_disc(self.R.to_double(),
                          *point_2_to_xy(robot[0]),
                          fill_color=Qt.red))
     for robot in self.blue_robots:
         self.gui_blue_robots.append(
             gui.add_disc(self.R.to_double(),
                          *point_2_to_xy(robot[0]),
                          fill_color=Qt.blue))
     for objective in self.red_objectives:
         self.gui_objectives.append(
             gui.add_disc(OBJECTIVE_RADIUS,
                          *point_2_to_xy(objective),
                          fill_color=Qt.red))
     for objective in self.blue_objectives:
         self.gui_objectives.append(
             gui.add_disc(OBJECTIVE_RADIUS,
                          *point_2_to_xy(objective),
                          fill_color=Qt.blue))
     for obstacle in self.obstacles:
         self.gui_obstacles.append(
             gui.add_polygon(
                 [point_2_to_xy(p) for p in obstacle.vertices()],
                 Qt.darkGray))
     for bonus in self.bonuses:
         self.gui_bonuses.append(
             gui.add_polygon(
                 [point_2_to_xy(p) for p in bonus[0].vertices()],
                 Qt.yellow))
Exemple #14
0
 def draw_scene(self):
     self.gui.empty_queue()
     self.gui.clear_scene()
     self.gui_robots = []
     for obstacle in self.obstacles:
         self.gui_obstacles.append(
             self.gui.add_polygon(
                 [point_2_to_xy(p) for p in obstacle.vertices()],
                 Qt.darkGray))
     for robot in self.red_robots:
         self.gui_red_robots.append(
             self.gui.add_disc_robot(self.R.to_double(),
                                     *point_2_to_xy(robot[0]),
                                     fill_color=QColor(
                                         Qt.red).lighter(130)))
     for robot in self.blue_robots:
         self.gui_blue_robots.append(
             self.gui.add_disc_robot(self.R.to_double(),
                                     *point_2_to_xy(robot[0]),
                                     fill_color=QColor(
                                         Qt.blue).lighter(130)))
     for bonus in self.bonuses:
         p = self.gui.add_polygon(
             [point_2_to_xy(p) for p in bonus[0].vertices()], Qt.yellow)
         fp = next(bonus[0].vertices())
         x = fp.x().to_double()
         y = fp.y().to_double()
         t = self.gui.add_text(str(bonus[1]), x, y, 1)
         self.gui_bonuses.append((p, t))
     for objective in self.red_objectives:
         self.gui_objectives.append(
             self.gui.add_disc(self.R.to_double(),
                               *point_2_to_xy(objective),
                               fill_color=Qt.transparent,
                               line_color=QColor(Qt.red).darker(130)))
     for objective in self.blue_objectives:
         self.gui_objectives.append(
             self.gui.add_disc(self.R.to_double(),
                               *point_2_to_xy(objective),
                               fill_color=Qt.transparent,
                               line_color=QColor(Qt.blue).darker(130)))
     self.gui.redraw()
Exemple #15
0
 def set_destinations(self, destinations):
     self.destinations = destinations
     for i in range(len(self.gui_destinations)):
         if self.gui_destinations[i] != None:
             self.gui_destinations[i].pos = QPointF(
                 *point_2_to_xy(destinations[i]))
Exemple #16
0
    def process_turn(self):
        robots = None
        gui_robots = None
        d = self.D
        if self.turn % 2 == 0:
            robots = self.red_robots
            gui_robots = self.gui_red_robots
        else:
            robots = self.blue_robots
            gui_robots = self.gui_blue_robots
        for step in self.path:
            edges = []
            for i in range(len(robots)):
                edges.append(Segment_2(robots[i][0], step[i]))

            if self.is_step_valid(edges, d):
                # Update d
                s = 0
                for edge in edges:
                    s += (edge.squared_length().to_double())**0.5
                d -= s

                # Collect bonuses
                bonus_anims = []
                for i in range(len(robots)):
                    edge = edges[i]
                    for expanded_bonus in self.expanded_bonuses:
                        bonus = self.bonuses[expanded_bonus[1]]
                        if not bonus[1] == 0:
                            if not expanded_bonus[0].is_edge_valid(edge):
                                if self.turn % 2 == 0:
                                    self.red_score += bonus[1]
                                else:
                                    self.blue_score += bonus[1]
                                robots[i][1] += bonus[1]
                                bonus[1] = 0
                                bonus_anims.append(
                                    self.gui.visibility_animation(
                                        self.gui_bonuses[expanded_bonus[1]][0],
                                        False))
                                bonus_anims.append(
                                    self.gui.visibility_animation(
                                        self.gui_bonuses[expanded_bonus[1]][1],
                                        False))
                                bonus_anims.append(
                                    self.gui.text_animation(
                                        gui_robots[i], int(robots[i][1])))

                # Queue animations
                for i in range(len(robots)):
                    robots[i][0] = step[i]
                anims = []
                for i in range(len(robots)):
                    edge = edges[i]
                    anims.append(
                        self.gui.linear_translation_animation(
                            gui_robots[i],
                            *point_2_to_xy(edge.source()),
                            *point_2_to_xy(edge.target()),
                            duration=2000 / len(self.path)))

                anim = self.gui.value_animation(self.gui.progressBars[0],
                                                int(100 * (d + s) / self.D),
                                                (100 * d / self.D),
                                                duration=2000 / len(self.path))
                anim = self.gui.parallel_animation(*anims, anim)
                self.gui.queue_animation(anim)
                anim = self.gui.parallel_animation(*bonus_anims)
                self.gui.queue_animation(anim)
            else:
                break