def build_polygon_graph(polygons): polygon_graph = {} count_p = 0 for p in polygons: previous = Node() first = Node() count_n = 0 for n in p: new_id = "P{}.{}".format(count_p + 1, count_n) polygon_graph[new_id] = Node(vec.Coord(n.x, n.y), new_id) current = polygon_graph[new_id] if previous.is_proper(): edge_id = "E{}.{}".format(count_p + 1, count_n) w = compute_weight(previous, current) previous.add_neighbour(Edge(w, previous, current, edge_id)) current.add_neighbour(Edge(w, current, previous, edge_id)) if count_n == 0: first = current previous = current count_n += 1 if count_n == len(p): edge_id = "E{}.{}".format(count_p + 1, count_n) w = compute_weight(current, first) current.add_neighbour(Edge(w, current, first, edge_id)) first.add_neighbour(Edge(w, first, current, edge_id)) count_p += 1 return polygon_graph
def __init__(self, coordinates=vec.Coord(-1, -1), id="undefined"): self.coord = coordinates self.neighbours = [] self.id = id # Hilfsattribute für Dijkstra self.distance = 0 self.visited = False self.prev = ""
def get_information(meter, v_graph, p_graph, start_node): departure = Time.Time(7, 30, 0) end_node = gr.Node(vec.Coord(0, meter), "B") gr.update_visibility(v_graph, p_graph, end_node) gr.dijkstra(v_graph, start_node) distance = end_node.distance bt = shortest_runtime(meter, "Bus") lt = shortest_runtime(distance, "Lisa") meeting_time = Time.add_seconds(departure, bt) leaving_time = Time.subtract_seconds(meeting_time, lt) print("Startzeit: {}".format(leaving_time)) print("Endzeit: {}".format(meeting_time)) print("y-Koordinate Bus: {} m".format(meter)) print("Laufdistanz: {} m".format(distance)) print("Laufdauer: {} min".format(Time.sec_in_min(lt))) print(gr.traversed_nodes(v_graph, end_node)) svg = Graphics.read_svg(case + ".svg") Graphics.visualise_path(svg, v_graph, end_node) Graphics.output_svg(svg, "shortest_path_final")
def find_leaving_time(lower, higher, step, p_graph, v_graph, start_node, end_node): departure = Time.Time(7, 30, 0) meter = 0 gr.dijkstra(v_graph, start_node) distance = end_node.distance # Zeit die Lisa braucht lt = shortest_runtime(distance, "Lisa") # Zeit die Bus braucht bt = shortest_runtime(meter, "Bus") # Zeit bei Treffpunkt, d.h Endzeit meeting_time = Time.add_seconds(departure, bt) # Startzeit leaving_time = Time.subtract_seconds(meeting_time, lt) # Initialisierung der Bestzeit (mit dazugehöriger y-Koordinate) current_best_time = leaving_time current_best_meter = meter times = [] # Finden des spätesten Hausverlasszeitpunkts for meter in range(lower, higher): if meter % step == 0: end_node = gr.Node(vec.Coord(0, meter), "B") gr.update_visibility(v_graph, p_graph, end_node) gr.dijkstra(v_graph, start_node) distance = end_node.distance lt = shortest_runtime(distance, "Lisa") bt = shortest_runtime(meter, "Bus") meeting_time = Time.add_seconds(departure, bt) leaving_time = Time.subtract_seconds(meeting_time, lt) if leaving_time > current_best_time: current_best_time = leaving_time current_best_meter = meter times.append(leaving_time.seconds_from_midnight()) # Plot of possible leaving times x = np.arange(lower, higher, step) plt.plot(x, times) plt.show() return current_best_meter
# Geschwindigkeit in m/s speed_lisa = 15.0 / 3.6 speed_bus = 30.0 / 3.6 # Daten einlesen f = open(case+".txt", "r") p = int(f.readline()) # Koordinaten Polygone polygons = [] for i in range(p): line = f.readline() coord = [] count = 0 for number in line.split(): if count % 2 != 0: coord.append(vec.Coord(pos_x=int(number))) if count % 2 == 0 and count != 0: coord[int((count / 2) - 1)].set_y(int(number)) count += 1 polygons.append(coord) # Koordinaten Haus line = f.readline() coord_h = [] for number in line.split(): coord_h.append(int(number)) start_x = coord_h[0] start_y = coord_h[1] f.close() # Startknoten start = vec.Coord(start_x, start_y)