private static AdjacencyGraph <NamedVertex, NamedEdge> Convert(AdjacencyGraph <string, Edge <string> > g)
        {
            AdjacencyGraph <NamedVertex, NamedEdge> cg =
                new AdjacencyGraph <NamedVertex, NamedEdge>();

            System.Collections.Generic.Dictionary <string, NamedVertex> vertices = new System.Collections.Generic.Dictionary <string, NamedVertex>(g.VertexCount);
            foreach (string v in g.Vertices)
            {
                NamedVertex iv = new NamedVertex(v);
                iv.Name = v;
                vertices.Add(v, iv);
                cg.AddVertex(iv);
            }
            int count = 0;

            foreach (Edge <string> e in g.Edges)
            {
                NamedEdge edge = new NamedEdge(
                    count.ToString(),
                    vertices[e.Source],
                    vertices[e.Target]
                    );
                edge.Name = edge.Source.Name + "->" + edge.Target.Name;
                cg.AddEdge(edge);
                count++;
            }
            return(cg);
        }
        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);
        }
Example #3
0
        public bool Test(IVertex v)
        {
            NamedVertex nv = v as NamedVertex;

            if (nv == null)
            {
                return(false);
            }
            return(nv.Name == name);
        }
        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 static BidirectionalGraph RegularLattice(int rows, int columns)
        {
            // create a new adjacency graph
            BidirectionalGraph g = new BidirectionalGraph(
                new NamedVertexProvider(),
                new EdgeProvider(),
                false);

            NamedVertex[,] latice = new NamedVertex[rows,columns];
            // adding vertices
            for(int i=0;i<rows;++i)
            {
                for(int j=0;j<columns;++j)
                {
                    latice[i,j] = (NamedVertex)g.AddVertex();
                    latice[i,j].Name = String.Format("{0},{1}",i.ToString(),j.ToString());
                }
            }

            // adding edges
            for(int i =0;i<rows-1;++i)
            {
                for(int j=0;j<columns-1;++j)
                {
                    g.AddEdge(latice[i,j], latice[i,j+1]);
                    g.AddEdge(latice[i,j+1], latice[i,j]);

                    g.AddEdge(latice[i,j], latice[i+1,j]);
                    g.AddEdge(latice[i+1,j], latice[i,j]);
                }
            }

            for(int j=0;j<columns-1;++j)
            {
                g.AddEdge(latice[rows-1,j], latice[rows-1,j+1]);
                g.AddEdge(latice[rows-1,j+1], latice[rows-1,j]);
            }

            for(int i=0;i<rows-1;++i)
            {
                g.AddEdge(latice[i,columns-1], latice[i+1,columns-1]);
                g.AddEdge(latice[i+1,columns-1], latice[i,columns-1]);
            }

            return g;
        }