helpful progress reporting
[IRC.git] / Robust / src / Benchmarks / PERT / Tag / PERT.java
1 task startup(StartupObject s{initialstate}) {
2
3     // read in configuration parameters
4     //System.printString("Top of task startup\n");
5     String path = new String("/home/jzhou/pert/conf.txt");
6     FileInputStream iStream = new FileInputStream(path);
7     byte[] b = new byte[1024];
8     int length = iStream.read(b);
9     if(length < 0) {
10         System.printString("Error! Can not read from configure file: " + path + "\n");
11         System.exit(-1);
12     }
13     iStream.close();
14     String content = new String(b, 0, length);
15     int index = content.indexOf('\n');
16     int stages = Integer.parseInt(content.subString(0, index));
17     Estimator estimator = new Estimator(stages){estimate};
18     for(int i = 0; i < stages; ++i) {
19         Stage stage = new Stage(i){sampling};
20     }
21
22     taskexit(s{!initialstate});
23 }
24
25 task sampling(Stage s{sampling}) {
26     //System.printString("Top of task sampling\n");
27
28     s.sampling();
29
30     taskexit(s{!sampling, estimate});
31 }
32
33 task estimateStage(Stage s{estimate}) {
34     //System.printString("Top of task estimateStage\n");
35
36     s.estimate();
37
38     taskexit(s{!estimate, merge});
39 }
40
41 task estimate(Estimator e{estimate}, optional Stage s{merge}) {
42     //System.printString("Top of task estimate\n");
43
44     boolean fake = false;
45     if(!isavailable(s)) {
46         fake = true;
47     }
48     boolean finish = e.estimate(s.getAntTime(), s.getAntVariance2(), fake);
49
50     if(finish) {
51         taskexit(e{!estimate, prob}, s{!merge});
52     } else {
53         taskexit(s{!merge});
54     }
55 }
56
57 task prob(Estimator e{prob}) {
58     //System.printString("Top of task prob\n");
59
60     if(e.isPartial()) {
61         System.printString("There are some sampling data unavailable. The anticipate probability may be greater than it should be!\n");
62     }
63
64     String path = new String("/home/jzhou/pert/prob.txt");
65     FileInputStream iStream = new FileInputStream(path);
66     byte b[] = new byte[1024];
67     int length = iStream.read(b);
68     if(length < 0) {
69         System.printString("Error! Can not read from input file: " + path + "\n");
70         System.exit(-1);
71     }
72     iStream.close();
73     String content = new String(b, 0, length);
74     int index = content.indexOf('\n');
75     int x = Integer.parseInt(content.subString(0, index));
76     content = content.subString(index + 1);
77     index = content.indexOf('\n');
78     int y = Integer.parseInt(content.subString(0, index));
79     //System.printString("x: " + x + "; y: " + y + "\n");
80     System.printString("The anticipate days need to finish this project is: " + e.getTime() + "\n");
81     System.printString("And the anticipate variance is: " + (int)(e.getVariance()*100) + "(/100)\n");
82     double prob = e.getProbability(x, y);
83
84     System.printString("The probability of this project to be finished in " + x + " to " + y + " days is: " + (int)(prob*100) + "%\n");
85     taskexit(e{!prob});
86 }