--- /dev/null
+import pygame
+
+
+pygame.init()
+
+WHITE = (255, 255, 255)
+BLACK = (0, 0, 0)
+GRAY = (128, 128, 128)
+BLUE = (0, 0, 255)
+
+
+class Node:
+ background_colour = GRAY
+ outline_colour = BLACK
+ text_colour = WHITE
+
+ radius = 15
+ thickness = 1
+ font = pygame.font.SysFont("arial", 15)
+
+ def __init__(self, position: tuple, number: int) -> None:
+ self.position = pygame.Vector2(position)
+ self.text = self.font.render(str(number), True, self.text_colour)
+
+ def draw(self, surf: pygame.Surface) -> None:
+ pygame.draw.circle(surf, self.background_colour, self.position, self.radius)
+ pygame.draw.circle(surf, self.outline_colour, self.position, self.radius, width=self.thickness)
+ surf.blit(self.text, self.text.get_rect(center=self.position))
+
+
+class Display:
+
+ def __init__(self, path: str) -> None:
+ with open(path, "r") as f:
+ contents = f.read().split("\n")
+ if contents[-1] == "":
+ contents = contents[:-1]
+
+ self.WIDTH, self.HEIGHT, self.N = tuple(map(int, contents[0].split(" ")))
+ self.nodes = [Node(tuple(map(int, node.split(" "))), num) for num, node in enumerate(contents[1:])]
+ self.screen = pygame.display.set_mode((self.WIDTH, self.HEIGHT))
+ self.is_running = True
+
+ self.clock = pygame.time.Clock()
+ self.delta = 0
+
+ def show(self, route: list) -> None:
+ while self.is_running:
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ self.is_running = False
+
+ self.screen.fill(WHITE)
+
+ if len(route) > 1:
+ pygame.draw.aalines(self.screen, BLUE, True, route, 5)
+
+ for node in self.nodes:
+ node.draw(self.screen)
+
+ pygame.display.update()
+ self.delta = self.clock.tick(60)
--- /dev/null
+import os
+import random
+
+
+def prune_filename(filename: str) -> int:
+ return int(filename[5:-4])
+
+
+def create(path: str, width: int, height: int, nodes: int):
+ graph = []
+ text = f"{width} {height} {nodes}\n"
+
+ for node in range(nodes):
+ x, y = (random.randint(0, width), random.randint(0, height))
+ graph.append((x, y))
+ text += f"{x} {y}\n"
+
+ current_file = 0
+ for root, dirs, files in os.walk("graphs/"):
+ for name in files:
+ current_file = max(current_file, prune_filename(name))
+ filename = f"graph{current_file + 1}.txt"
+ with open(os.path.join(path, filename), "w") as f:
+ f.write(text[:-1])
+
+ return graph, filename
+
+
+def distance(x1: int, x2: int, y1: int, y2: int) -> float:
+ return pow(pow(x1 - x2, 2) + pow(y1 - y2, 2), 0.5)
+
+
+def get_distances(graph: list) -> dict:
+ distances = dict()
+ for i in graph:
+ distances[i] = dict()
+ x1, y1 = i
+ for j in graph:
+ x2, y2 = j
+ distances[i][j] = distance(x1, x2, y1, y2)
+ return distances
--- /dev/null
+from graph import create
+from display import Display
+import os
+
+GRAPH_PATH = "graphs/"
+
+
+def main():
+ graph, filename = create(GRAPH_PATH, 640, 640, 20)
+ display = Display(os.path.join(GRAPH_PATH, filename))
+
+ display.show(graph)
+
+
+if __name__ == "__main__":
+ main()