Example #1
0
        public bool JonhsonFATSPAlgorithm()
        {
            AuxiliaryGraph.AddNode(new Node(AuxiliaryGraph.QuantityOfNodes, "Temporary"));

            for (int Index = 0; Index < AuxiliaryGraph.QuantityOfNodes - 1; Index++)
            {
                AuxiliaryGraph.AddTwoWayEdge(new Edge(0, AuxiliaryGraph.SetOfNodes[AuxiliaryGraph.QuantityOfNodes - 1], AuxiliaryGraph.SetOfNodes[Index]));
            }

            BellmanFordPathSearch = new BellmanFordAlgorithm(AuxiliaryGraph);

            if (BellmanFordPathSearch.BellmanFordShortestPathSearchAlgorithm(AuxiliaryGraph.SetOfNodes[AuxiliaryGraph.QuantityOfNodes - 1]))
            {
                for (int FirstIndex = 0; FirstIndex < InnerGraph.QuantityOfNodes; FirstIndex++)
                {
                    DijkstraPathSearch = new DijkstraAlgorithm(InnerGraph);

                    DijkstraPathSearch.DijkstraSWSAlgorithm(InnerGraph.SetOfNodes[FirstIndex]);

                    for (int SecondIndex = 0; SecondIndex < InnerGraph.QuantityOfNodes; SecondIndex++)
                    {
                        MatrixOfTheShortesPathes[FirstIndex, SecondIndex] = DijkstraPathSearch.ShortestPath[SecondIndex].Weight;
                    }
                }

                return(true);
            }
            else
            {
                for (int Index = 0; Index < InnerGraph.QuantityOfEdges; Index++)
                {
                    InnerGraph.SetOfEdges[Index].Weight =
                        InnerGraph.SetOfEdges[Index].Weight +
                        BellmanFordPathSearch.ShortestPath[InnerGraph.SetOfEdges[Index][0].Index].Weight -
                        BellmanFordPathSearch.ShortestPath[InnerGraph.SetOfEdges[Index][1].Index].Weight;
                }

                for (int FirstIndex = 0; FirstIndex < InnerGraph.QuantityOfNodes; FirstIndex++)
                {
                    DijkstraPathSearch = new DijkstraAlgorithm(InnerGraph);

                    DijkstraPathSearch.DijkstraSWSAlgorithm(InnerGraph.SetOfNodes[FirstIndex]);

                    for (int SecondIndex = 0; SecondIndex < InnerGraph.QuantityOfNodes; SecondIndex++)
                    {
                        MatrixOfTheShortesPathes[FirstIndex, SecondIndex] = DijkstraPathSearch.ShortestPath[SecondIndex].Weight;
                    }
                }
            }

            return(true);
        }
Example #2
0
        static void Main(string[] args)
        {
            // data loading module
            {
                Load.LoadNodes(Graph);
                Load.LoadEdges(Graph);
            }
            Console.WriteLine("Loading finished");
            // algo module
            {
                BFS.BreadthFirstSearch(Graph.SetOfNodes[0]);
            }
            {
                DFS.DepthFirstSearch(Graph.SetOfNodes[0]);
            }
            {
                Kruscal.KruskalSMSTAlgorithm();
            }
            {
                Prima.PrimaSMSTAlgorithm();
            }
            {
                BellmanFord.BellmanFordShortestPathSearchAlgorithm(Graph.SetOfNodes[0]);
            }
            {
                Dijkstra.DijkstraSWSAlgorithm(Graph.SetOfNodes[0]);
            }
            {
                Floyd_Warshall.Floyd_WarshalSATSPAlgorithm();
            }
            {
                Johnson.JonhsonFATSPAlgorithm();
            }
            {
                FordFulkerson.FordFulkersonBFSTypeAlgorithm(Graph.SetOfNodes[0], Graph.SetOfNodes[1]);
            }
            {
                A_Star.A_StarAlgorithm(Graph.SetOfNodes[0], Graph.SetOfNodes[1]);
            }

            Console.ReadKey();
        }