package model.randomGraph ;

import java.util.Random ;
import java.util.Iterator;
import model.graphs.Graph;
import model.graphs.Node;

public class randomGraph<T extends Comparable<T>> extends Graph<T>{
	
	Graph<Integer> G ;
	Integer nodesNumber ;
	

	public randomGraph() {
		this.G = new Graph<Integer>() ;	
		this.nodesNumber = 0 ;
	}
		
	//TODO: escludere il caso in cui ci sono 0 nodi
	//Crea un numero casuale di nodi (MAX 10)	
	public void randomNodes() {
		
		Random random = new Random() ;
		
		Integer i ;
		int n = 10 ;
		int m = random.nextInt(n) ;
		
		System.out.println("Il numero di nodi è " + m );
	 	
		for (i=0;i<m;i++) {
			
			Node<Integer> x = new Node<Integer>(i) ;
		
			this.G.insertNode(x);
			this.nodesNumber ++ ;
		}
		
		this.G.print() ;
	}
		
	public void randomEdges(){
		
		Integer[] A = new Integer[this.nodesNumber] ;
		
        Iterator<Node<Integer>> I = this.G.V().iterator() ;
		
	    Integer i = 0 ;
	    
	    
	    while (I.hasNext()) {
	    	
	    	A[i] = I.next().getElement() ;
	    	i++ ;
	    	
	    }
	    
	   
		Node<Integer> u ;
		Node<Integer> v ;
		
		Random random1 = new Random() ;
		
		if (this.nodesNumber > 1) {
			
			int m = this.nodesNumber ;		//MAX_N edges
			
			int n = random1.nextInt(m) ;
			
			System.out.println("Il numero di archi è " + n );
			
			
	        for (i=0;i<n;i++){
				
				u = (Node<Integer>) new Node(A[random1.nextInt(this.nodesNumber - 1)]) ;
				v = (Node<Integer>) new Node(A[random1.nextInt(this.nodesNumber - 1)]) ;
				
				//TODO: verificare che l'arco non sia stato già creato
				if (u.getElement() != v.getElement()) {
					this.G.insertEdge(u, v) ;
					System.out.println("è stato appena creato un arco da " + u + " a " + v );
				}
				
				
				
			}
		}
	}

	
	//TODO: perqualecazzodimotivo non stampa il grafo
	public static void main (String[] args) {
		
		randomGraph<Integer> g1 = new randomGraph<Integer>() ;
		
		g1.randomNodes();
		g1.randomEdges();
		
		g1.print() ;
		
	}
}


@@ -562,63 +562,8 @@
 %0A%09%09%0A
-%09%09System.out.println(%22Il numero di nodi %C3%A8 %22 + m );%0A%09 %09%0A
 %09%09fo
@@ -689,30 +689,8 @@
 %09%09%7D%0A
-%09%09%0A%09%09this.G.print() ;%0A
 %09%7D%0A%09
@@ -718,25 +718,24 @@
 Edges()%7B%0A%09%09%0A
-%09
 %09Integer%5B%5D A
@@ -836,20 +836,16 @@
 ) ;%0A%09%09%0A%09
-    
 Integer 
@@ -865,20 +865,16 @@
 %0A%09    %0A%09
-    
 while (I
@@ -888,27 +888,19 @@
 t()) %7B%0A%09
-    %09%0A%09    
+%09%0A%09
 %09A%5Bi%5D = 
@@ -943,20 +943,16 @@
 %09    %09%0A%09
-    
 %7D%0A%09    %0A
@@ -956,17 +956,16 @@
   %0A%09   %0A
-%09
 %09Node%3CIn
@@ -975,17 +975,16 @@
 er%3E u ;%0A
-%09
 %09Node%3CIn
@@ -993,25 +993,24 @@
 ger%3E v ;%0A%09%09%0A
-%09
 %09Random rand
@@ -1033,17 +1033,16 @@
 () ;%0A%09%09%0A
-%09
 %09if (thi
@@ -1064,25 +1064,24 @@
  1) %7B%0A%09%09%09%0A%09%09
-%09
 int m = this
@@ -1116,17 +1116,16 @@
 s%0A%09%09%09%0A%09%09
-%09
 int n = 
@@ -1155,76 +1155,8 @@
 %09%0A%09%09
-%09System.out.println(%22Il numero di archi %C3%A8 %22 + n );%0A%09%09%09%0A%09%09%09%0A%09        
 for 
@@ -1175,17 +1175,16 @@
 )%7B%0A%09%09%09%09%0A
-%09
 %09%09%09u = (
@@ -1251,17 +1251,16 @@
  1)%5D) ;%0A
-%09
 %09%09%09v = (
@@ -1335,17 +1335,16 @@
 %09%09%09%09%0A%09%09%09
-%09
 //TODO: 
@@ -1390,17 +1390,16 @@
  creato%0A
-%09
 %09%09%09if (u
@@ -1437,17 +1437,16 @@
 ) %7B%0A%09%09%09%09
-%09
 this.G.i
@@ -1463,17 +1463,16 @@
 u, v) ;%0A
-%09
 %09%09%09%09Syst
@@ -1545,40 +1545,33 @@
  );%0A
-%09%09%09%09%7D%0A%09%09%09%09%0A%09%09%09%09%0A%09%09%09%09%0A
 %09%09%09%7D%0A
+%09%09%09%0A
 %09%09%7D%0A%09%7D
+%0A        %7D
 %0A%0A%09%0A
@@ -1583,49 +1583,26 @@
 DO: 
-perqualecazzodimotivo non stampa il grafo
+verificare print()
 %0A%09pu

Update randomGraph.java