public PushRelabelMaximumFlowAlgorithm(IIndexedVertexListGraph g, EdgeDoubleDictionary capacities, EdgeEdgeDictionary reversedEdges)
     : base(g, capacities, reversedEdges)
 {
     this.visitedGraph = g;
     this.excessFlow = new VertexDoubleDictionary();
     this.current = new VertexIntDictionary();
     this.distances = new VertexIntDictionary();
 }
コード例 #2
0
 /// <summary>
 /// Builds a priorithzied vertex buffer and fills a vertex distance map.
 /// </summary>
 /// <param name="distances">vertex distance map</param>
 public PriorithizedVertexBuffer(VertexDoubleDictionary distances)
     : base()
 {
     if ( distances == null)
         throw new ArgumentNullException("Distance map is null");
     m_Distances = distances;
     m_Comparer = new DistanceComparer(m_Distances);
 }
コード例 #3
0
 /// <summary>
 /// Builds a priorithzied vertex buffer and fills a vertex distance map.
 /// </summary>
 /// <param name="distances">vertex distance map</param>
 public PriorithizedVertexBuffer(VertexDoubleDictionary distances)
     : base()
 {
     if (distances == null)
     {
         throw new ArgumentNullException("Distance map is null");
     }
     this.distances = distances;
     this.comparer  = new DistanceComparer(this.distances);
 }
コード例 #4
0
		/// <summary>
		/// Builds a new Bellman Ford 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 BellmanFordShortestPathAlgorithm(
			IVertexAndEdgeListGraph g, 
			EdgeDoubleDictionary weights
			)
		{
			if (weights == null)
				throw new ArgumentNullException("Weights");

			m_VisitedGraph = g;
			m_Colors = new VertexColorDictionary();
			m_Weights = weights;
			m_Distances = new VertexDoubleDictionary();
			m_Predecessors = new VertexVertexDictionary();
		}
コード例 #5
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");

			this.visitedGraph = g;
			this.colors = new VertexColorDictionary();
			this.distances = new VertexDoubleDictionary();
			this.weights = weights;
			this.vertexQueue = null;
		}
コード例 #6
0
 public DagShortestPathAlgorithm(IVertexListGraph g, EdgeDoubleDictionary weights)
 {
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     if (weights == null)
     {
         throw new ArgumentNullException("Weights");
     }
     this.m_VisitedGraph = g;
     this.m_Colors = new VertexColorDictionary();
     this.m_Distances = new VertexDoubleDictionary();
     this.m_Predecessors = new VertexVertexDictionary();
     this.m_Weights = weights;
 }
コード例 #7
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;
        }
コード例 #8
0
        private bool IsFlow(MaximumFlowAlgorithm maxFlow)
        {
            // check edge flow values
            foreach (IVertex u in maxFlow.VisitedGraph.Vertices)
            {
                foreach (IEdge a in maxFlow.VisitedGraph.OutEdges(u))
                {
                    if (maxFlow.Capacities[a] > 0)
                        if ((maxFlow.ResidualCapacities[a] + maxFlow.ResidualCapacities[maxFlow.ReversedEdges[a]]
                            != maxFlow.Capacities[a])
                            || (maxFlow.ResidualCapacities[a] < 0)
                            || (maxFlow.ResidualCapacities[maxFlow.ReversedEdges[a]] < 0))
                            return false;
                }
            }

            // check conservation
            VertexDoubleDictionary inFlows = new VertexDoubleDictionary();
            VertexDoubleDictionary outFlows = new VertexDoubleDictionary();
            foreach (IVertex u in maxFlow.VisitedGraph.Vertices)
            {
                inFlows[u] = 0;
                outFlows[u] = 0;
            }

            foreach (IVertex u in maxFlow.VisitedGraph.Vertices)
            {
                foreach (IEdge e in maxFlow.VisitedGraph.OutEdges(u))
                {
                    if (maxFlow.Capacities[e] > 0)
                    {
                        double flow = maxFlow.Capacities[e] - maxFlow.ResidualCapacities[e];

                        inFlows[e.Target] += flow;
                        outFlows[e.Source] += flow;
                    }
                }
            }

            foreach (IVertex u in maxFlow.VisitedGraph.Vertices)
            {
                if (u != source && u != sink)
                    if (inFlows[u] != outFlows[u])
                        return false;
            }

            return true;
        }
コード例 #9
0
ファイル: DistanceComparer.cs プロジェクト: timonela/mb-unit
		/// <summary>
		/// Builds a vertex distance comparer
		/// </summary>
		/// <param name="distances"></param>
		public DistanceComparer(VertexDoubleDictionary distances)
		{
			m_Distances = distances;
		}
 protected void Initialize()
 {
     this.costs = new VertexDoubleDictionary();
     this.priorityQueue = new PriorithizedVertexBuffer(this.costs);
     this.unvisitedSuccessorCounts = new VertexIntDictionary();
     this.states.Clear();
     VertexCollection.Enumerator enumerator = this.goals.GetEnumerator();
     while (enumerator.MoveNext())
     {
         IVertex vertex = enumerator.get_Current();
         this.costs.Add(vertex, 0.0);
         this.priorityQueue.Push(vertex);
     }
     IVertexEnumerator enumerator2 = this.NotGoals.GetEnumerator();
     while (enumerator2.MoveNext())
     {
         IVertex vertex2 = enumerator2.get_Current();
         this.costs.Add(vertex2, double.PositiveInfinity);
     }
     IVertexEnumerator enumerator3 = this.TestGraph.ChoicePoints.GetEnumerator();
     while (enumerator3.MoveNext())
     {
         IVertex vertex3 = enumerator3.get_Current();
         this.unvisitedSuccessorCounts.Add(vertex3, this.testGraph.Graph.OutDegree(vertex3));
     }
     IVertexEnumerator enumerator4 = this.TestGraph.Graph.get_Vertices().GetEnumerator();
     while (enumerator4.MoveNext())
     {
         IVertex vertex4 = enumerator4.get_Current();
         this.states.Add(vertex4, null);
     }
 }
コード例 #11
0
ファイル: DistanceComparer.cs プロジェクト: tmauldin/mb-unit
 /// <summary>
 /// Builds a vertex distance comparer
 /// </summary>
 /// <param name="distances"></param>
 public DistanceComparer(VertexDoubleDictionary distances)
 {
     m_Distances = distances;
 }
コード例 #12
0
 private static void swapRanks(VertexDoubleDictionary left, VertexDoubleDictionary right)
 {
     VertexDoubleDictionary temp = left;
     left = right;
     right = temp;
 }
コード例 #13
0
        /// <summary>
        /// Computes the PageRank over the <see cref="VisitedGraph"/>.
        /// </summary>
        public void Compute()
        {
            VertexDoubleDictionary tempRanks = new VertexDoubleDictionary();
            // create filtered graph
            FilteredBidirectionalGraph fg = new FilteredBidirectionalGraph(
                this.VisitedGraph,
                Preds.KeepAllEdges(),
                new InDictionaryVertexPredicate(this.ranks)
                );

            int iter = 0;
            double error = 0;
            do
            {
                // compute page ranks
                error = 0;
                foreach(DictionaryEntry de in this.Ranks)
                {
                    IVertex v = (IVertex)de.Key;
                    double rank = (double)de.Value;
                    // compute ARi
                    double r = 0;
                    foreach(IEdge e in fg.InEdges(v))
                    {
                        r += this.ranks[e.Source] / fg.OutDegree(e.Source);
                    }

                    // add sourceRank and store
                    double newRank = (1-this.damping) + this.damping * r;
                    tempRanks[v] = newRank;
                    // compute deviation
                    error += Math.Abs(rank - newRank);
                }

                // swap ranks
                VertexDoubleDictionary temp = ranks;
                ranks = tempRanks;
                tempRanks = temp;

                iter++;
            }while( error > this.tolerance && iter < this.maxIterations);
            Console.WriteLine("{0}, {1}",iter,error);
        }
コード例 #14
0
 public void Compute()
 {
     VertexDoubleDictionary dictionary = new VertexDoubleDictionary();
     FilteredBidirectionalGraph graph = new FilteredBidirectionalGraph(this.VisitedGraph, Preds.KeepAllEdges(), new InDictionaryVertexPredicate(this.ranks));
     int num = 0;
     double num2 = 0.0;
     do
     {
         num2 = 0.0;
         IDictionaryEnumerator enumerator = this.Ranks.GetEnumerator();
         while (enumerator.MoveNext())
         {
             DictionaryEntry current = (DictionaryEntry) enumerator.Current;
             IVertex key = (IVertex) current.Key;
             double num3 = (double) current.Value;
             double num4 = 0.0;
             FilteredEdgeEnumerable.Enumerator enumerator2 = graph.InEdges(key).GetEnumerator();
             while (enumerator2.MoveNext())
             {
                 IEdge edge = enumerator2.get_Current();
                 num4 += this.ranks.get_Item(edge.get_Source()) / ((double) graph.OutDegree(edge.get_Source()));
             }
             double num5 = (1.0 - this.damping) + (this.damping * num4);
             dictionary.set_Item(key, num5);
             num2 += Math.Abs((double) (num3 - num5));
         }
         VertexDoubleDictionary ranks = this.ranks;
         this.ranks = dictionary;
         dictionary = ranks;
         num++;
     }
     while ((num2 > this.tolerance) && (num < this.maxIterations));
     Console.WriteLine("{0}, {1}", num, num2);
 }
コード例 #15
0
 private static void swapRanks(VertexDoubleDictionary left, VertexDoubleDictionary right)
 {
     VertexDoubleDictionary dictionary = left;
     left = right;
     right = dictionary;
 }