Skip to content

Commit

Permalink
changed example
Browse files Browse the repository at this point in the history
  • Loading branch information
wmatecki97 committed Sep 28, 2024
1 parent b25fab5 commit 899ad9f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 52 deletions.
2 changes: 1 addition & 1 deletion generate_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def save_examples(examples, filename="tsp_examples.json"):
json.dump(examples, f, indent=2)

if __name__ == "__main__":
examples = generate_examples(num_examples=1, min_cities=20, max_cities=20)
examples = generate_examples(num_examples=1, min_cities=15, max_cities=15)
save_examples(examples)
print(f"Generated 10 TSP examples and saved them to tsp_examples.json")

Expand Down
Binary file added local minimum demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion program.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def crossover(parent1, parent2):
return Tour(child_cities)

class GeneticAlgorithm:
def __init__(self, cities, population_size=100, elite_size=20, mutation_rate=0.00, generations=1500):
def __init__(self, cities, population_size=100, elite_size=20, mutation_rate=0.00, generations=200):
self.cities = cities
self.population_size = population_size
self.elite_size = elite_size
Expand Down
80 changes: 30 additions & 50 deletions tsp_examples.json
Original file line number Diff line number Diff line change
@@ -1,84 +1,64 @@
[
[
{
"x": 91,
"y": 30
"x": 54,
"y": 87
},
{
"x": 53,
"y": 58
},
{
"x": 34,
"y": 22
},
{
"x": 64,
"y": 6
},
{
"x": 36,
"y": 44
},
{
"x": 51,
"y": 1
},
{
"x": 13,
"y": 93
"x": 62,
"y": 71
},
{
"x": 100,
"y": 76
"x": 44,
"y": 34
},
{
"x": 16,
"y": 66
"x": 21,
"y": 65
},
{
"x": 63,
"y": 60
"x": 61,
"y": 53
},
{
"x": 87,
"y": 66
"x": 60,
"y": 4
},
{
"x": 2,
"y": 30
"x": 76,
"y": 84
},
{
"x": 59,
"y": 18
"x": 8,
"y": 40
},
{
"x": 62,
"y": 82
"x": 80,
"y": 61
},
{
"x": 64,
"y": 64
"x": 41,
"y": 15
},
{
"x": 77,
"y": 74
"x": 7,
"y": 57
},
{
"x": 94,
"y": 55
"x": 99,
"y": 6
},
{
"x": 10,
"y": 44
"x": 27,
"y": 96
},
{
"x": 24,
"y": 35
"x": 30,
"y": 87
},
{
"x": 8,
"y": 7
"x": 100,
"y": 66
}
]
]

0 comments on commit 899ad9f

Please sign in to comment.