Exemplo n.º 1
0
        static List <Edge <T> > adjEdges(MazeGraph <T> G, int i)
        {
            List <MazeGraph <T> .VertexCost> adj = G.Adjacents(i);
            List <Edge <T> > adjEdges_           = new List <Edge <T> >(adj.Count);

            for (int j = 0; j < adj.Count; ++j)
            {
                adjEdges_.Add(new Edge <T>(i, adj[j].vertex, adj[j].cost));
            }
            return(adjEdges_);
        }
Exemplo n.º 2
0
 static void initializeVariables(MazeGraph <T> G)
 {
     n     = G.numVert();
     g     = new MazeGraph <T>(n, G.rows, G.cols);
     P     = new Partition(n);
     queue = new PartialOrderedTree <Edge <T> >(n * n);
     for (int i = 0; i < n; ++i)
     {
         List <MazeGraph <T> .VertexCost> adj = G.Adjacents(i);
         for (int j = 0; j < adj.Count; ++j)
         {
             queue.insert(new Edge <T>(i, adj[j].vertex, adj[j].cost));
         }
     }
 }
Exemplo n.º 3
0
        public static MazeGraph <T> Execute(MazeGraph <T> G)
        {
            InitializeVariables(G);
            //int count = 0;
            int idx   = rand.Next(0, unvisited.Count);
            int first = unvisited[idx];

            unvisited.RemoveAt(idx);
            while (unvisited.Count > 0) //&& count<500000) {
            {
                int        current = unvisited[rand.Next(0, unvisited.Count)];
                List <int> path    = new List <int>();
                path.Add(current);
                while (unvisited.IndexOf(current) != -1)  //&& count < 500000) {
                {
                    current = G.Adjacents(current)[rand.Next(0, G.Adjacents(current).Count)].vertex;
                    int pos = path.IndexOf(current);
                    if (pos == -1)
                    {
                        path.Add(current);
                    }
                    else
                    {
                        path = path.GetRange(0, pos + 1);
                    }
                    //count++;
                }
                for (int i = 0; i < path.Count - 1; ++i)
                {
                    g.addEdge(path[i], path[i + 1], default(T));
                    g.addEdge(path[i + 1], path[i], default(T));
                    unvisited.Remove(path[i]);
                }
            }
            return(g);
        }