-
Notifications
You must be signed in to change notification settings - Fork 1
/
LP4Driver.java
48 lines (40 loc) · 1.42 KB
/
LP4Driver.java
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
package rsn170330.lp4;
import java.util.Scanner;
// Driver code for PERT: *recommend to use main() of PERT instead*
public class LP4Driver {
public static void main(String[] args) throws Exception {
boolean details = false;
if (args.length > 0) {
details = Boolean.parseBoolean(args[0]);
}
String graph = "11 12 2 4 1 2 5 1 3 5 1 3 6 1 4 7 1 5 7 1 5 8 1 "
+ " 6 8 1 6 9 1 7 10 1 8 10 1 9 10 1 "
+ " 0 3 2 3 2 1 3 2 4 1 0 ";
Scanner in;
// If there is a command line argument, use it as file from which
// input is read, otherwise use input from string.
in = (args.length > 1) ? new Scanner(new java.io.File(args[1])) : new Scanner(graph);
rbk.Graph g = rbk.Graph.readDirectedGraph(in);
//g.printGraph(false);
int[] duration = new int[g.size()];
for (int i = 0; i < g.size(); i++) {
duration[i] = in.nextInt();
}
PERT p = PERT.pert(g, duration);
if (p == null) {
System.out.println("Invalid graph: not a DAG");
}
else {
if (g.size() <= 20 || details) {
g.printGraph(false);
System.out.println("u\tDur\tEC\tLC\tSlack\tCritical");
for (rbk.Graph.Vertex u : g) {
System.out.println(u + "\t" + duration[u.getIndex()] + "\t" + p.ec(u)
+ "\t" + p.lc(u) + "\t" + p.slack(u) + "\t" + p.critical(u));
}
}
System.out.println("Length of Critical Path: " + p.criticalPath()
+ "\nNumber of Critical Nodes: " + p.numCritical());
}
}
}