x.f = y now prunes new edge's beta by alpha at x
[IRC.git] / Robust / src / Benchmarks / PERT / Mcore / Estimator.java
1 public class Estimator {
2     flag estimate;
3     flag prob;
4
5     int stages;
6     int time;
7     float variance;
8     float[] probtable;
9
10     public Estimator(int stages) {
11         this.stages = stages;
12         this.time = 0;
13         this.variance = 0;
14
15         this.probtable = new float[31];
16         int i = 0;
17         this.probtable[i++] = (float)0.5000;
18         this.probtable[i++] = (float)0.5398;
19         this.probtable[i++] = (float)0.5793;
20         this.probtable[i++] = (float)0.6179;
21         this.probtable[i++] = (float)0.6554;
22         this.probtable[i++] = (float)0.6915;
23         this.probtable[i++] = (float)0.7257;
24         this.probtable[i++] = (float)0.7580;
25         this.probtable[i++] = (float)0.7881;
26         this.probtable[i++] = (float)0.8159;
27         this.probtable[i++] = (float)0.8413;
28         this.probtable[i++] = (float)0.8643;
29         this.probtable[i++] = (float)0.8849;
30         this.probtable[i++] = (float)0.9032;
31         this.probtable[i++] = (float)0.9192;
32         this.probtable[i++] = (float)0.9332;
33         this.probtable[i++] = (float)0.9452;
34         this.probtable[i++] = (float)0.9554;
35         this.probtable[i++] = (float)0.9641;
36         this.probtable[i++] = (float)0.9713;
37         this.probtable[i++] = (float)0.9772;
38         this.probtable[i++] = (float)0.9821;
39         this.probtable[i++] = (float)0.9861;
40         this.probtable[i++] = (float)0.9893;
41         this.probtable[i++] = (float)0.9918;
42         this.probtable[i++] = (float)0.9938;
43         this.probtable[i++] = (float)0.9953;
44         this.probtable[i++] = (float)0.9965;
45         this.probtable[i++] = (float)0.9974;
46         this.probtable[i++] = (float)0.9981;
47         this.probtable[i++] = (float)0.9987;
48     }
49
50     public boolean estimate(int time, float variance2) {
51         //System.printI(0xff30);
52         this.time += time;
53         this.variance += variance2;
54         --this.stages;
55         //System.printI(0xff31);
56         //System.printI(this.stages);
57         //System.printI(this.time);
58         //System.printI((int)this.variance);
59         if(this.stages == 0) {
60             //System.printI(0xff32);
61             //System.printString("variance2: " + (int)(this.variance*100) + "(/100); ");
62             this.variance = Math.sqrtf(this.variance);
63             //System.printString("variance: " + (int)(this.variance*100) + "(/100)\n");
64             return true;
65         }
66         //System.printI(0xff33);
67         return false;
68     }
69
70     public float getProbability(int x, int y) {
71         int l = x;
72         int r = y;
73         if(x > y) {
74             l = y;
75             r = x;
76         }
77
78         float prob = prob(r) - prob(l);
79         return prob;
80     }
81
82     private float prob(int s) {
83         int tmp = (int)((s - this.time) * 10 / this.variance);
84         //System.printString(tmp + "\n");
85         int abs = (int)Math.abs(tmp);
86         float prob = 0;
87         if(abs > this.probtable.length - 1) {
88             prob = 1;
89         } else {
90             prob = this.probtable[abs];
91         }
92         if(tmp < 0) {
93             return (float)1.0 - prob;
94         } else {
95             return prob;
96         }
97     }
98
99     public int getTime() {
100         return this.time;
101     }
102
103     public float getVariance() {
104         return this.variance;
105     }
106
107 }