示例#1
0
 public SourceFirstTopologicalSortAlgorithm(
     IVertexAndEdgeListGraph <TVertex, TEdge> visitedGraph
     )
     : base(visitedGraph)
 {
     this.heap = new PriorithizedVertexBuffer <TVertex, int>(this.inDegrees);
 }
 public UndirectedFirstTopologicalSortAlgorithm(
     IUndirectedGraph <TVertex, TEdge> visitedGraph
     )
     : base(visitedGraph)
 {
     this.heap = new PriorithizedVertexBuffer <TVertex, int>(this.degrees);
 }
示例#3
0
        protected void Initialize()
        {
            this.costs                    = new VertexDoubleDictionary();
            this.priorityQueue            = new PriorithizedVertexBuffer(costs);
            this.unvisitedSuccessorCounts = new VertexIntDictionary();
            this.states.Clear();

            foreach (IVertex v in this.goals)
            {
                this.costs.Add(v, 0);
                this.priorityQueue.Push(v);
            }

            foreach (IVertex v in this.NotGoals)
            {
                this.costs.Add(v, double.PositiveInfinity);
            }

            foreach (IVertex v in this.TestGraph.ChoicePoints)
            {
                this.unvisitedSuccessorCounts.Add(v, this.testGraph.Graph.OutDegree(v));
            }

            foreach (IVertex v in this.TestGraph.Graph.Vertices)
            {
                this.states.Add(v, null);
            }
        }
示例#4
0
 public SourceFirstTopologicalSortAlgorithm(
     IVertexAndEdgeListGraph visitedGraph
     )
 {
     this.visitedGraph = visitedGraph;
     this.heap         = new PriorithizedVertexBuffer(this.inDegrees);
 }
示例#5
0
 private void Initialize()
 {
     this.minimumWeights = new Dictionary <TVertex, double>(this.VisitedGraph.VertexCount);
     this.queue          = new PriorithizedVertexBuffer <TVertex, double>(this.minimumWeights);
     foreach (TVertex u in this.VisitedGraph.Vertices)
     {
         this.minimumWeights.Add(u, double.MaxValue);
         this.queue.Add(u);
     }
     this.queue.Sort();
 }
        /// <summary>
        /// Builds a new Dijsktra searcher.
        /// </summary>
        /// <param name="g">The graph</param>
        /// <param name="weights">Edge weights</param>
        /// <exception cref="ArgumentNullException">Any argument is null</exception>
        /// <remarks>This algorithm uses the <seealso cref="BreadthFirstSearchAlgorithm"/>.</remarks>
        public DijkstraShortestPathAlgorithm(
            IVertexListGraph g,
            EdgeDoubleDictionary weights
            )
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }
            if (weights == null)
            {
                throw new ArgumentNullException("Weights");
            }

            this.visitedGraph = g;
            this.colors       = new VertexColorDictionary();
            this.distances    = new VertexDoubleDictionary();
            this.weights      = weights;
            this.vertexQueue  = null;
        }
        public void ComputeNoInit(IVertex s)
        {
            this.vertexQueue = new PriorithizedVertexBuffer(this.distances);
            BreadthFirstSearchAlgorithm bfs = new BreadthFirstSearchAlgorithm(
                VisitedGraph,
                this.vertexQueue,
                Colors
                );

            bfs.InitializeVertex += this.InitializeVertex;
            bfs.DiscoverVertex   += this.DiscoverVertex;
            bfs.ExamineEdge      += this.ExamineEdge;
            bfs.ExamineVertex    += this.ExamineVertex;
            bfs.FinishVertex     += this.FinishVertex;

            bfs.TreeEdge   += new EdgeEventHandler(this.TreeEdge);
            bfs.GrayTarget += new EdgeEventHandler(this.GrayTarget);

            bfs.Visit(s);
        }
示例#8
0
        /// <summary>
        /// Builds a new Dijsktra searcher.
        /// </summary>
        /// <param name="g">The graph</param>
        /// <param name="weights">Edge weights</param>
        /// <exception cref="ArgumentNullException">Any argument is null</exception>
        /// <remarks>This algorithm uses the <seealso cref="BreadthFirstSearchAlgorithm"/>.</remarks>
        public DijkstraShortestPathAlgorithm(
            IVertexListGraph g,
            EdgeDoubleDictionary weights
            )
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }
            if (weights == null)
            {
                throw new ArgumentNullException("Weights");
            }

            m_VisitedGraph = g;
            m_Colors       = new VertexColorDictionary();
            m_Distances    = new VertexDoubleDictionary();
            m_Predecessors = new VertexVertexDictionary();
            m_Weights      = weights;
            m_VertexQueue  = null;
        }
示例#9
0
        public void ComputeNoInit(TVertex s)
        {
            this.vertexQueue = new PriorithizedVertexBuffer <TVertex, double>(this.Distances);
            BreadthFirstSearchAlgorithm <TVertex, TEdge> bfs = new BreadthFirstSearchAlgorithm <TVertex, TEdge>(
                this.VisitedGraph,
                this.vertexQueue,
                VertexColors
                );

            try
            {
                bfs.InitializeVertex += this.InitializeVertex;
                bfs.DiscoverVertex   += this.DiscoverVertex;
                bfs.StartVertex      += this.StartVertex;
                bfs.ExamineEdge      += this.ExamineEdge;
                bfs.ExamineVertex    += this.ExamineVertex;
                bfs.FinishVertex     += this.FinishVertex;

                bfs.TreeEdge   += new EdgeEventHandler <TVertex, TEdge>(this.InternalTreeEdge);
                bfs.GrayTarget += new EdgeEventHandler <TVertex, TEdge>(this.InternalGrayTarget);

                bfs.Visit(s);
            }
            finally
            {
                if (bfs != null)
                {
                    bfs.InitializeVertex -= this.InitializeVertex;
                    bfs.DiscoverVertex   -= this.DiscoverVertex;
                    bfs.StartVertex      -= this.StartVertex;
                    bfs.ExamineEdge      -= this.ExamineEdge;
                    bfs.ExamineVertex    -= this.ExamineVertex;
                    bfs.FinishVertex     -= this.FinishVertex;

                    bfs.TreeEdge   -= new EdgeEventHandler <TVertex, TEdge>(this.InternalTreeEdge);
                    bfs.GrayTarget -= new EdgeEventHandler <TVertex, TEdge>(this.InternalGrayTarget);
                }
            }
        }
示例#10
0
 private void CleanUp()
 {
     this.minimumWeights = null;
     this.queue          = null;
 }