Example #1
0
    def draw_end_dist(self):
        if self.end_dist == -1:  # 如果是第一次计算
            end_road_start, end_road_stop, end_road_dist = absorp.absorp(
                self.x, self.y, self.graph)
            route_from_start = dijkstra.get_route(end_road_start,
                                                  self.arrive_point)
            cost_from_start = route_from_start['cost'] + end_road_dist
            route_from_end = dijkstra.get_route(end_road_stop,
                                                self.arrive_point)
            cost_from_end = route_from_end['cost'] + dijkstra.get_cost(
                end_road_start, end_road_stop) - end_road_dist
            if cost_from_start < cost_from_end:
                end_route = route_from_start
            else:
                end_route = route_from_end
            self.end_dist = end_route['cost']
            self.end_path = end_route['path']

            dist = math.sqrt(
                (self.x - self.graph.x[self.arrive_point - 1])**2 +
                (6000 - self.y - self.graph.y[self.arrive_point - 1])**2)
            print('real dist: ' + str(dist))
            if dist <= 300:  # 认为到达终点
                self.end_dist = 0
                self.end_path = []

            print('end_dist: ' + str(self.end_dist))
            route = dijkstra.get_route(self.depart_point, self.arrive_point)
            self.Penalty.display(
                min(self.end_dist / route['cost'] * 120.0, 120.0))

        for i in range(len(self.end_path) - 1):
            start_point = int(self.end_path[i])
            end_point = int(self.end_path[i + 1])
            start_x = self.graph.x[start_point -
                                   1] * self.x_scale + self.width / 35
            start_y = (6000 - self.graph.y[start_point - 1]
                       ) * self.y_scale + self.height / 35
            end_x = self.graph.x[end_point -
                                 1] * self.x_scale + self.width / 35
            end_y = (6000 - self.graph.y[end_point -
                                         1]) * self.y_scale + self.height / 35
            self.scene.addLine(
                start_x,
                start_y,
                end_x,
                end_y,
                QtGui.QPen(
                    Qt.darkRed,
                    10,
                    QtCore.Qt.SolidLine,  # 颜色数字
                    QtCore.Qt.RoundCap,
                    QtCore.Qt.RoundJoin))
Example #2
0
    def __calc_route__(self):
        node_dict = {}
        map_dict = {}
        for item in self.ms.all_doors():
            node = Node(item)
            node_dict[item] = node
            if not item.map_name in map_dict:
                map_dict[item.map_name] = []

            map_dict[item.map_name].append(node)

        from_node = Node(wx.GetApp().GetNavFrom())
        map_dict[wx.GetApp().GetNavFrom().map_name].append(from_node)

        to_node = Node(wx.GetApp().GetNavTo())
        map_dict[wx.GetApp().GetNavTo().map_name].append(to_node)

        #beam
        beam_node = Node(self.ms.beam_location())
        log.debug("beam_node: %s" % beam_node)
        from_node.edges.append((1, beam_node))
        map_dict[beam_node.payload.map_name].append(beam_node)


        for map_name, map_nodes in map_dict.items():
            for index, item_a in enumerate(map_nodes):
                for item_b in map_nodes[index + 1:]:
                    cost = self.ds.in_map_distance(item_a.payload, item_b.payload)
                    add_edge(cost, item_a, item_b)

        for item, node in node_dict.items():
            other_item = self.ms.other_side(item)
            cost = self.ds.cost(item, other_item)
            cost = 1
            node.edges.append((cost, node_dict[other_item]))

        node_dict[wx.GetApp().GetNavFrom()] = from_node
        node_dict[wx.GetApp().GetNavTo()] = to_node
        node_dict[self.ms.beam_location()] = beam_node

        nodes = node_dict.values()
        for item in nodes:
            log.debug(item)
            for item_b in item.edges:
                log.debug("  %s" % str(item_b))

        from_node.cost = 0
        solve(nodes)
        for item in nodes:
            log.debug(item)
        log.debug("ROUTE:")
        self.__route__ = get_route(nodes, node_dict[wx.GetApp().GetNavTo()])
Example #3
0
    def drawall(self):
        ### 画地图
        self.scene.clear()
        self.x_scale = self.width / self.x_max * 9 / 10
        self.y_scale = self.height / self.y_max * 9 / 10
        for i in range(self.graph.point_num):
            for j in range(self.graph.point_num):
                if self.graph.line[i][j] != 0:
                    x1 = self.graph.x[i] * self.x_scale + self.width / 35
                    y1 = (6000 -
                          self.graph.y[i]) * self.y_scale + self.height / 35
                    x2 = self.graph.x[j] * self.x_scale + self.width / 35
                    y2 = (6000 -
                          self.graph.y[j]) * self.y_scale + self.height / 35
                    # self.scene.addLine(x1, y1, x2, y2, self.pens[self.traffic[self.current_traffic].line[i][j]])
                    self.scene.addLine(
                        x1,
                        y1,
                        x2,
                        y2,
                        QtGui.QPen(
                            Qt.black,
                            10,
                            QtCore.Qt.SolidLine,  # 颜色数字
                            QtCore.Qt.RoundCap,
                            QtCore.Qt.RoundJoin))  #去掉路况后用黑色线画地图

        ### 画最短路径
        route = dijkstra.get_route(self.depart_point, self.arrive_point)
        path = route['path']
        for i in range(len(path) - 1):
            start_point = int(path[i])
            end_point = int(path[i + 1])
            start_x = self.graph.x[start_point -
                                   1] * self.x_scale + self.width / 35
            start_y = (6000 - self.graph.y[start_point - 1]
                       ) * self.y_scale + self.height / 35
            end_x = self.graph.x[end_point -
                                 1] * self.x_scale + self.width / 35
            end_y = (6000 - self.graph.y[end_point -
                                         1]) * self.y_scale + self.height / 35
            self.scene.addLine(
                start_x,
                start_y,
                end_x,
                end_y,
                QtGui.QPen(
                    Qt.cyan,
                    10,
                    QtCore.Qt.SolidLine,  # 颜色数字
                    QtCore.Qt.RoundCap,
                    QtCore.Qt.RoundJoin))

        ### 画当前位置
        self.start_x = self.graph.x[self.start_num -
                                    1] * self.x_scale + self.width / 35
        self.start_y = (6000 - self.graph.y[self.start_num - 1]
                        ) * self.y_scale + self.height / 35
        self.end_x = self.graph.x[self.end_num -
                                  1] * self.x_scale + self.width / 35
        self.end_y = (6000 - self.graph.y[self.end_num -
                                          1]) * self.y_scale + self.height / 35
        self.scene.addLine(
            self.start_x,
            self.start_y,
            self.end_x,
            self.end_y,
            QtGui.QPen(
                Qt.darkGreen,
                10,
                QtCore.Qt.SolidLine,  # 颜色数字
                QtCore.Qt.RoundCap,
                QtCore.Qt.RoundJoin))

        ### 画小车
        # self.x = 1000 + 500 * math.cos(self.second)   #模拟生成位置
        # self.y = 1000 + 500 * math.sin(self.second)
        x = self.x * self.x_scale + self.width / 35 - self.carsize / 20
        y = self.y * self.y_scale + self.height / 35 - self.carsize / 20
        self.scene.addEllipse(x, y, self.carsize, self.carsize, self.pen_car,
                              self.brush_car)

        ### 画起终点
        start_x = self.graph.x[
            self.depart_point -
            1] * self.x_scale + self.width / 35 - self.circle_size / 2
        start_y = (6000 - self.graph.y[self.depart_point - 1]
                   ) * self.y_scale + self.height / 35 - self.circle_size / 2
        end_x = self.graph.x[
            self.arrive_point -
            1] * self.x_scale + self.width / 35 - self.circle_size / 2
        end_y = (6000 - self.graph.y[self.arrive_point - 1]
                 ) * self.y_scale + self.height / 35 - self.circle_size / 2
        self.scene.addEllipse(start_x, start_y, self.circle_size,
                              self.circle_size, self.pen_start_point,
                              self.brush_start)
        self.scene.addEllipse(end_x, end_y, self.circle_size, self.circle_size,
                              self.pen_end_point, self.brush_end)

        ### 画未走路线
        if self.start_flag == False:
            self.draw_end_dist()
Example #4
0
near_locations.sort()

print "\nnear_locations"
pprint(near_locations)
where_am_i = near_locations[0][1]
print "\nnear_location: %s" % where_am_i

#~ where_am_i = find_location_obj(ex.map_name, ex.loc)

#~ where_am_i = find_location_obj('White Stone', (707,162))
#~ where_am_i = find_location_obj('Desert Pines', (166,100))    #sto
#~ where_am_i = find_location_obj('Nordcarn', (51,184))
#~ where_am_i = find_location_obj('Desert Pines', (44,302))
#~ where_am_i = find_location_obj('Desert Pines', (172,12))    #South Exit to Portland
where_am_i.cost = 0

solve(all_nodes)
#~ for item in all_nodes:
    #~ print item

#~ destination_location = find_location_obj('Desert Pines', (44,302))
#~ destination_location = find_location_obj('Nordcarn', (51,184))
destination_location = find_location_obj('Desert Pines', (166,100))    #sto

print "\nRoute"
for item in get_route(all_nodes, destination_location):
    print item

#~ print beam_location_xml