DefaultNamespace.Graph.BuildGraph C# (CSharp) 메소드

BuildGraph() 공개 메소드

public BuildGraph ( ) : void
리턴 void
	public void BuildGraph() {
		
		// Build Nodes	
		Console.WriteLine("Building Vertices...");
		for(int i=0;i< Nodes; i++) {
			Vertex temp = new Vertex(i);
			if(Vfirst==null) {
			     Vfirst = temp;
			     Vlast = temp;
		        }
		        else {
			     temp.AddVertex(Vlast,temp);
			     Vlast = temp;
                        }
			Console.WriteLine("Vertex {0} built...",i);
		}
		
		// Build Edges
		Console.WriteLine("Building Edges...");
	
		DateTime time = DateTime.Now;
		Int32 seed = (Int32)time.Ticks;
		Random rand = new Random(seed);
		
		for(int i=0;i< Nodes;i++) {
		    
		    int j = rand.Next(0,Nodes);
		    for(int k=0;k<j;k++) {
		       int v2;
		       while((v2 = rand.Next(0,Nodes))==i);     //select a random node, also avoid self-loops
		       BuildEdge(i,v2);                //build edge betn node i and v2
		       //Console.WriteLine("Edge built between {0} and {1}...",i,v2);
	              
		       
		    }		
		}
	}

Usage Example

예제 #1
0
        public static void Main()
        {
            Console.WriteLine("Building Graph with 800 vertices...");
            Graph MyGraph = new Graph(800); // graph with 800 nodes

            MyGraph.BuildGraph();

            Console.WriteLine("Checking if all vertices are reachable...");
            MyGraph.CheckIfReachable();

            //Console.WriteLine("Printing the Graph...");
            //MyGraph.PrintGraph();

            Console.WriteLine("Deleting a random vertex...");
            MyGraph.DeleteVertex();

            //MyGraph.PrintGraph();

            Console.WriteLine("Done");
            Environment.ExitCode = (0);
            Console.WriteLine("Test Passed");
        }
All Usage Examples Of DefaultNamespace.Graph::BuildGraph