Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion waypoint/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from waypoint.preprocessing import file_to_graph, file_to_airports
from waypoint.algorithms import djikstra
from waypoint.algorithms import djikstra, bfs


def main():
Expand All @@ -8,11 +8,22 @@ def main():

# Example: Find path from BOS to MCO
path = djikstra(graph, 10721, 11953)
print("Djikstra Path from BOS to MCO:")
if path.flights is None:
print("No path found")
return
for airport_id in path.flights:
print(airports[airport_id])
print(path.time)

path = bfs(graph, 10721, 11953)
print("BFS Path from BOS to MCO:")
if path.flights is None:
print("No path found")
return
for airport_id in path.flights:
print(airports[airport_id])
print(path.time)


if __name__ == "__main__":
Expand Down
29 changes: 20 additions & 9 deletions web/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from flask import Flask, render_template, request, jsonify

from waypoint.preprocessing import file_to_graph, file_to_airports
from waypoint.algorithms import djikstra
from waypoint.algorithms import djikstra, bfs
from waypoint.path import Path

app = Flask(__name__)
Expand Down Expand Up @@ -33,19 +33,30 @@ def process():
start = int(data["start"])
end = int(data["end"])

path = djikstra(graph, start, end)
path1 = djikstra(graph, start, end)
path2 = bfs(graph, start, end)

if path == Path.empty():
if path1 == Path.empty() or path2 == Path.empty():
return jsonify({"message": "No path found."})

return jsonify(
{
"flights": (
[airports[airport_id] for airport_id in path.flights]
if path.flights is not None
else []
),
"time": path.time,
"djikstra": {
"flights": (
[airports[airport_id] for airport_id in path1.flights]
if path1.flights is not None
else []
),
"time": path1.time,
},
"bfs": {
"flights": (
[airports[airport_id] for airport_id in path2.flights]
if path2.flights is not None
else []
),
"time": path2.time,
},
}
)

Expand Down
9 changes: 7 additions & 2 deletions web/static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ routeBtn.addEventListener("click", async () => {
if (json.message) output.textContent = json.message;
else {
output.textContent =
json.flights.map((airport) => `${airport}`).join("\n") +
`\nTotal travel time: ${json.time} minutes`;
"Route found using Djikstra's Algorithm:\n\n" +
json.djikstra.flights.map((airport) => `${airport}`).join("\n") +
`\nTotal travel time: ${json.djikstra.time} minutes` +
"\n\n" +
"Route found using BFS Algorithm:\n\n" +
json.bfs.flights.map((airport) => `${airport}`).join("\n") +
`\nTotal travel time: ${json.bfs.time} minutes`;
}
} catch (err) {
output.textContent = `Error: ${err.message}`;
Expand Down