- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
Latest commit
66 lines (59 loc) · 1.79 KB
/
Copy pathMain.java
File metadata and controls
66 lines (59 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* AUTHOR https://github.com/code-blooded */
importjava.io.PrintWriter;
importjava.util.ArrayList;
importjava.util.List;
importjava.util.Random;
classrandom_graph {
publicintnodes;
privateListconnected;
privateListunconnected;
privatePrintWriterwriter;
random_graph(intn){
nodes = n;
connected = newArrayList();
unconnected = newArrayList();
connected.add(1);
for (inti = 2; i <= nodes; i++) {
unconnected.add(i);
}
try {
writer = newPrintWriter("the-file-name.txt", "UTF-8");
}catch (Exceptione) {
System.out.println("File Error");
}
}
voidgenerate(doublepercentage){
intextra_edges,edges;
extra_edges = (int)(nodes*nodes*(percentage/100.0));
System.out.println(extra_edges);
edges = 0;
RandomR = newRandom(4587);
while(!unconnected.isEmpty()){
inttemp1 = R.nextInt(connected.size());
inttemp2 = R.nextInt(unconnected.size());
intu = (int)connected.get(temp1);
intv = (int)unconnected.get(temp2);
addEdge(u,v);
unconnected.remove(temp2);
connected.add(v);
edges++;
}
while(extra_edges>0){
inttemp1 = R.nextInt(nodes);
inttemp2 = R.nextInt(nodes);
addEdge(temp1,temp2);
extra_edges--;
}
writer.close();
}
voidaddEdge(intu,intv){
//System.out.println(u+" "+v);
writer.println(u+" "+v);
}
}
publicclassMain {
publicstaticvoidmain(String[] args) {
random_graphg = newrandom_graph(1000);
g.generate(0.1);
}
}