예제 #1
0
        public void Test(IVertexAndEdgeListGraph g, IVertex root)
        {
            this.root = root;

            RandomWalkAlgorithm walker = new RandomWalkAlgorithm(g);
            walker.TreeEdge +=new EdgeEventHandler(walker_TreeEdge);
            walker.Generate(root,50);

            BidirectionalAdaptorGraph bg = new BidirectionalAdaptorGraph(g);
            ReversedBidirectionalGraph rg = new ReversedBidirectionalGraph(bg);
            CyclePoppingRandomTreeAlgorithm pop = new CyclePoppingRandomTreeAlgorithm(rg);

            pop.InitializeVertex +=new VertexEventHandler(this.InitializeVertex);
            pop.FinishVertex +=new VertexEventHandler(this.FinishVertex);
            pop.TreeEdge += new EdgeEventHandler(this.TreeEdge);

            pop.InitializeVertex +=new VertexEventHandler(vis.InitializeVertex);
            pop.TreeEdge += new EdgeEventHandler(vis.TreeEdge);
            pop.ClearTreeVertex += new VertexEventHandler(vis.ClearTreeVertex);

            pop.RandomTreeWithRoot(root);

            // plot tree...
            GraphvizAlgorithm gv = new GraphvizAlgorithm(g,".",GraphvizImageType.Svg);
            gv.FormatEdge +=new FormatEdgeEventHandler(this.FormatEdge);
            gv.FormatVertex +=new FormatVertexEventHandler(this.FormatVertex);

            gv.Write("randomtree");
        }
        public void IsolatedVerticesWithRoot()
        {
            var g = new AdjacencyGraph<int, Edge<int>>(true);
            g.AddVertex(0);
            g.AddVertex(1);

            var target = new CyclePoppingRandomTreeAlgorithm<int, Edge<int>>(g);
            target.RandomTreeWithRoot(0);
        }
        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 RootIsNotAccessible()
        {
            AdjacencyGraph<int, Edge<int>> g = new AdjacencyGraph<int, Edge<int>>(true);
            g.AddVertex(0);
            g.AddVertex(1);
            g.AddEdge(new Edge<int>(0, 1));

            target = new CyclePoppingRandomTreeAlgorithm<int, Edge<int>>(g);
            target.RandomTreeWithRoot(0);
        }
        public void IsolatedVerticesWithRoot()
        {
            var g = new AdjacencyGraph <int, Edge <int> >(true);

            g.AddVertex(0);
            g.AddVertex(1);

            var target = new CyclePoppingRandomTreeAlgorithm <int, Edge <int> >(g);

            target.RandomTreeWithRoot(0);
        }
        public void RootIsNotAccessible()
        {
            AdjacencyGraph <int, Edge <int> > g = new AdjacencyGraph <int, Edge <int> >(true);

            g.AddVertex(0);
            g.AddVertex(1);
            g.AddEdge(new Edge <int>(0, 1));

            var target = new CyclePoppingRandomTreeAlgorithm <int, Edge <int> >(g);

            target.RandomTreeWithRoot(0);
        }
예제 #7
0
        public void GenerateWalls(int outi, int outj, int ini, int inj)
        {
            // here we use a uniform probability distribution among the out-edges
            CyclePoppingRandomTreeAlgorithm pop =
                new CyclePoppingRandomTreeAlgorithm(this.graph);

            // we can also weight the out-edges
            /*
            EdgeDoubleDictionary weights = new EdgeDoubleDictionary();
            foreach(IEdge e in this.graph.Edges)
                weights[e]=1;
            pop.EdgeChain = new WeightedMarkovEdgeChain(weights);
            */
            IVertex root = this.latice[outi,outj];
            if (root==null)
                throw new ArgumentException("outi,outj vertex not found");

            pop.RandomTreeWithRoot(this.latice[outi,outj]);
            this.successors = pop.Successors;

            // build the path to ini, inj
            IVertex v = this.latice[ini,inj];
            if (v==null)
                throw new ArgumentException("ini,inj vertex not found");
            this.outPath = new EdgeCollection();
            while (v!=root)
            {
                IEdge e = this.successors[v];
                if (e==null)
                    throw new Exception();
                this.outPath.Add(e);
                v = e.Target;
            }
        }