diff --git a/.vs/comivoyar/v15/.suo b/.vs/comivoyar/v15/.suo index 066d4d7..3318954 100644 Binary files a/.vs/comivoyar/v15/.suo and b/.vs/comivoyar/v15/.suo differ diff --git a/comivoyar/Program.cs b/comivoyar/Program.cs index 5a567f3..cd6a549 100644 --- a/comivoyar/Program.cs +++ b/comivoyar/Program.cs @@ -57,30 +57,42 @@ namespace komvo int[] toSwap = new int[Points.Count - 1]; for (int i = 0; i <= toSwap.Length - 1; i++) toSwap[i] = i + 2; - int index = 0; + bool first = true; double opLength = 0, prevResult = 0; string opRoute = string.Empty; Permutations perm = new Permutations(toSwap); foreach(IList p in perm) { - string route = string.Empty; - for (int i = 0; i < toSwap.Length; i++) route += p[i].ToString() + ";"; - opLength = CountLength(Matrix, route); + int[] route = new int[Points.Count - 1]; + for (int i = 0; i < toSwap.Length; i++) route[i] = p[i]; + prevResult = CountLength(Matrix, route); + //WriteLine(opLength); - if (index != 0) + if (first) { - if (opLength > prevResult) - { - opLength = prevResult; - opRoute = route; - } + opLength = prevResult; + first = false; } - else prevResult = opLength; - index++; + if(opLength > prevResult) + { + opLength = prevResult; + opRoute = string.Empty; + foreach (int i in route) opRoute += i + ";"; + } } + + //int[] toSwapNew = new int[Points.Count - 1]; + //for (int i = 0; i <= toSwap.Length - 1; i++) toSwapNew[i] = i + 2; + //foreach (int i in toSwapNew) Write(i + " "); + + + + + + WriteLine("\n\n1;{1}1 - оптимальный маршрут длинной {0:00.00}\nИз {2} маршрутов при {3} точках\nПосчитано за {4} мс\n\n", opLength, opRoute, Fact(Points.Count-1), Points.Count, stopwatch.ElapsedMilliseconds); stopwatch.Stop(); @@ -95,22 +107,21 @@ namespace komvo } } - public static double CountLength(double[,] mtr, string route) + public static double CountLength(double[,] mtr, int[] route) { double result = 0; - string[] index = route.Split(';'); - for (int j = 0; j < index.Length - 1; j++) + for (int j = 0; j < route.Length - 1; j++) { - if (j == 0) result += mtr[0, int.Parse(index[j]) - 1]; - else if (j == index.Length - 1) + if (j == 0) result += mtr[0, route[j] - 1]; + else if (j == route.Length - 1) { - result += mtr[int.Parse(index[j - 1]) - 2, int.Parse(index[j]) - 2]; - result += mtr[0, int.Parse(index[j]) - 2]; + result += mtr[route[j - 1] - 2, route[j] - 2]; + result += mtr[0, route[j] - 2]; } else { - result += mtr[int.Parse(index[j - 1]) - 2, int.Parse(index[j]) - 2]; + result += mtr[route[j - 1] - 2, route[j] - 2]; } } return result; diff --git a/comivoyar/bin/Debug/comivoyar.exe b/comivoyar/bin/Debug/comivoyar.exe deleted file mode 100644 index 3e29095..0000000 Binary files a/comivoyar/bin/Debug/comivoyar.exe and /dev/null differ diff --git a/comivoyar/bin/Debug/comivoyar.pdb b/comivoyar/bin/Debug/comivoyar.pdb index f00be1a..7408d41 100644 Binary files a/comivoyar/bin/Debug/comivoyar.pdb and b/comivoyar/bin/Debug/comivoyar.pdb differ diff --git a/comivoyar/obj/Debug/comivoyar.exe b/comivoyar/obj/Debug/comivoyar.exe index 3e29095..a828299 100644 Binary files a/comivoyar/obj/Debug/comivoyar.exe and b/comivoyar/obj/Debug/comivoyar.exe differ diff --git a/comivoyar/obj/Debug/comivoyar.pdb b/comivoyar/obj/Debug/comivoyar.pdb index f00be1a..7408d41 100644 Binary files a/comivoyar/obj/Debug/comivoyar.pdb and b/comivoyar/obj/Debug/comivoyar.pdb differ