Ejemplo n.º 1
0
        static public Path[] runAlgorithm(Graph graph_, Vertex begin, Vertex end)
        {
            graph = graph_;
            Path[] widestPath = new Path[graph.Vertices.Length];
            PriorityQueue.Heap<Vertex> verticesHeap = new PriorityQueue.Heap<Vertex>();

            initialize(begin);
            verticesHeap.initialise(graph.Vertices.Length);
            for (int i = 0; i < graph.Vertices.Length; i++)
            {
                verticesHeap.insertElement(new PriorityQueue.Element<Vertex>(graph.Vertices[i].CumulatedWeight, graph.Vertices[i]));
            }

            while (verticesHeap.NumberOfElements != 0)
            {
                Vertex currentVertex = verticesHeap.deleteMax().Data;
                if (currentVertex.CumulatedWeight == 0)
                    break;
                

                foreach (Edge e in currentVertex.EdgesOut)
                {
                    Vertex neighbor = e.End;


                    double alternate = Math.Max(neighbor.CumulatedWeight, Math.Min(currentVertex.CumulatedWeight, e.Weight));

                    if (alternate > neighbor.CumulatedWeight)
                    {
                        neighbor.CumulatedWeight = alternate;
                        neighbor.Prev = currentVertex;
                    }


                }

             
                sortHeap(ref verticesHeap);
            
            }

           
                widestPath[0] = generatePath(begin, end);
            

            return widestPath;
        }
Ejemplo n.º 2
0
        static private void initialize(string path)
        {
            graph = new Graph();
            using (StreamReader streamReader = new StreamReader(path))
            {
                List<string> textFile = new List<string>();

                while (streamReader.EndOfStream == false)
                {
                    string line = streamReader.ReadLine();

                    if (!line.Contains("#") && line != "")
                    {
                        textFile.Add(line);
                    }
                }
                graph.load(textFile);
            }
        }
Ejemplo n.º 3
0
        static public Path[] runAlgorithm(Graph graph_, Vertex begin, Vertex end)
        {

            graph = graph_;
            Path[] shortestPaths = new Path[graph.Vertices.Length];

            initialize();

            algorithmLogic();

            int len = graph.Vertices.Length;
            
            shortestPaths[0] = generatePath(begin, end);
            return shortestPaths;
        }
Ejemplo n.º 4
0
        //static private void print(double[,] arr)
        //{
        //    var rowCount = arr.GetLength(0);
        //    var colCount = arr.GetLength(1);
        //    for (int row = 0; row < rowCount; row++)
        //    {
        //        for (int col = 0; col < colCount; col++)
        //            Console.Write(String.Format("{0}\t", arr[row, col]));
        //        Console.WriteLine();
        //    }
        //}

        //static private void print(Vertex[,] arr)
        //{
        //    var rowCount = arr.GetLength(0);
        //    var colCount = arr.GetLength(1);
        //    for (int row = 0; row < rowCount; row++)
        //    {
        //        for (int col = 0; col < colCount; col++)
        //            if(arr[row,col] != null)
        //            {
        //                Console.Write(String.Format("{0}\t", arr[row, col].Id));
        //            }else
        //            {
        //                Console.Write(String.Format("{0}\t", "-"));
        //            }
        //        Console.WriteLine();
        //    }
        //}

        static public Path[] runAlgorithm(Graph graph_, Vertex begin)
        {

            graph = graph_;
            Path[] shortestPaths = new Path[graph.Vertices.Length];

            initialize();

            algorithmLogic();

            int len = graph.Vertices.Length;
            for (int i = 0; i < len; i++)
            {
                shortestPaths[i] = generatePath(begin, graph.Vertices[i]);
            }
            return shortestPaths;
        }
Ejemplo n.º 5
0
        static public Path[,] runAlgorithm(Graph graph_)
        {

            graph = graph_;
            Path[,] shortestPaths = new Path[graph.Vertices.Length, graph.Vertices.Length];

            

            initialize();

            algorithmLogic();

            int len = graph.Vertices.Length;
            for (int i = 0; i < len; i++)
                for (int j = 0; j < len; j++)
                {
                    shortestPaths[i,j] = generatePath(graph.Vertices[i], graph.Vertices[j]);
                }
            return shortestPaths;
        }