|
|
@ -49,11 +49,11 @@ namespace komvo |
|
|
|
for (int i = 0; i <= toSwap.Length - 1; i++) toSwap[i] = i + 2; |
|
|
|
for (int i = 0; i <= toSwap.Length - 1; i++) toSwap[i] = i + 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < toSwap.Length; i++) WriteLine(toSwap[i]); |
|
|
|
//for (int i = 0; i < toSwap.Length; i++) WriteLine(toSwap[i]); |
|
|
|
|
|
|
|
|
|
|
|
int fct = Fact(Points.Count - 1); |
|
|
|
int fct = Fact(Points.Count - 1); |
|
|
|
|
|
|
|
|
|
|
|
int[] routes = new int[fct]; |
|
|
|
string[] routes = new string[fct]; |
|
|
|
double[] leng = new double[fct]; |
|
|
|
double[] leng = new double[fct]; |
|
|
|
|
|
|
|
|
|
|
|
double optim = leng[0]; |
|
|
|
double optim = leng[0]; |
|
|
@ -64,19 +64,20 @@ namespace komvo |
|
|
|
foreach(IList<int> p in perm) |
|
|
|
foreach(IList<int> p in perm) |
|
|
|
{ |
|
|
|
{ |
|
|
|
string res = string.Empty; |
|
|
|
string res = string.Empty; |
|
|
|
for (int i = 0; i < toSwap.Length; i++) res += p[i].ToString(); |
|
|
|
for (int i = 0; i < toSwap.Length; i++) res += p[i].ToString() + ";"; |
|
|
|
routes[index++] = int.Parse(res); |
|
|
|
routes[index++] = res; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < routes.Length; i++) WriteLine(routes[i]); |
|
|
|
//for (int i = 0; i < routes.Length; i++) WriteLine(routes[i]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CountLen(ref leng, Matrix, routes); |
|
|
|
//CountLen(ref leng, Matrix, routes); |
|
|
|
|
|
|
|
CountLen2(ref leng, Matrix, routes); |
|
|
|
SearchBest(ref optim, ref oIndex, routes, leng); |
|
|
|
SearchBest(ref optim, ref oIndex, routes, leng); |
|
|
|
Debug(routes); |
|
|
|
//Debug(routes); |
|
|
|
|
|
|
|
|
|
|
|
WriteLine("\n\n1{1}1 - оптимальный маршрут длинной {0:00.00}\nВсего маршрутов {2}\n{4} {3}", |
|
|
|
WriteLine("\n\n1{1}1 - оптимальный маршрут длинной {0:00.00}\nВсего маршрутов {2}\n{4} {3}", |
|
|
|
optim, routes[oIndex], routes.Length, fct, Points.Count); |
|
|
|
optim, routes[oIndex], routes.Length, fct, Points.Count); |
|
|
@ -86,12 +87,47 @@ namespace komvo |
|
|
|
ReadKey(); |
|
|
|
ReadKey(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void CountLen (ref double[] result, double[,] mtr, int[] rts) |
|
|
|
|
|
|
|
|
|
|
|
public static void CountLen2(ref double[] result, double[,] mtr, string[] rts) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
//WriteLine("loading 00%"); |
|
|
|
|
|
|
|
for (int i = 0; i < rts.Length; i++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
double res = 0; |
|
|
|
|
|
|
|
//char[] ch = rts[i].ToCharArray(); |
|
|
|
|
|
|
|
//CursorLeft -= 3; |
|
|
|
|
|
|
|
//int percent = i / rts.Length * 100; |
|
|
|
|
|
|
|
//Write("{0:00}%"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string[] index = rts[i].Split(';'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < index.Length - 1; j++) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
string dg = index[j]; |
|
|
|
|
|
|
|
int db = int.Parse(index[j]) - 2; //debug |
|
|
|
|
|
|
|
string db1 = rts[i].ToString(); //debug |
|
|
|
|
|
|
|
if (j == 0) res += mtr[0, int.Parse(index[j]) - 1]; |
|
|
|
|
|
|
|
else if (j == index.Length - 1) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
res += mtr[int.Parse(index[j - 1]) - 2, int.Parse(index[j]) - 2]; |
|
|
|
|
|
|
|
res += mtr[0, int.Parse(index[j]) - 2]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
res += mtr[int.Parse(index[j - 1]) - 2, int.Parse(index[j]) - 2]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
result[i] = res; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void CountLen (ref double[] result, double[,] mtr, string[] rts) |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (int i = 0; i < rts.Length; i++) |
|
|
|
for (int i = 0; i < rts.Length; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
double res = 0; |
|
|
|
double res = 0; |
|
|
|
char[] ch = rts[i].ToString().ToCharArray(); |
|
|
|
char[] ch = rts[i].ToCharArray(); |
|
|
|
for (int j = 0; j < ch.Length; j++) |
|
|
|
for (int j = 0; j < ch.Length; j++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int db = int.Parse(ch[j].ToString()) - 1; //debug |
|
|
|
int db = int.Parse(ch[j].ToString()) - 1; //debug |
|
|
@ -111,13 +147,13 @@ namespace komvo |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void SearchBest(ref double optim, ref int oIndex, int[] routes, double[] leng) |
|
|
|
public static void SearchBest(ref double optim, ref int oIndex, string[] routes, double[] leng) |
|
|
|
{ |
|
|
|
{ |
|
|
|
optim = leng[0]; |
|
|
|
optim = leng[0]; |
|
|
|
oIndex = 0; |
|
|
|
oIndex = 0; |
|
|
|
for (int i = 0; i < leng.Length; i++) |
|
|
|
for (int i = 0; i < leng.Length; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
WriteLine("{0:N2} - {1}", leng[i], routes[i]); |
|
|
|
//WriteLine("{0:N2} - {1}", leng[i], routes[i]); |
|
|
|
if (optim > leng[i]) |
|
|
|
if (optim > leng[i]) |
|
|
|
{ |
|
|
|
{ |
|
|
|
optim = leng[i]; |
|
|
|
optim = leng[i]; |
|
|
@ -126,7 +162,7 @@ namespace komvo |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void Debug (int[] routes) |
|
|
|
public static void Debug (string[] routes) |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (int i = 0; i < routes.Length; i++) |
|
|
|
for (int i = 0; i < routes.Length; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|