From: Skullheadx <704277@pdsb.net> Date: Wed, 28 Dec 2022 00:37:09 +0000 (-0500) Subject: fix glitch where 2 points on same spot X-Git-Url: http://git.skullheadx.com/nixos/static/git-logo.png?a=commitdiff_plain;h=5401f0bfa287b8f2237e55704f156671329bec78;p=The-Traveling-Salesman-Problem.git fix glitch where 2 points on same spot --- diff --git a/graph.py b/graph.py index d30f652..7fab2f5 100644 --- a/graph.py +++ b/graph.py @@ -9,11 +9,16 @@ def prune_filename(filename: str) -> int: def create(path: str, width: int, height: int, nodes: int): graph = [] text = f"{width} {height} {nodes}\n" + seen = set() # so that there are no duplicate points - for node in range(nodes): + counter = 0 + while counter < nodes: x, y = (random.randint(0, width), random.randint(0, height)) - graph.append((x, y)) - text += f"{x} {y}\n" + if (x, y) not in seen: + graph.append((x, y)) + text += f"{x} {y}\n" + seen.add((x, y)) + counter += 1 current_file = 0 for root, dirs, files in os.walk(path):