The code below is returning a zero value for the calculation of distance of selected route(array). I have been trying to debug it but to no avail. Additionally, I will like points or cities modeled as array, to be randomly generated from mouse clicks on a map in picBox. Can anyone please help or give some hints?

namespace TSA { class Route { ArrayList Cities = new ArrayList(); double travelCost; int dist; public double RunGA(int numCities, int[,] distancematrix) { for (int i = 0; i < distancematrix.Length; i++) { for (int j = 0; j < distancematrix.Length; j++) { Cities.Add(distancematrix); } } // distancematrix = new int[numCities,numCities]; int dX = 0; int dY = 0; for (int i = 0; i < numCities; i++) { for (int j = i; j < numCities; j++) { if (i == j) distancematrix[i, j] = 0; else { dX = Math.Abs(((Point)Cities[i]).X - ((Point)Cities[j]).X); dY = Math.Abs(((Point)Cities[i]).Y - ((Point)Cities[j]).Y); dist = (int)(Math.Sqrt(dX * dX + dY * dY)); distancematrix[i, j] = dist; distancematrix[j, i] = dist; } } } travelCost = (double)dist; return travelCost; } } } namespace TSA { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnRunGA_Click(object sender, EventArgs e) { int numcities = 6; Route r = new Route(); double cost=r.RunGA(numcities, new int[,] { {0, 20, 25, 15, 45, 32 }, {20, 0, 35, 17, 28, 39 }, {25, 35, 0, 45, 35, 22 }, {15, 17, 45, 0, 15, 42 }, {45, 28, 35, 15, 0, 52 }, {32, 39, 22, 42, 52, 0 } }); MessageBox.Show("Cost for this Rout is: " +"" + cost.ToString()); } } }

Thank you.

nanosystems

MOD EDIT: Fixed code tags. The RIGHT way to use code tags:

This post has been edited by **JackOfAllTrades**: 30 April 2011 - 05:25 AM