       Re: Traveling Salesman

• To: mathgroup at smc.vnet.net
• Subject: [mg35516] Re: [mg35497] Traveling Salesman
• From: Andrzej Kozlowski <andrzej at yhc.att.ne.jp>
• Date: Wed, 17 Jul 2002 02:09:09 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```It depends which version of the Combinatorica package you have. If it is
the one which comes with Mathematica 4.1 and earlier you have to do
something like this. First write your matrix using the proper
Mathematica syntax.

m = {{0 , 1,  3,  4}, {1,  0,  2,  6}, {3,  2 , 0 , 5}, {4 , 6,  5 , 0}};

What you need to do is to create a graph with m as its adjacency matrix
and apply the TravelingSalesman function to it. Here is one way to do
this:

In:=
TravelingSalesman[Graph[m,CircularVertices]]

Out=
{1,2,3,4,1}

If you have the new Combinatorica package which comes with version 4.2
of Mathematica or the pre-released version that I am using (assuming
that they are the same in this respect!) then  the answer by evaluating:

In:=

Out=
{1,2,3,4,1}

Andrzej Kozlowski
Toyama International University
JAPAN
http://platon.c.u-tokyo.ac.jp/andrzej/

On Tuesday, July 16, 2002, at 04:50  AM, Nathan Given wrote:

> I am looking for some help with the Traveling Salesman problem.
>
> I have one matrix that has the distances in miles between cities, it
> looks like this...
>
>
> [0  1  3  4]
> [1  0  2  6]
> [3  2  0  5]
> [4  6  5  0]
>
> Now, how do I use the traveling salesman algorithm in mathematica to
> help me with this?
>
> (I am new to mathematica)
>
> Thus far, here is what I have accomplished...
>
>  << DiscreteMath`Combinatorica`
>
>
> Thanks!
> --
> Nathan
>
>
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~
> Nathan G. Given
> ngiven at lanl.gov
> (505) 662 - 5919 x201
> (505) 663 - 3406
> X-5, Applied Physics
> MS F663
> ~~~~~~~~~~~~~~~~~~~~~~~
>
>
>

```

• Prev by Date: RE: Constructing a Special Form for 'MatrixForm'
• Next by Date: RE: help in generating a gaussian random variable
• Previous by thread: Re: Traveling Salesman
• Next by thread: Expanding expressions with Dot, Times and Plus