Exemple #1
0
 static private void sortHeap(ref PriorityQueue.Heap <Vertex> heap)
 {
     PriorityQueue.Element <Vertex>[] updatedKeys = new PriorityQueue.Element <Vertex> [heap.NumberOfElements];
     for (int i = 0; i < updatedKeys.Length; i++)
     {
         updatedKeys[i] = updateKey(heap.deleteMax());
     }
     for (int i = 0; i < updatedKeys.Length; i++)
     {
         heap.insertElement(updatedKeys[i]);
     }
 }
Exemple #2
0
        static public Path[,] runAlgorithm(Graph graph_)
        {
            graph = graph_;
            Path[,] widestPaths = new Path[graph.Vertices.Length, graph.Vertices.Length];
            PriorityQueue.Heap <Vertex> verticesHeap = new PriorityQueue.Heap <Vertex>();


            for (int b = 0; b < graph.Vertices.Length; b++)
            {
                Vertex begin = graph.Vertices[b];
                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);
                }

                for (int i = 0; i < graph.Vertices.Length; i++)
                {
                    widestPaths[b, i] = generatePath(begin, graph.Vertices[i]);
                }
            }
            return(widestPaths);
        }