public GraphBalancerAlgorithm(IMutableBidirectionalVertexAndEdgeListGraph visitedGraph, IVertex source, IVertex sink)
 {
     this.source = null;
     this.sink = null;
     this.balancingSource = null;
     this.balancingSourceEdge = null;
     this.balancingSink = null;
     this.balancingSinkEdge = null;
     this.capacities = new EdgeDoubleDictionary();
     this.preFlow = new EdgeIntDictionary();
     this.surplusVertices = new VertexCollection();
     this.surplusEdges = new EdgeCollection();
     this.deficientVertices = new VertexCollection();
     this.deficientEdges = new EdgeCollection();
     this.balanced = false;
     if (visitedGraph == null)
     {
         throw new ArgumentNullException("visitedGraph");
     }
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     if (!visitedGraph.ContainsVertex(source))
     {
         throw new ArgumentException("source is not part of the graph");
     }
     if (sink == null)
     {
         throw new ArgumentNullException("sink");
     }
     if (!visitedGraph.ContainsVertex(sink))
     {
         throw new ArgumentException("sink is not part of the graph");
     }
     this.visitedGraph = visitedGraph;
     this.source = source;
     this.sink = sink;
     IEdgeEnumerator enumerator = this.VisitedGraph.get_Edges().GetEnumerator();
     while (enumerator.MoveNext())
     {
         IEdge edge = enumerator.get_Current();
         this.capacities.Add(edge, double.MaxValue);
     }
     IEdgeEnumerator enumerator2 = this.VisitedGraph.get_Edges().GetEnumerator();
     while (enumerator2.MoveNext())
     {
         IEdge edge2 = enumerator2.get_Current();
         this.preFlow.Add(edge2, 1);
     }
 }
Example #2
0
        private void menuItem8_Click(object sender, System.EventArgs e)
        {
            if (this.netronPanel.Graph==null)
                throw new Exception("Generate a graph first");
            if (this.netronPanel.Populator==null)
                throw new Exception("Populator should not be null.");

            ResetVertexAndEdgeColors();

            // create algorithm
            this.vertexCounts = new VertexIntDictionary();
            this.edgeCounts = new EdgeIntDictionary();
            foreach(IVertex vertex in this.netronPanel.Graph.Vertices)
                this.vertexCounts[vertex]=0;
            foreach(IEdge edge in this.netronPanel.Graph.Edges)
                this.edgeCounts[edge]=0;

            this.edgeWeights =new EdgeDoubleDictionary();
            foreach(IEdge edge in this.netronPanel.Graph.Edges)
                edgeWeights[edge]=1;
            WeightedMarkovEdgeChain chain = new WeightedMarkovEdgeChain(edgeWeights);
            RandomWalkAlgorithm walker = new RandomWalkAlgorithm(
                this.netronPanel.Graph
                );

            walker.TreeEdge+=new EdgeEventHandler(walker_WeightedTreeEdge);

            LayoutAlgorithmTraverVisitor tracer = new LayoutAlgorithmTraverVisitor(this.netronPanel.Populator);
            walker.TreeEdge +=new EdgeEventHandler(tracer.TreeEdge);

            Thread thread = new Thread(new ThreadStart(walker.Generate));
            thread.Start();
        }