Last active
June 26, 2016 04:23
-
-
Save TakahisaShiratori/14509bcd9c8df3a7a2332949aee55d37 to your computer and use it in GitHub Desktop.
Code to generate position of cities randomly for Traveling Salesman Problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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