AddVertex() public method

public AddVertex ( Vertex x, Vertex y ) : void
x Vertex
y Vertex
return void
Esempio n. 1
0
        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);
                }
            }
        }
Esempio n. 2
0
	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);
	              
		       
		    }		
		}
	}