--- /dev/null
+from queue import Queue
+from graph import calculate_distance
+
+
+def brute_force(graph: list) -> list:
+ routes = []
+ q = Queue()
+ q.put([])
+
+ while not q.empty():
+ current = q.get()
+ if len(current) == len(graph):
+ current.append(current[0])
+ routes.append(current)
+ continue
+
+ for node in graph:
+ if node not in current:
+ temp = current[:]
+ temp.append(node)
+ q.put(temp)
+
+ shortest_distance = None
+ shortest_route = []
+ for route in routes:
+ distance = calculate_distance(route)
+ if shortest_distance is None or distance < shortest_distance:
+ shortest_distance = distance
+ shortest_route = route
+
+ return shortest_route
from graph import create
from display import Display
+from brute_force import brute_force
import os
GRAPH_PATH = "graphs/"
+DELETE_PREVIOUS_FILES = True
def main():
- graph, filename = create(GRAPH_PATH, 640, 640, 20)
+ if DELETE_PREVIOUS_FILES:
+ for root, dirs, files in os.walk("graphs/"):
+ for name in files:
+ path = os.path.join(root, name)
+
+ if os.path.exists(path):
+ os.remove(path)
+ else:
+ print("The file does not exist")
+
+ graph, filename = create(GRAPH_PATH, 640, 640, 5)
display = Display(os.path.join(GRAPH_PATH, filename))
- display.show(graph)
+ route = brute_force(graph)
+
+ display.show(route)
if __name__ == "__main__":