コード例 #1
0
ファイル: FloydAlgorithm.cs プロジェクト: dplacinta/Geronimus
        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;
        }
コード例 #2
0
ファイル: Node.cs プロジェクト: TwoClunkers/Clunk-Genesis
        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;
        }
コード例 #3
0
ファイル: MatrixLoader.cs プロジェクト: dplacinta/Geronimus
        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();
        }
コード例 #4
0
ファイル: Geronimus.cs プロジェクト: dplacinta/Geronimus
        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;
        }
コード例 #5
0
ファイル: Geronimus.cs プロジェクト: dplacinta/Geronimus
 private static void PersistData(ShortestPathsResult shortestPathsResult, double[][] resultedInitialMatrix,
     Node[][] resultedNodesMatrix, bool saveData)
 {
     if (!saveData)
     {
         return;
     }
     shortestPathsResult.ResultedInitialMatrix = resultedInitialMatrix;
     shortestPathsResult.ResultedNodesMatrix = resultedNodesMatrix;
 }
コード例 #6
0
ファイル: Geronimus.cs プロジェクト: dplacinta/Geronimus
 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;
 }
コード例 #7
0
ファイル: FloydAlgorithm.cs プロジェクト: dplacinta/Geronimus
        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;
        }
コード例 #8
0
ファイル: FloydAlgorithm.cs プロジェクト: dplacinta/Geronimus
        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;
        }
コード例 #9
0
ファイル: FloydTest.cs プロジェクト: dplacinta/Geronimus
 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));
 }