Skip to content

Instantly share code, notes, and snippets.

@TakahisaShiratori
Last active June 26, 2016 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TakahisaShiratori/14509bcd9c8df3a7a2332949aee55d37 to your computer and use it in GitHub Desktop.
Save TakahisaShiratori/14509bcd9c8df3a7a2332949aee55d37 to your computer and use it in GitHub Desktop.
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