Skip to content

Commit

Permalink
Fix bug in path finder
Browse files Browse the repository at this point in the history
  • Loading branch information
Wissiak committed Dec 3, 2023
1 parent 089400f commit 7ecfe4a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
15 changes: 8 additions & 7 deletions lib/path_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
STEP_SIZE = 5
model = VanillaLSTM(step_size=STEP_SIZE, load_from='trained_models/vanilla-lstm-1')


no_empty_if_below = 0.4
n_days = 5

def get_next_n_days(n_days: int, no_empty_if_below: float):
all_needed_time = []
all_needed_capacity = []
Expand All @@ -59,7 +55,7 @@ def get_next_n_days(n_days: int, no_empty_if_below: float):
print(needed_capacity)
print(visited_stations_by_id)
most_left_point = np.argmin([float(x["lat"]) for x in visited_stations[1:-1]])
tour, locations = path_finder.refine_path(most_left_point+1, visited_stops) # +1 because visited_stations[1:-1]
tour, locations = path_finder.refine_path(most_left_point, visited_stops[1:-1], visited_stations[1:-1])
locations = [station_0] + locations + [station_0]
print(tour)

Expand Down Expand Up @@ -100,7 +96,6 @@ def get_next_n_days(n_days: int, no_empty_if_below: float):

return all_needed_time, all_needed_capacity, all_visited_locations

#get_next_n_days(n_days, no_empty_if_below)

@path_api.route("", methods=['GET'])
def get_path():
Expand All @@ -110,4 +105,10 @@ def get_path():

all_needed_time, all_needed_capacity, all_visited_locations = get_next_n_days(5, no_empty_if_below)

return jsonify({"visited_locations": all_visited_locations, "needed_times": all_needed_time, "needed_capacities": all_needed_capacity})
return jsonify({"visited_locations": all_visited_locations, "needed_times": all_needed_time, "needed_capacities": all_needed_capacity})


if __name__ == '__main__':
no_empty_if_below = 0.4
n_days = 5
get_next_n_days(n_days, no_empty_if_below)
12 changes: 6 additions & 6 deletions lib/path_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
map_file_refined = 'map-output-refined.png'

class PathFinder:
capacity = 10 - 1 # size of trough minus 1 container
capacity = 8 - 1 # size of trough minus 1 container
time_per_working_day = 6 * 60 * 60 # 6 hours in seconds divided by 3 because only 40/120 containers have sensors
time_per_emptying = 15 * 60 # 15 minutes in seconds, 5 minutes per container

Expand Down Expand Up @@ -73,12 +73,12 @@ def find_path(self):

return visited_stops, needed_time, visited_locations, needed_capacity

def refine_path(self, starting_point_idx, visited_stops):
def refine_path(self, starting_point_idx, visited_stops, visited_locations):
# refine path using dijkstra
unvisited = visited_stops[1:-1]
unvisited = visited_stops.copy()
tour = [visited_stops[starting_point_idx]] # Start from the first point
locations = [visited_locations[np.argwhere(np.array(visited_stops) == tour[-1]).ravel()[0]]]
unvisited.remove(tour[-1])
locations = [self.sensor_data.iloc[tour[-1]]["geo_point_2d"].split(", ")]

while unvisited:
current_point = tour[-1]
Expand All @@ -87,7 +87,7 @@ def refine_path(self, starting_point_idx, visited_stops):
if idx in unvisited:
nearest_point = int(idx)
tour.append(nearest_point)
locations.append(self.sensor_data.iloc[nearest_point]["geo_point_2d"].split(", "))
locations.append(visited_locations[np.argwhere(np.array(visited_stops) == nearest_point).ravel()[0]])
unvisited.remove(nearest_point)

return tour, locations
Expand Down Expand Up @@ -135,7 +135,7 @@ def refine_path(self, starting_point_idx, visited_stops):
f.close()

most_left_point = np.argmin([float(x["lat"]) for x in visited_locations[1:-1]])
tour, locations = path_finder.refine_path(most_left_point, visited_stops)
tour, locations = path_finder.refine_path(most_left_point, visited_stops[1:-1], visited_locations[1:-1])
locations = [station_0] + locations + [station_0]

print("Refined path", tour)
Expand Down

0 comments on commit 7ecfe4a

Please sign in to comment.