public static IList<int> CalculatePath(Node[][] nodes, int startPoint, int endPoint) { IList<int> paths = GetPath(nodes, startPoint, endPoint, new List<int>()); paths.Insert(0, startPoint); paths.Insert(paths.Count, endPoint); return paths; }
public Node getCopy() { Node newNode = new Node (); newNode.localPosition.Set(localPosition.x, localPosition.y, localPosition.z); newNode.localRotation.Set (localRotation.x, localRotation.y, localRotation.z); newNode.attachedPart = new PartTag (); newNode.attachedPart.set (attachedPart.index, attachedPart.level, attachedPart.parent, attachedPart.node); newNode.equipped = equipped; newNode.typeRestriction = typeRestriction; return newNode; }
public static string GetString(Node[][] shortestPaths) { var sb = new StringBuilder(); for (int i = 0; i < shortestPaths.LongLength; i++) { for (int j = 0; j < shortestPaths.Length; j++) { sb.Append(string.Format(NumberFormat, shortestPaths[i][j].ShortestPath)); } sb.Append(Environment.NewLine); } return sb.ToString(); }
public static double CalculateOverallTimeInTrafic(Node[][] initialMatrix, double[][] passengerFlow) { double sum = 0; for (int i = 0; i < initialMatrix.Length; i++) { for (int j = i + 1; j < initialMatrix[i].Length; j++) { sum += initialMatrix[i][j].ShortestPath*passengerFlow[i][j]; sum += initialMatrix[j][i].ShortestPath*passengerFlow[j][i]; if (sum == double.PositiveInfinity) { LogText("Suma a ajuns la infinit"); return sum; } } } return sum; }
private static void PersistData(ShortestPathsResult shortestPathsResult, double[][] resultedInitialMatrix, Node[][] resultedNodesMatrix, bool saveData) { if (!saveData) { return; } shortestPathsResult.ResultedInitialMatrix = resultedInitialMatrix; shortestPathsResult.ResultedNodesMatrix = resultedNodesMatrix; }
private static IList<IList<int>> BuildAllPossiblePaths(Node[][] nodesMatrix) { IList<IList<int>> pathsList = new List<IList<int>>(); for (int i = 0; i < nodesMatrix.LongLength; i++) { for (int j = 0; j < nodesMatrix.Length; j++) { if (i == j /* || initialMatrix[i][j] < double.PositiveInfinity*/) { continue; } pathsList.Add(FloydAlgorithm.CalculatePath(nodesMatrix, i, j)); } } return pathsList; }
private static double GetPathLength(Node[][] nodes, double waitingTime, int k, int i, int j, IEnumerable<IList<int>> shortestPaths) { if (shortestPaths.Any(path => path.Contains(i) && path.Contains(j) && path.Contains(k))) { return nodes[i][k].ShortestPath + nodes[k][j].ShortestPath; } return nodes[i][k].ShortestPath + waitingTime + nodes[k][j].ShortestPath; }
private static Node[][] InitMatrix(double[][] inputMatrix) { var result = new Node[inputMatrix.Length][]; for (int i = 0; i < inputMatrix.Length; i++) { result[i] = new Node[inputMatrix.Length]; for (int j = 0; j < inputMatrix.Length; j++) { result[i][j] = new Node(i == j ? 0 : inputMatrix[i][j]); } } return result; }
public void TestNodeCreation() { const double shortestPath = 5; var node = new Node(shortestPath); const int next = 2; node.Next = next; Assert.That(node.ShortestPath, Is.EqualTo(shortestPath)); Assert.That(node.Next, Is.EqualTo(next)); }