|
Hi guys!
So I'm doing a project on the Travelling Salesman Problem and thought that it would be easiest to do it through mathematica as it seems like I have the most programming experience through that program. Anyways, I'm pretty much done..except for one thing. I want my graph to display what the Distance the computer found!
Here's what I have so far..
+ Show Spoiler +
Manipulate[ With[{p = RandomInteger[10, {n, 2}]}, Graphics[{Line[p[[Last[FindShortestTour[p]]]]], PointSize[Large], Red, Point[p]}]], {n, 1, 50, 1}]
I'll add a screenshot later, but in between my Manipulate function i want it to show the distance mathematica found to be the shortest. Any guesses?
|
Well, the first return value of FindShortestTour is the distance.
So do you want something like this? + Show Spoiler + Manipulate[ Module[{p = RandomInteger[10, {n, 2}], tour}, tour = FindShortestTour[p]; Column[{ "Distance: " <> ToString@N[First@tour], Graphics[ {Line[p[[Last[tour]]]], PointSize[Large], Red, Point[p]}] }] ], {n, 1, 50, 1}]
|
United States10328 Posts
oh my, np-complete problems? perhaps I should learn to use mathematica
|
On May 07 2009 13:17 overpool wrote:Well, the first return value of FindShortestTour is the distance. So do you want something like this? + Show Spoiler + Manipulate[ Module[{p = RandomInteger[10, {n, 2}], tour}, tour = FindShortestTour[p]; Column[{ "Distance: " <> ToString@N[First@tour], Graphics[ {Line[p[[Last[tour]]]], PointSize[Large], Red, Point[p]}] }] ], {n, 1, 50, 1}]
YES perfect, I didn't think about doing the return value first..
|
I'm looking for people who'd like to collaborate on linear programming models in Mathematica of SC2 for optimization solutions. I have a ludicrously expensive optimization book that's a few versions out of date, and rusty Mathematica and operations research skills, but its a project I've wanted to do for years.
Anyone else interested?
|
You want to use LPs to solve SC2 optimization problems? Sounds like it'd be pretty intense. I'm an OR major, you can PM me and I'll see if I can help you formulate the problem, but I've never used Mathematica.
|
|
|
|