Browse Source

v1.1

master
parent
commit
5138ec1f79
  1. BIN
      .vs/comivoyar/v15/.suo
  2. 45
      comivoyar/Program.cs
  3. BIN
      comivoyar/bin/Debug/comivoyar.exe
  4. BIN
      comivoyar/bin/Debug/comivoyar.pdb
  5. BIN
      comivoyar/obj/Debug/comivoyar.exe
  6. BIN
      comivoyar/obj/Debug/comivoyar.pdb

BIN
.vs/comivoyar/v15/.suo

Binary file not shown.

45
comivoyar/Program.cs

@ -57,29 +57,41 @@ namespace komvo
int[] toSwap = new int[Points.Count - 1]; int[] toSwap = new int[Points.Count - 1];
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;
int index = 0; bool first = true;
double opLength = 0, prevResult = 0; double opLength = 0, prevResult = 0;
string opRoute = string.Empty; string opRoute = string.Empty;
Permutations<int> perm = new Permutations<int>(toSwap); Permutations<int> perm = new Permutations<int>(toSwap);
foreach(IList<int> p in perm) foreach(IList<int> p in perm)
{ {
string route = string.Empty; int[] route = new int[Points.Count - 1];
for (int i = 0; i < toSwap.Length; i++) route += p[i].ToString() + ";"; for (int i = 0; i < toSwap.Length; i++) route[i] = p[i];
opLength = CountLength(Matrix, route); prevResult = CountLength(Matrix, route);
//WriteLine(opLength);
if (index != 0) if (first)
{ {
opLength = prevResult;
first = false;
}
if(opLength > prevResult) if(opLength > prevResult)
{ {
opLength = prevResult; opLength = prevResult;
opRoute = route; opRoute = string.Empty;
foreach (int i in route) opRoute += i + ";";
} }
} }
else prevResult = opLength;
index++;
} //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", 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); opLength, opRoute, Fact(Points.Count-1), Points.Count, stopwatch.ElapsedMilliseconds);
@ -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; 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]; if (j == 0) result += mtr[0, route[j] - 1];
else if (j == index.Length - 1) else if (j == route.Length - 1)
{ {
result += mtr[int.Parse(index[j - 1]) - 2, int.Parse(index[j]) - 2]; result += mtr[route[j - 1] - 2, route[j] - 2];
result += mtr[0, int.Parse(index[j]) - 2]; result += mtr[0, route[j] - 2];
} }
else 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; return result;

BIN
comivoyar/bin/Debug/comivoyar.exe

Binary file not shown.

BIN
comivoyar/bin/Debug/comivoyar.pdb

Binary file not shown.

BIN
comivoyar/obj/Debug/comivoyar.exe

Binary file not shown.

BIN
comivoyar/obj/Debug/comivoyar.pdb

Binary file not shown.
Loading…
Cancel
Save