public void AddAndRemoveOnFsm()
 {
     this.target = new ReversedEdgeAugmentorAlgorithm(GraphFactory.Fsm());
     this.target.AddReversedEdges();
     this.VerifyReversedEdges();
     this.target.RemoveReversedEdges();
 }
        public MaximumFlowDemo()
        {
            graph = new AdjacencyGraph(
                new NamedVertexProvider(),
                new EdgeProvider(),
                true);

            s = (NamedVertex)graph.AddVertex(); s.Name = "s";
            x = (NamedVertex)graph.AddVertex(); x.Name = "x";
            v = (NamedVertex)graph.AddVertex(); v.Name = "v";
            w = (NamedVertex)graph.AddVertex(); w.Name = "w";
            t = (NamedVertex)graph.AddVertex(); t.Name = "t";

            sx = graph.AddEdge(s, x); capacities[sx] = 5;
            sv = graph.AddEdge(s, v); capacities[sv] = 7;
            xv = graph.AddEdge(x, v); capacities[xv] = 3;
            xw = graph.AddEdge(x, w); capacities[xw] = 7;
            wv = graph.AddEdge(w, v); capacities[wv] = 5;
            wt = graph.AddEdge(w, t); capacities[wt] = 4;
            vt = graph.AddEdge(v, t); capacities[vt] = 6;

            this.graphviz = new GraphvizAlgorithm(this.graph);
            this.graphviz.ImageType = NGraphviz.Helpers.GraphvizImageType.Svg;
            this.graphviz.GraphFormat.RankDirection = NGraphviz.Helpers.GraphvizRankDirection.LR;
            this.graphviz.FormatVertex+=new FormatVertexEventHandler(graphviz_FormatVertex);
            this.graphviz.FormatEdge+=new FormatEdgeEventHandler(graphviz_FormatEdge);

            this.reversedEdgeAugmentor = new ReversedEdgeAugmentorAlgorithm(this.graph);
            this.reversedEdgeAugmentor.ReversedEdgeAdded += new EdgeEventHandler(reversedEdgeAugmentor_ReversedEdgeAdded);
        }
 public void AddAndRemoveOnEmptyGraph()
 {
     this.target = new ReversedEdgeAugmentorAlgorithm(new AdjacencyGraph());
     target.AddReversedEdges();
     Assert.AreEqual(0, this.target.VisitedGraph.VerticesCount);
     Assert.AreEqual(0, this.target.VisitedGraph.EdgesCount);
 }
 public void AddAndRemoveAndCheckAugmented()
 {
     this.target = new ReversedEdgeAugmentorAlgorithm(new AdjacencyGraph());
     Assert.IsFalse(target.Augmented);
     target.AddReversedEdges();
     Assert.IsTrue(target.Augmented);
     target.RemoveReversedEdges();
     Assert.IsFalse(target.Augmented);
 }
Esempio n. 5
0
 private void Initialize()
 {
     this.reverser = new ReversedEdgeAugmentorAlgorithm(this.VisitedGraph);
     this.reverser.ReversedEdgeAdded += new EdgeEventHandler(reverser_ReversedEdgeAdded);
     this.maxFlowF1 = new PushRelabelMaximumFlowAlgorithm(
         this.VisitedGraph,
         this.capacities,
         this.reverser.ReversedEdges);
 }
        public void AddAndRemoveOneEdge()
        {
            AdjacencyGraph g = new AdjacencyGraph();
            IVertex v = g.AddVertex();
            IVertex u = g.AddVertex();
            IEdge edge = g.AddEdge(u, v);

            this.target = new ReversedEdgeAugmentorAlgorithm(g);
            target.AddReversedEdges();
            target.RemoveReversedEdges();
            Assert.AreEqual(2, this.target.VisitedGraph.VerticesCount);
            Assert.AreEqual(1, this.target.VisitedGraph.EdgesCount);
            CollectionAssert.AreCountEqual(0, this.target.AugmentedEdges);
            Assert.AreEqual(0, this.target.ReversedEdges.Count);
        }
 public MinimumFlowAlgorithm(BidirectionalGraph visitedGraph, EdgeDoubleDictionary capacities)
 {
     this.reverser = null;
     this.balancer = null;
     this.maxFlowF1 = null;
     this.maxFlowf2 = null;
     if (visitedGraph == null)
     {
         throw new ArgumentNullException("visitedGraph");
     }
     if (capacities == null)
     {
         throw new ArgumentNullException("capacities");
     }
     this.visitedGraph = visitedGraph;
     this.capacities = capacities;
     this.Initialize();
 }
        public void AddOneEdge()
        {
            AdjacencyGraph g = new AdjacencyGraph();
            IVertex v = g.AddVertex();
            IVertex u = g.AddVertex();
            IEdge edge = g.AddEdge(u, v);

            this.target = new ReversedEdgeAugmentorAlgorithm(g);
            target.AddReversedEdges();

            Assert.AreEqual(2, this.target.VisitedGraph.VerticesCount);
            Assert.AreEqual(2, this.target.VisitedGraph.EdgesCount);
            CollectionAssert.AreCountEqual(1, this.target.AugmentedEdges);
            VerifyReversedEdges();

            IEdge reversedEdge = this.target.ReversedEdges[edge];
            Assert.IsNotNull(reversedEdge);
            Assert.IsTrue(this.target.AugmentedEdges.Contains(reversedEdge));
        }
 public MinimumFlowAlgorithm(BidirectionalGraph visitedGraph)
 {
     this.reverser = null;
     this.balancer = null;
     this.maxFlowF1 = null;
     this.maxFlowf2 = null;
     if (visitedGraph == null)
     {
         throw new ArgumentNullException("visitedGraph");
     }
     if (this.capacities == null)
     {
         throw new ArgumentNullException("capacities");
     }
     this.visitedGraph = visitedGraph;
     this.capacities = new EdgeDoubleDictionary();
     VertexEdgesEnumerator enumerator = this.visitedGraph.Edges.GetEnumerator();
     while (enumerator.MoveNext())
     {
         IEdge edge = enumerator.get_Current();
         this.capacities.Add(edge, double.MaxValue);
     }
     this.Initialize();
 }
 public void ConstructorWithNullGraph()
 {
     this.target = new ReversedEdgeAugmentorAlgorithm(null);
 }