public void SortCyclicPUT_NEW1(AdjacencyGraph g, bool rndConstructor, bool allowParallelEdges, int numberOfVertices, bool toNull)
        {
            g = AdjacencyGraphFactory.CreateAcyclicGraph1(allowParallelEdges, numberOfVertices, toNull);
            TopologicalSortAlgorithm topo;
            List<IVertex> list = null;
            if (g != null && g.VerticesCount > 0)
            {
                list = new List<IVertex>();
                foreach (IVertex v in g.Vertices)
                {
                    IVertex a = g.AddVertex();
                    list.Add(v);
                }
                g = createCycle(g);
            }
            if (rndConstructor)
                topo = new TopologicalSortAlgorithm(g, list);
            else
                topo = new TopologicalSortAlgorithm(g);

            topo.Compute();
            for (int j = 0; j < topo.SortedVertices.Count; ++j)
            {
                PexObserve.ValueForViewing<IVertex>("Sorted Vertex", (IVertex)topo.SortedVertices[j]);
            }
        }
		public void CheckPredecessorLineGraph()
		{
			AdjacencyGraph g = new AdjacencyGraph(true); 
			IVertex v1 = g.AddVertex();
			IVertex v2 = g.AddVertex();
			IVertex v3 = g.AddVertex();

			IEdge e12 = g.AddEdge(v1,v2);
			IEdge e23 = g.AddEdge(v2,v3);

			EdgeDoubleDictionary weights = DijkstraShortestPathAlgorithm.UnaryWeightsFromEdgeList(g);
			DijkstraShortestPathAlgorithm dij = new DijkstraShortestPathAlgorithm(g,weights);
			PredecessorRecorderVisitor vis = new PredecessorRecorderVisitor();
			dij.RegisterPredecessorRecorderHandlers(vis);

			dij.Compute(v1);

			EdgeCollection col = vis.Path(v2);
			Assert.AreEqual(1,col.Count);
			Assert.AreEqual(e12,col[0]);

			col = vis.Path(v3);
			Assert.AreEqual(2,col.Count);
			Assert.AreEqual(e12,col[0]);
			Assert.AreEqual(e23,col[1]);
		}
        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 Sort()
		{
			AdjacencyGraph g = new AdjacencyGraph(true);
			Hashtable iv = new Hashtable();
			
			int i = 0;
			IVertex a = g.AddVertex();
			iv[i++]=a;
			IVertex b = g.AddVertex();
			iv[i++]=b;
			IVertex c = g.AddVertex();
			iv[i++]=c;
			IVertex d = g.AddVertex();
			iv[i++]=d;
			IVertex e = g.AddVertex();
			iv[i++]=e;

			g.AddEdge(a,b);
			g.AddEdge(a,c);
			g.AddEdge(b,c);
			g.AddEdge(c,d);				
			g.AddEdge(a,e);				

			TopologicalSortAlgorithm topo = new TopologicalSortAlgorithm(g);
			topo.Compute();
		}
        public void SortCyclicPUT_NEW(AdjacencyGraph g, IVertex[] listOfVertices, bool rndConstructor)
        {
            TopologicalSortAlgorithm topo;// = new TopologicalSortAlgorithm(g);
            List<IVertex> list = null;
            if (listOfVertices != null && g!= null)
            {
                list = new List<IVertex>();
                foreach (IVertex v in listOfVertices)
                {
                    IVertex a = g.AddVertex();
                    list.Add(v);
                }
                g = createCycle(g);
            }
            if (rndConstructor)
                topo = new TopologicalSortAlgorithm(g, list);
            else
                topo = new TopologicalSortAlgorithm(g);

            topo.Compute();
            for (int j = 0; j < topo.SortedVertices.Count; ++j)
            {
                PexObserve.ValueForViewing<IVertex>("Sorted Vertex", (IVertex)topo.SortedVertices[j]);
            }
        }
        //   [PexFactoryMethod(typeof(AdjacencyGraph))]
        public static AdjacencyGraph CreateAcyclicGraph1(bool allowParallelEdges_b, int numberOfVertices, bool toNull)
        {
            AdjacencyGraph adjacencyGraph;
            if (toNull)
            {
                adjacencyGraph = new AdjacencyGraph(null, allowParallelEdges_b);
                return null;
            }

            PexAssume.IsTrue(numberOfVertices < 10);

            adjacencyGraph = new AdjacencyGraph(new VertexAndEdgeProvider(), allowParallelEdges_b);

               /* IVertex u = adjacencyGraph.AddVertex();
            IVertex v = adjacencyGraph.AddVertex();
            IVertex w = adjacencyGraph.AddVertex();
            adjacencyGraph.AddEdge(u, v);
            adjacencyGraph.AddEdge(v, w);
            adjacencyGraph.AddEdge(w, u);*/

            //Adding remaining number of vertices
            for (int count = 0; count < numberOfVertices; count++)
            {
                adjacencyGraph.AddVertex();
            }

            return adjacencyGraph;
        }
        public static AdjacencyGraph CreateAcyclicGraph(
            VertexAndEdgeProvider provider_iVertexAndEdgeProvider,
            bool allowParallelEdges_b,
            int numberOfVertices
            )
        {
            PexAssume.IsTrue(numberOfVertices < 50);

            AdjacencyGraph adjacencyGraph
               = new AdjacencyGraph(provider_iVertexAndEdgeProvider, allowParallelEdges_b);

            IVertex u = adjacencyGraph.AddVertex();
            IVertex v = adjacencyGraph.AddVertex();
            IVertex w = adjacencyGraph.AddVertex();
            adjacencyGraph.AddEdge(u, v);
            adjacencyGraph.AddEdge(v, w);
            adjacencyGraph.AddEdge(u, w);

            //Adding remaining number of vertices
            for (int count = 3; count < numberOfVertices; count++)
            {
                adjacencyGraph.AddVertex();
            }

            return adjacencyGraph;
        }
        public void Sort()
        {
            AdjacencyGraph g = new AdjacencyGraph(new VertexAndEdgeProvider(), true);
            Hashtable iv = new Hashtable();

            int i = 0;
            IVertex a = g.AddVertex();
            iv[i++]=a;
            IVertex b = g.AddVertex();
            iv[i++]=b;
            IVertex c = g.AddVertex();
            iv[i++]=c;
            IVertex d = g.AddVertex();
            iv[i++]=d;
            IVertex e = g.AddVertex();
            iv[i++]=e;

            g.AddEdge(a,b);
            g.AddEdge(a,c);
            g.AddEdge(b,c);
            g.AddEdge(c,d);
            g.AddEdge(a,e);

            TopologicalSortAlgorithm topo = new TopologicalSortAlgorithm(g);
            topo.Compute();

            for(int j=0;j<topo.SortedVertices.Count;++j)
            {
                Assert.AreEqual( (IVertex)iv[j], topo.SortedVertices[j]);
            }
        }
Example #9
0
        public void Test()
        {
            // create a new adjacency graph
            AdjacencyGraph g = new AdjacencyGraph(new VertexAndEdgeProvider(), false);

            // adding files and storing names
            IVertex zig_cpp = g.AddVertex();	Names[zig_cpp]="zip.cpp";
            IVertex boz_h = g.AddVertex();		Names[boz_h]="boz.h";
            IVertex zag_cpp = g.AddVertex();	Names[zag_cpp]="zag.cpp";
            IVertex yow_h = g.AddVertex();		Names[yow_h]="yow.h";
            IVertex dax_h = g.AddVertex();		Names[dax_h]="dax.h";
            IVertex bar_cpp = g.AddVertex();	Names[bar_cpp]="bar.cpp";
            IVertex zow_h = g.AddVertex();		Names[zow_h]="zow.h";
            IVertex foo_cpp = g.AddVertex();	Names[foo_cpp]="foo.cpp";

            IVertex zig_o = g.AddVertex();		Names[zig_o]="zig.o";
            IVertex zag_o = g.AddVertex();		Names[zag_o]="zago";
            IVertex bar_o = g.AddVertex();		Names[bar_o]="bar.o";
            IVertex foo_o = g.AddVertex();		Names[foo_o]="foo.o";
            IVertex libzigzag_a = g.AddVertex();Names[libzigzag_a]="libzigzig.a";
            IVertex libfoobar_a = g.AddVertex();Names[libfoobar_a]="libfoobar.a";

            IVertex killerapp = g.AddVertex();	Names[killerapp]="killerapp";

            // adding dependencies
            g.AddEdge(dax_h, foo_cpp);
            g.AddEdge(dax_h, bar_cpp);
            g.AddEdge(dax_h, yow_h);
            g.AddEdge(yow_h, bar_cpp);
            g.AddEdge(yow_h, zag_cpp);
            g.AddEdge(boz_h, bar_cpp);
            g.AddEdge(boz_h, zig_cpp);
            g.AddEdge(boz_h, zag_cpp);
            g.AddEdge(zow_h, foo_cpp);
            g.AddEdge(foo_cpp, foo_o);
            g.AddEdge(foo_o, libfoobar_a);
            g.AddEdge(bar_cpp, bar_o);
            g.AddEdge(bar_o, libfoobar_a);
            g.AddEdge(libfoobar_a, libzigzag_a);
            g.AddEdge(zig_cpp, zig_o);
            g.AddEdge(zig_o, libzigzag_a);
            g.AddEdge(zag_cpp, zag_o);
            g.AddEdge(zag_o, libzigzag_a);
            g.AddEdge(libzigzag_a, killerapp);

            // outputing graph to png
            GraphvizAlgorithm gw = new GraphvizAlgorithm(
                g,                      // graph to draw
                "filedependency",         // output file prefix
                ".",                    // output file path
                GraphvizImageType.Png   // output file type
                );
            // outputing to graph.
            gw.Write();

            // attaching the file name outputer...
            gw.WriteVertex += new VertexHandler(this.WriteVertex);
            gw.Write();
        }
 public FixtureDependencyGraph()
 {
     this.graph = new AdjacencyGraph(
         new FixtureVertex.Provider(),
         new EdgeProvider(),
         false
         );
 }
        public void IsolatedVertex()
        {
            AdjacencyGraph g = new AdjacencyGraph();
            g.AddVertex();

            target = new CyclePoppingRandomTreeAlgorithm(g);
            target.RandomTree();
        }
 public TestDomainDependencyGraph()
 {
     graph = new AdjacencyGraph(
         new TestDomainVertex.Provider(),
         new EdgeProvider(),
         false
         );
 }
		public void AttachDistanceRecorderVisitor()
		{
			AdjacencyGraph g = new AdjacencyGraph(true); 
			EdgeDoubleDictionary weights = DijkstraShortestPathAlgorithm.UnaryWeightsFromEdgeList(g);
			DijkstraShortestPathAlgorithm dij = new DijkstraShortestPathAlgorithm(g,weights);
			DistanceRecorderVisitor vis = new DistanceRecorderVisitor();
			dij.RegisterDistanceRecorderHandlers(vis);
		}
		public void OneVertex()
		{
			AdjacencyGraph g =new AdjacencyGraph(true);
			IVertex v1 = g.AddVertex();
			StrongComponentsAlgorithm strong = new StrongComponentsAlgorithm(g);
			Assert.AreEqual(1, strong.Compute());

			checkStrong(strong);
		}
 /// <summary>
 /// Constructs a <see cref="ClusteredAdjacencyGraph"/> on top of
 /// the <see cref="AdjacencyGraph"/> object.
 /// </summary>
 /// <param name="wrapped">parent graph</param>
 public ClusteredAdjacencyGraph(AdjacencyGraph wrapped)
 {
     if(wrapped==null)
         throw new ArgumentNullException("parent");
     this.parent = null;
     this.wrapped = wrapped;
     this.clusters = new ArrayList();
     this.colapsed=false;
 }
 public ClusteredAdjacencyGraph(ClusteredAdjacencyGraph parent)
 {
     if (parent == null)
     {
         throw new ArgumentNullException("parent");
     }
     this.parent = parent;
     this.wrapped = new AdjacencyGraph(this.Parent.VertexProvider, this.Parent.EdgeProvider, this.Parent.AllowParallelEdges);
     this.clusters = new ArrayList();
 }
        public void RootIsNotAccessible()
        {
            AdjacencyGraph g = new AdjacencyGraph();
            IVertex root = g.AddVertex();
            IVertex v = g.AddVertex();
            g.AddEdge(root, v);

            target = new CyclePoppingRandomTreeAlgorithm(g);
            target.RandomTreeWithRoot(root);
        }
		public void Init()
		{
			this.capacities = new EdgeDoubleDictionary();
			this.reversedEdges = new EdgeEdgeDictionary();
			this.graph = new AdjacencyGraph();

			this.source = graph.AddVertex();
			this.sink = graph.AddVertex();

			BuildSimpleGraph(source, sink);
		}
 /// <summary>
 /// Star canal
 /// </summary>
 /// <param name="n"></param>
 /// <returns></returns>
 public static AdjacencyGraph CreateStar(int n)
 {
     AdjacencyGraph g = new AdjacencyGraph();
     IVertex root = g.AddVertex();
     for(int i = 0;i<n;++i)
     {
         IVertex v = g.AddVertex();
         g.AddEdge(root, v);
     }
     return g;
 }
 /// <summary>
 /// Reversed star canal
 /// </summary>
 /// <param name="n"></param>
 /// <returns></returns>
 public static AdjacencyGraph CreateReversedStart(int n)
 {
     AdjacencyGraph g = new AdjacencyGraph();
     IVertex root = g.AddVertex();
     for(int i = 0;i<n;++i)
     {
         IVertex v = g.AddVertex();
         g.AddEdge(v,root);
     }
     return g;
 }
		public void TwoVertexOnEdge()
		{
			AdjacencyGraph g =new AdjacencyGraph(true);
			IVertex v1 = g.AddVertex();
			IVertex v2 = g.AddVertex();
			IEdge e = g.AddEdge(v1,v2);
			StrongComponentsAlgorithm strong = new StrongComponentsAlgorithm(g);
			Assert.AreEqual(2, strong.Compute());

			checkStrong(strong);
		}
Example #22
0
		public RunTree(TestFixturePatternAttribute fixturePattern) 
		{
			if (fixturePattern==null)
				throw new ArgumentNullException("fixturePattern");
			
			this.fixturePattern = fixturePattern;
			this.graph = new AdjacencyGraph(
				new RunVertex.Provider(),
				new EdgeProvider(),
				false);
			
			this.root = (RunVertex)this.graph.AddVertex();		
		}
        public static AdjacencyGraph FileDependency()
        {
            // create a new adjacency graph
            AdjacencyGraph g = new AdjacencyGraph(
                new NamedVertexProvider(),
                new NamedEdgeProvider(),
                true
                );

            // adding files and storing names
            NamedVertex zig_cpp = (NamedVertex)g.AddVertex();	zig_cpp.Name="zip.cpp";
            NamedVertex boz_h = (NamedVertex)g.AddVertex();		boz_h.Name="boz.h";
            NamedVertex zag_cpp = (NamedVertex)g.AddVertex();	zag_cpp.Name="zag.cpp";
            NamedVertex yow_h = (NamedVertex)g.AddVertex();		yow_h.Name="yow.h";
            NamedVertex dax_h = (NamedVertex)g.AddVertex();		dax_h.Name="dax.h";
            NamedVertex bar_cpp = (NamedVertex)g.AddVertex();	bar_cpp.Name="bar.cpp";
            NamedVertex zow_h = (NamedVertex)g.AddVertex();		zow_h.Name="zow.h";
            NamedVertex foo_cpp = (NamedVertex)g.AddVertex();	foo_cpp.Name="foo.cpp";

            NamedVertex zig_o = (NamedVertex)g.AddVertex();		zig_o.Name="zi.o";
            NamedVertex zag_o = (NamedVertex)g.AddVertex();		zag_o.Name="zag.o";
            NamedVertex bar_o = (NamedVertex)g.AddVertex();		bar_o.Name="bar.o";
            NamedVertex foo_o = (NamedVertex)g.AddVertex();		foo_o.Name="foo.o";
            NamedVertex libzigzag_a = (NamedVertex)g.AddVertex(); libzigzag_a.Name="libzigzag.a";
            NamedVertex libfoobar_a = (NamedVertex)g.AddVertex(); libfoobar_a.Name="libfoobar.a";

            NamedVertex killerapp = (NamedVertex)g.AddVertex();	killerapp.Name="killerapp";

            // adding dependencies
            g.AddEdge(dax_h, foo_cpp);
            g.AddEdge(dax_h, bar_cpp);
            g.AddEdge(dax_h, yow_h);
            g.AddEdge(yow_h, bar_cpp);
            g.AddEdge(yow_h, zag_cpp);
            g.AddEdge(boz_h, bar_cpp);
            g.AddEdge(boz_h, zig_cpp);
            g.AddEdge(boz_h, zag_cpp);
            g.AddEdge(zow_h, foo_cpp);
            g.AddEdge(foo_cpp, foo_o);
            g.AddEdge(foo_o, libfoobar_a);
            g.AddEdge(bar_cpp, bar_o);
            g.AddEdge(bar_o, libfoobar_a);
            g.AddEdge(libfoobar_a, libzigzag_a);
            g.AddEdge(zig_cpp, zig_o);
            g.AddEdge(zig_o, libzigzag_a);
            g.AddEdge(zag_cpp, zag_o);
            g.AddEdge(zag_o, libzigzag_a);
            g.AddEdge(libzigzag_a, killerapp);

            return g;
        }
 public AdjacencyGraph createCycle(AdjacencyGraph g)
 {
     foreach (IVertex v1 in g.Vertices)
     {
         foreach (IVertex v2 in g.Vertices)
         {
             if (v1 != v2 && g.ContainsEdge(v1, v2))
             {
                 g.AddEdge(v1, v2);
             }
         }
     }
     return g;
 }
        /// <summary>
        /// Cascade graph
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public static AdjacencyGraph CreateCascade(int n)
        {
            IVertex previous, next;

            AdjacencyGraph g = new AdjacencyGraph();
            next = g.AddVertex();
            for(int i = 0;i<n;++i)
            {
                previous = next;
                next = g.AddVertex();
                g.AddEdge(previous,next);
            }
            return g;
        }
        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 RunInvokerTree(Fixture fixture)
        {
            if (fixture==null)
                throw new ArgumentNullException("fixture");
            this.fixture = fixture;

            this.graph = new AdjacencyGraph(
                new RunInvokerVertexProvider(),
                new EdgeProvider(),
                false
                );

            CreateRoot();
            Reflect();
        }
        public XmlSerializationTest()
        {
            m_Graph = new AdjacencyGraph(
                new NamedVertexProvider(),
                new NamedEdgeProvider(),
                true
                );

            u = (NamedVertex)Graph.AddVertex(); u.Name = "u";
            v = (NamedVertex)Graph.AddVertex(); v.Name = "v";
            w = (NamedVertex)Graph.AddVertex(); w.Name = "w";

            uv = (NamedEdge)Graph.AddEdge(u,v); uv.Name = "uv";
            uw = (NamedEdge)Graph.AddEdge(u,w); uw.Name = "uw";
        }
		public void RunOnLineGraph()
		{
			AdjacencyGraph g = new AdjacencyGraph(true); 
			IVertex v1 = g.AddVertex();
			IVertex v2 = g.AddVertex();
			IVertex v3 = g.AddVertex();

			IEdge e12 = g.AddEdge(v1,v2);
			IEdge e23 = g.AddEdge(v2,v3);

			EdgeDoubleDictionary weights = DijkstraShortestPathAlgorithm.UnaryWeightsFromEdgeList(g);
			DijkstraShortestPathAlgorithm dij = new DijkstraShortestPathAlgorithm(g,weights);
			dij.Compute(v1);

			Assert.AreEqual(0, dij.Distances[v1]);
			Assert.AreEqual(1, dij.Distances[v2]);
			Assert.AreEqual(2, dij.Distances[v3]);
		}
        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));
        }