Example #1
0
    def draw_target(self, target_coords):
        for i, (startx, starty) in enumerate(target_coords):
            stddraw.setPenColor(c=stddraw.BOOK_LIGHT_BLUE)
            stddraw.filledSquare(startx, starty, 10)
            stddraw.text(startx, starty + 25, "tar id:{}".format(i))

        self.__reset_pen()
Example #2
0
    def __draw_drone_info(self, drone, cur_step):
        stddraw.setPenRadius(0.0125)
        stddraw.setPenColor(c=stddraw.BLACK)

        # index
        stddraw.text(drone.coords[0],
                     drone.coords[1] + (drone.com_range / 2.0),
                     "id: " + str(drone.identifier))
Example #3
0
    def draw_depot(self, depot):
        coords = depot.coords
        stddraw.setPenRadius(0.0100)
        stddraw.setPenColor(c=stddraw.BLUE)
        stddraw.point(coords[0], coords[1])
        self.__draw_communication_range(depot)
        self.__reset_pen()

        # draw the buffer size
        stddraw.setPenRadius(0.0125)
        stddraw.setPenColor(c=stddraw.BLACK)
        stddraw.text(depot.coords[0], depot.coords[1] + 100,
                     "pk: " + str(len(depot.buffer)))
Example #4
0
    def __validate_rew(self, drone, cur_step):
        coords = drone.coords

        stddraw.setPenColor(c=stddraw.RED)

        # reward: relay found when doing broadcast
        if drone.routing_algorithm.draw_rew_broad is not None:
            r = drone.routing_algorithm.draw_rew_broad
            self.keep_indictor["r.bro"].append((cur_step, drone, r))
            drone.routing_algorithm.draw_rew_broad = None

        # reward: packet expired
        if drone.routing_algorithm.draw_rew_exp is not None:
            r = drone.routing_algorithm.draw_rew_exp
            self.keep_indictor["r.exp"].append((cur_step, drone, r))
            drone.routing_algorithm.draw_rew_exp = None

        # reward: packet delivered to depot
        if drone.routing_algorithm.draw_rew_dep is not None:
            r = drone.routing_algorithm.draw_rew_dep
            self.keep_indictor["r.dep"].append((cur_step, drone, r))
            drone.routing_algorithm.draw_rew_dep = None

        # reward: every delta did move
        if drone.routing_algorithm.draw_rew_area_move is not None:
            r = drone.routing_algorithm.draw_rew_area_move
            self.keep_indictor["r.dmo"].append((cur_step, drone, r))
            drone.routing_algorithm.draw_rew_area_move = None

        # reward: every delta did broad
        if drone.routing_algorithm.draw_rew_area_broad is not None:
            r = drone.routing_algorithm.draw_rew_area_broad
            self.keep_indictor["r.dbr"].append((cur_step, drone, r))
            drone.routing_algorithm.draw_rew_area_broad = None

        for k in self.keep_indictor:
            for ts, drone_in, r in self.keep_indictor[k]:
                if drone == drone_in:
                    # red for all rewards except those evaluated every delta
                    if k in ["r.dmo", "r.dbr"]:
                        stddraw.setPenColor(c=stddraw.MAGENTA)
                    else:
                        stddraw.setPenColor(c=stddraw.RED)

                    stddraw.text(coords[0] + 30, coords[1] + 30,
                                 k + " " + str(round(r, 3)))

                    if cur_step - ts >= 100:
                        self.keep_indictor[k].remove((ts, drone_in, r))
Example #5
0
    def draw_depot(self, depot):
        coords = depot.coords
        stddraw.setPenRadius(0.0100)
        stddraw.setPenColor(c=stddraw.DARK_RED)
        size_depot = 50
        stddraw.filledPolygon([
            coords[0] - (size_depot / 2), coords[0], coords[0] +
            (size_depot / 2)
        ], [coords[1], coords[1] + size_depot, coords[1]])
        self.__draw_communication_range(depot)
        self.__reset_pen()

        # draw the buffer size
        stddraw.setPenRadius(0.0125)
        stddraw.setPenColor(c=stddraw.BLACK)
        stddraw.text(depot.coords[0], depot.coords[1] + 100,
                     "pk: " + str(len(depot.all_packets())))
Example #6
0
    def __grid_plot(self):
        for i in range(0, self.width, self.simulator.prob_size_cell):
            stddraw.setPenColor(c=stddraw.GRAY)
            stddraw.setPenRadius(0.0025)
            # x1, y1, x2, y2
            stddraw.line(i, 0, i, self.height)
            self.__reset_pen()
        for j in range(0, self.height, self.simulator.prob_size_cell):
            stddraw.setPenColor(c=stddraw.GRAY)
            stddraw.setPenRadius(0.0025)
            # x1, y1, x2, y2
            stddraw.line(0, j, self.width, j)
            self.__reset_pen()

        for cell, cell_center in utilities.TraversedCells.all_centers(
                self.width, self.height, self.simulator.prob_size_cell):
            index_cell = int(cell[0])
            pr = self.simulator.cell_prob_map[index_cell][2]
            stddraw.text(cell_center[0], cell_center[1],
                         "pr-c: " + str(round(pr, 4)))
Example #7
0
    def draw_simulation_info(self, cur_step, max_steps):
        TEXT_LEFT = 60
        TEXT_TOP = 30

        stddraw.text(TEXT_LEFT + 20, self.height - TEXT_TOP,
                     str(cur_step) + "/" + str(max_steps))
        #if self.simulator.is_free_movement():
        stddraw.text(TEXT_LEFT + 20, self.height - TEXT_TOP * 2,
                     "drone: " + str(self.simulator.selected_drone.identifier))
        stddraw.text(TEXT_LEFT + 20, self.height - TEXT_TOP * 3,
                     "speed: " + str(self.simulator.selected_drone.speed))
        stddraw.text(TEXT_LEFT + 20, self.height - TEXT_TOP * 4,
                     "angle: " + str(self.simulator.selected_drone.angle))
        self.__reset_pen()
Example #8
0
    def __draw_drone_info(self, drone, cur_step):
        stddraw.setPenRadius(0.0125)
        stddraw.setPenColor(c=stddraw.BLACK)
        # life time and speed
        stddraw.text(drone.coords[0] - 50, drone.coords[1],
                     "buf: " + str(drone.buffer_length()))
        # index
        stddraw.text(drone.coords[0],
                     drone.coords[1] + (drone.communication_range / 2.0),
                     "id: " + str(drone.identifier))

        if drone.buffer_length() > 0:
            stddraw.text(
                drone.coords[0],
                drone.coords[1] - (drone.communication_range / 2.0),
                "retr: " + str(drone.routing_algorithm.current_n_transmission))

        # If the buffer is empty, do not show the retransmission counters since they are not updated
        else:
            stddraw.text(drone.coords[0],
                         drone.coords[1] - (drone.communication_range / 2.0),
                         "retr: -- \\ --")
Example #9
0
 def draw_simulation_info(self, cur_step, max_steps):
     TEXT_LEFT = 60
     TEXT_TOP = 20
     stddraw.text(TEXT_LEFT + 20, self.height - TEXT_TOP,
                  str(cur_step) + "/" + str(max_steps))
     self.__reset_pen()