Travelling salesman variation in python

Terry Reedy tjreedy at udel.edu
Fri Apr 2 12:06:13 EST 2004


"Erlend Andreas Garberg" <erlendga at tva.ifi.uio.no> wrote in message
news:slrnc6on9h.spl.erlendga at tva.ifi.uio.no...
> Example:
> Nodes:
> A with numbers B->1200, C->2000
> B with numbers A->3000, C->4000
> C with numbers A->9000, B->5000
>
> The optimal ring is in this case can f.ex. be:
> A->1200->B->4000->C->9000->A with sum 14200.
>
> I have implemented this in python in the following way:
>
> hash is a dictionary with node-name as key and node-object as value.
> Each node-object has a dictionary speeds with node-name as key and a
> number as value. this dict stores the numbers associated with the other
> nodes.

If you number (0 -- n-1) rather than name the nodes, then you just need a
nodes array and a speed array for each node.  That should make your code a
bit simpler and easier to play with.  It should also be a bit faster, but a
good approximation algorithm will be **far** more important.  There is at
least one book on the TSP.

Terry J. Reedy







More information about the Python-list mailing list