title: Generating a map/graph for a traveling salesmanproblem (Python)
body: <p>I'm going to create a couple of algorithms to solve a traveling salesman problem, but first I'm to create a graph/map with n nodes and every node has a border. (if n=100 then it's 99 borders). Distance between each node should be a random number from 1 to 5.</p>
  
  <p>(I'm doing this in python)
  My first thought was for each node to have a list (final map will then be lists within a list) with distances to the other nodes.
  If 10 nodes, then each list will have 9 integers in them.</p>
  
  <p>After generating the first list, the other lists would inherit the corresponding distances.
  Ex.  </p>
  
  <pre><code>A: [5, 5, 3]
  B: [5]
  C: [5]
  D: [3]
  </code></pre>
  
  <p>Next step is to generate a new list with one less element, place it behind the value that's already there and do the same as above (rest of the nodes will inherit the corresponding distances). This would be done recursively until all the lists are full.</p>
  
  <p>Final list will look something list this:  </p>
  
  <pre><code>[[5, 5, 3],
   [5, 2, 1],
   [5, 2, 4],
   [3, 1, 4]
  </code></pre>
  
  <p>Could someone give me a hint of how I should go about implementing this?
  Or maybe if there's a much simpler method. Thanks!</p>
  
  <p>import random</p>
  
  <pre><code>def main():
      graph_map = []
      max_nodes = 10
      i = 0
      generate_map(graph_map, max_nodes, i)
      print graph_map
  
  def generate_map(graph_map, max, i):
      temp_list = []
      for j in range(max-1):
          temp_list.append(random.randint(1, 5))
      if i &gt; 0:
          graph_map[i].append(temp_list)
      else:
          graph_map.append(temp_list)
  
      for j in range(1, max):
          graph_map.append([temp_list[j-1]])
  
  
  
  
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>This code will give me the start I wanted with sample output:</p>
  
  <pre><code>[[4, 5, 5, 2, 1, 3, 3, 3, 2], [4], [5], [5], [2], [1], [3], [3], [3], [2]]
  </code></pre>