def Astarsearch(graph, startpoint, start_time, time_dict, rest_list, place_to_rest, move_time, ptr_time): pq = PriorityQueue() n_nodes = len(graph.vertices()) mstCost = MST.mstCost(graph, [startpoint]) frontier = Frontier(mstCost, 0.0, [startpoint], startpoint, start_time) pq.put(frontier) found = False sequence = [startpoint] while (not found): curr = pq.get() if (len(curr.seq) == n_nodes and curr.eat_lunch == False and curr.eat_dinner == False): sequence = curr.seq cost = curr.prevCost + curr.mstCost break if (len(curr.seq) == n_nodes + 2 and curr.eat_lunch == True and curr.eat_dinner == True): sequence = curr.seq cost = curr.prevCost + curr.mstCost # print(sequence) # print(cost) #print(curr.cur_pathcost) break if (len(curr.seq) == n_nodes + 1 and curr.eat_dinner == True): # ate dinner sequence = curr.seq cost = curr.prevCost + curr.mstCost # print(sequence) # print(cost) #print(curr.cur_pathcost) break if (len(curr.seq) == n_nodes + 1 and curr.eat_lunch == True): sequence = curr.seq cost = curr.prevCost + curr.mstCost print(curr.cur_time) # print(cost) #print(curr.cur_pathcost) break if (curr.cur_time.time() >= dt.datetime.time( dt.datetime(100, 1, 1, 11, 00, 00)) and curr.cur_time.time() <= dt.datetime.time( dt.datetime(100, 1, 1, 13, 00, 00)) and not curr.eat_lunch): curr.eat_lunch = True findrest(rest_list, curr, pq, 0, place_to_rest, ptr_time) continue if (curr.cur_time.time() >= dt.datetime.time( dt.datetime(100, 1, 1, 17, 00, 00)) and curr.cur_time.time() <= dt.datetime.time( dt.datetime(100, 1, 1, 20, 00, 00)) and not curr.eat_dinner): curr.eat_dinner = True findrest(rest_list, curr, pq, 1, place_to_rest, ptr_time) continue # put restaurant into the frontier and do the other loop. adj_edges = graph.get_edges(curr.cur_vertex) # get all the adj edges. new_visited = [] for vertex in curr.seq: new_visited.append(vertex) for edge in adj_edges: cur_visit = [] for vertex in new_visited: cur_visit.append(vertex) if edge.dest not in cur_visit: cur_visit.append(edge.dest) time = timeadder( time_dict[edge.dest] + int(move_time[(curr.cur_vertex, edge.dest)]), curr.cur_time) cur_mstCost = MST.mstCost(graph, cur_visit) frontier = Frontier(cur_mstCost, curr.prevCost + float(edge.weight), cur_visit, curr.cur_vertex, time, curr.eat_lunch, curr.eat_dinner) pq.put(frontier) return sequence