Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code to generate position of cities randomly for Traveling Salesman Problem
import json
import random
cities = []
nnmax = 50
for nn in range(nnmax):
city = {}
city['id'] = nn
city['x'] = (random.random() - 0.5)*2
city['y'] = (random.random() - 0.5)*2
cities.append(city)
with open('city_info.json', "w") as file:
json.dump(cities, file, sort_keys=True, indent=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment