|
|
|
@ -20,31 +20,23 @@ namespace komvo
|
|
|
|
|
{ |
|
|
|
|
string[] str = line.Split(); |
|
|
|
|
Points.Add(new Point { X = int.Parse(str[0]), Y = int.Parse(str[1]) }); |
|
|
|
|
WriteLine(str[0] + " " + str[1]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
WriteLine(); |
|
|
|
|
|
|
|
|
|
int matr = Points.Count; |
|
|
|
|
double[,] Matrix = new double[matr, matr]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (Point p in Points) |
|
|
|
|
{ |
|
|
|
|
WriteLine("{0} {1}", p.X, p.Y); |
|
|
|
|
} |
|
|
|
|
WriteLine(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < Points.Count; i++) |
|
|
|
|
{ |
|
|
|
|
for (int j = i; j < Points.Count - 1; j++) |
|
|
|
|
{ |
|
|
|
|
Matrix[i, j + 1] = Math.Sqrt(Math.Pow(Points[j + 1].X - Points[i].X, 2) + Math.Pow(Points[j + 1].Y - Points[i].Y, 2)); |
|
|
|
|
Write("{0} {1} : {2:N2}\t", Points[i].X, Points[j + 1].X, Matrix[i, j]); |
|
|
|
|
Matrix[i, j + 1] = Matrix[j + 1, i] = |
|
|
|
|
Math.Sqrt(Math.Pow(Points[j + 1].X - Points[i].X, 2) + Math.Pow(Points[j + 1].Y - Points[i].Y, 2)); |
|
|
|
|
} |
|
|
|
|
WriteLine(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < matr; i++) |
|
|
|
|
{ |
|
|
|
|
for (int j = 0; j < matr; j++) Write("{0:00.00} ", Matrix[i, j]); |
|
|
|
@ -54,16 +46,14 @@ namespace komvo
|
|
|
|
|
string formP = string.Empty; |
|
|
|
|
for (int i = 2; i <= Points.Count; i++) formP += i.ToString(); |
|
|
|
|
|
|
|
|
|
WriteLine("{0} {1}", formP, Fact(Points.Count - 1)); |
|
|
|
|
int fct = Fact(Points.Count - 1); |
|
|
|
|
WriteLine("{0} {1}", formP, fct); |
|
|
|
|
WriteLine("\n\n"); |
|
|
|
|
|
|
|
|
|
int[] routes = new int[Fact(Points.Count - 1)]; |
|
|
|
|
double[] leng = new double[Fact(Points.Count - 1)]; |
|
|
|
|
int[] routes = new int[fct]; |
|
|
|
|
double[] leng = new double[fct]; |
|
|
|
|
|
|
|
|
|
int waves = 0; |
|
|
|
|
if (Points.Count == 4) waves = 1; |
|
|
|
|
else if (Points.Count == 5) waves = 4; |
|
|
|
|
else if (Points.Count == 6) waves = 20; |
|
|
|
|
int waves = fct / 6; |
|
|
|
|
|
|
|
|
|
int cn = 1, cn2 = 0; |
|
|
|
|
string inf = formP; |
|
|
|
@ -125,42 +115,9 @@ namespace komvo
|
|
|
|
|
//} |
|
|
|
|
//cn++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//routes[0] = int.Parse(formP); |
|
|
|
|
//routes[1] = int.Parse(Swap(formP, 1, 2)); |
|
|
|
|
//routes[2] = int.Parse(formP = Swap(formP, 0, 1)); |
|
|
|
|
//routes[3] = int.Parse(Swap(formP, 1, 2)); |
|
|
|
|
//routes[4] = int.Parse(formP = Swap(formP, 0, 2)); |
|
|
|
|
//routes[5] = int.Parse(Swap(formP, 1, 2)); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < routes.Length; i++) |
|
|
|
|
{ |
|
|
|
|
double res = 0; |
|
|
|
|
char[] ch = routes[i].ToString().ToCharArray(); |
|
|
|
|
for(int j = 0; j < ch.Length; j++) |
|
|
|
|
{ |
|
|
|
|
if (j == 0) res += Matrix[0, 1]; |
|
|
|
|
else if (j == ch.Length - 1) |
|
|
|
|
{ |
|
|
|
|
res += Matrix[int.Parse(ch[j - 1].ToString()) - 1, int.Parse(ch[j].ToString()) - 1]; |
|
|
|
|
res += Matrix[0, int.Parse(ch[j].ToString()) - 1]; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
res += Matrix[int.Parse(ch[j - 1].ToString()) - 1, int.Parse(ch[j].ToString()) - 1]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
leng[i] = res; |
|
|
|
|
} |
|
|
|
|
CountLen(ref leng, Matrix, routes); |
|
|
|
|
|
|
|
|
|
double optim = leng[0]; |
|
|
|
|
int oIndex = 0; |
|
|
|
@ -181,7 +138,7 @@ namespace komvo
|
|
|
|
|
if (routes[i].Equals(routes[j])) WriteLine("{0} {2}:: {1} {3}!!!!", routes[i], routes[j], i, j); |
|
|
|
|
} |
|
|
|
|
WriteLine("\n\n1{1}1 - оптимальный маршрут длинной {0:00.00}\nВсего маршрутов {2}\n{4} {3}", |
|
|
|
|
optim, routes[oIndex], routes.Length, Fact(Points.Count - 1), Points.Count); |
|
|
|
|
optim, routes[oIndex], routes.Length, fct, Points.Count); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -217,6 +174,29 @@ namespace komvo
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void CountLen (ref double[] result, double[,] mtr, int[] rts) |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i < rts.Length; i++) |
|
|
|
|
{ |
|
|
|
|
double res = 0; |
|
|
|
|
char[] ch = rts[i].ToString().ToCharArray(); |
|
|
|
|
for (int j = 0; j < ch.Length; j++) |
|
|
|
|
{ |
|
|
|
|
if (j == 0) res += mtr[0, int.Parse(ch[j].ToString()) - 1]; |
|
|
|
|
else if (j == ch.Length - 1) |
|
|
|
|
{ |
|
|
|
|
res += mtr[int.Parse(ch[j - 1].ToString()) - 1, int.Parse(ch[j].ToString()) - 1]; |
|
|
|
|
res += mtr[0, int.Parse(ch[j].ToString()) - 1]; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
res += mtr[int.Parse(ch[j - 1].ToString()) - 1, int.Parse(ch[j].ToString()) - 1]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
result[i] = res; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public partial struct Point |
|
|
|
|
{ |
|
|
|
|
public int X { get; set; } |
|
|
|
|