//public void ExecTwice() //{ // TargetMatrix = GetTargetMatrix(Matrix); // List<int> shouldPassPoints = GetShouldPassPoints(); // foreach (int k in shouldPassPoints) // { // foreach (int i in shouldPassPoints) // { // if (k == i) { continue; } // foreach (int j in shouldPassPoints) // { // if (j == i) { continue; } // bool next = false; // foreach (Path p in TargetMatrix[i, j].Paths) // { // if (p.ContainPoint(k)) { next = true; } // } // if (next) { continue; } // for (int p1 = 0; p1 < TargetMatrix[i, k].Paths.Count; p1++) // { // for (int p2 = 0; p2 < TargetMatrix[k, j].Paths.Count; p2++) // { // //k点不为起点或终点 // if (i == k || j == k) { continue; } // //起点终点是一个点 // if (i == j) { continue; } // Path newPath = new Path(TargetMatrix[i, k].Paths[p1], TargetMatrix[k, j].Paths[p2]); // bool shouldAdd = true; // #region 条件判断 // //for (int p = Matrix[i, j].Paths.Count; p > 0; p--) // //{ // // var eachPath = Matrix[i, j].Paths[p - 1]; // // if (newPath.Distance >= eachPath.Distance && newPath.Step >= eachPath.Step) { shouldAdd = false; } // // //是否保留相同权值和步数的路径,保留会影响搜索速度,但能找到多个最优解(如果存在). // // if (newPath.EqualsInValue(eachPath) && RetainSameValuePaths) { shouldAdd = true; } // // //借此循环删除List中无用路径 // // if (eachPath.IsUseless(newPath)) { Matrix[i, j].Paths.Remove(eachPath); } // // //保存最小Distance路径 // // if (newPath.LessValueOfDistance(Matrix[i, j].MinDistancePath)) { Matrix[i, j].MinDistancePath = newPath; } // // //保存最小Step路径 // // if (newPath.LessValueOfStep(Matrix[i, j].MinStepPath)) { Matrix[i, j].MinStepPath = newPath; } // //} // #endregion // if (shouldAdd) { TargetMatrix[i, j].Paths.Add(newPath); } // } // } // } // } // } // for (int k = 0; k < TableSize; k++) // { // for (int i = 0; i < TableSize; i++) // { // for (int j = 0; j < TableSize; j++) // { // if (TargetMatrix[i, j] == null || TargetMatrix[i, k] == null || TargetMatrix[k, j] == null) { continue; } // //对i->k k->j中全部路径做比较 // for (int p1 = 0; p1 < TargetMatrix[i, k].Paths.Count; p1++) // { // for (int p2 = 0; p2 < TargetMatrix[k, j].Paths.Count; p2++) // { // //k点不为起点或终点 // if (i == k || j == k) { continue; } // //起点终点是一个点 // if (i == j) { continue; } // Path newPath = new Path(TargetMatrix[i, k].Paths[p1], TargetMatrix[k, j].Paths[p2]); // bool shouldAdd = true; // #region 条件判断 // #endregion // if (shouldAdd) { TargetMatrix[i, j].Paths.Add(newPath); } // } // } // } // } // } //} public void ExecSearchAllTargetPaths(int s, int e) { TargetPathsContainer = new PathsContainer(s, e); TargetPathsContainer.Paths.Clear(); //List<int> ShouldPassPoints = GetShouldPassPoints(); //if (ShouldPassPoints.Count == 0) //{ // TargetPathsContainer.Paths.AddRange(Matrix[s, e].Paths); // return; //} //ShouldPassPoints.Remove(e); //ShouldPassPoints.Remove(s); List <int> mustPassPoints = new List <int>(MustPassPoints); List <Path> mustPassPaths = new List <Path>(MustPassEitherWayPaths); DfsAllMustPassPaths(s, e, mustPassPoints, mustPassPaths); }
private void InitMatrix(int size) { Matrix = new PathsContainer[size, size]; OriginalMatrix = new PathsContainer[size, size]; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { if (i == j) { Matrix[i, j] = new PathsContainer(i, j); OriginalMatrix[i, j] = new PathsContainer(i, j); //Matrix[i, j].Paths.Add(new Path(i, j, 0)); //OriginalMatrix[i, j].Paths.Add(new Path(i, j, 0)); } else { Matrix[i, j] = new PathsContainer(i, j); OriginalMatrix[i, j] = new PathsContainer(i, j); } } } }
public PathsContainer(PathsContainer pc) { FromPoint = pc.FromPoint; ToPoint = pc.ToPoint; Paths = new List <Path>(pc.Paths); }