changes to handle fixed point analysis properly + bug fix.
[IRC.git] / Robust / src / Analysis / Scheduling / ScheduleEdge.java
1 package Analysis.Scheduling;
2
3 import java.util.Iterator;
4
5 import Analysis.TaskStateAnalysis.*;
6 import Util.Edge;
7 import Util.GraphNode;
8
9 /* Edge *****************/
10 public class ScheduleEdge extends Edge {
11
12   public final static int NEWEDGE = 0;
13   public final static int TRANSEDGE = 1;
14
15   protected int uid;
16   protected int gid;
17   protected static int nodeID=0;
18
19   protected String label;
20   protected final FlagState fstate;
21   protected int type;   // 0--new edge: indicate creating new objects
22                         // 1--transmit edge: indicate transimitting an existing object
23
24   protected FlagState targetFState;
25
26   private ClassNode sourceCNode;
27   private ClassNode targetCNode;
28
29   private double probability;
30   private long transTime;
31   private long listExeTime;
32
33   private FEdge fedge;
34   private int newRate;
35
36   private boolean isclone;
37
38   /** Class Constructor
39    *
40    */
41   public ScheduleEdge(ScheduleNode target, 
42                       String label, 
43                       FlagState fstate, 
44                       int type, 
45                       int gid) {
46     super(target);
47     this.uid = ScheduleEdge.nodeID++;
48     this.gid = gid;
49     this.fedge = null;
50     this.targetFState = null;
51     this.sourceCNode = null;
52     this.targetCNode = null;
53     this.label = label;
54     this.fstate = fstate;
55     this.newRate = -1;
56     this.probability = 100;
57     this.transTime = -1;
58     this.listExeTime = -1;
59     this.isclone = false;
60     this.type = type;
61   }
62
63   public boolean isclone() {
64     return isclone;
65   }
66
67   public void setIsclone(boolean isclone) {
68     this.isclone = isclone;
69   }
70
71   public void setTarget(GraphNode sn) {
72     this.target = sn;
73   }
74
75   public int getType() {
76     return type;
77   }
78
79   public String getLabel() {
80     String completeLabel = label;
81     if(ScheduleEdge.NEWEDGE == this.type) {
82       completeLabel += ":" + Integer.toString(this.newRate);
83     }
84     completeLabel += ":(" + Double.toString(this.probability) + "%)" + ":[" + Long.toString(this.transTime) + "]";
85     return completeLabel;
86   }
87
88   public FlagState getFstate() {
89     return fstate;
90   }
91
92   public FEdge getFEdge() {
93     return this.fedge;
94   }
95
96   public void setFEdge(FEdge fEdge) {
97     this.fedge = fEdge;
98   }
99
100   public FlagState getSourceFState() {
101     if(this.fedge == null) {
102       return null;
103     }
104     return (FlagState) this.fedge.getTarget();
105   }
106
107   public void setTargetFState(FlagState targetFState) {
108     this.targetFState = targetFState;
109   }
110
111   public FlagState getTargetFState() {
112     return this.targetFState;
113   }
114
115   public double getProbability() {
116     return this.probability;
117   }
118
119   public int getNewRate() {
120     return this.newRate;
121   }
122
123   public ClassNode getSourceCNode() {
124     return this.sourceCNode;
125   }
126
127   public void setSourceCNode(ClassNode sourceCNode) {
128     this.sourceCNode = sourceCNode;
129   }
130
131   public ClassNode getTargetCNode() {
132     return this.targetCNode;
133   }
134
135   public void setTargetCNode(ClassNode targetCNode) {
136     this.targetCNode = targetCNode;
137     this.transTime = targetCNode.getTransTime();
138   }
139
140   public boolean equals(Object o) {
141     if (o instanceof ScheduleEdge) {
142       ScheduleEdge e=(ScheduleEdge)o;
143       if(e.gid == this.gid) {
144         if(e.uid != this.uid) {
145           return false;
146         }
147       }
148       if ((e.label.equals(label))&&
149           (e.target.equals(target))&&
150           (e.source.equals(source)) &&
151           (e.fstate.equals(fstate)) &&
152           (e.sourceCNode.equals(sourceCNode)) &&
153           (e.targetCNode.equals(targetCNode)) &&
154           (e.newRate == newRate) &&
155           (e.probability == probability) &&
156           (e.type == type) &&
157           (e.transTime == transTime) &&
158           (e.listExeTime == listExeTime))
159         if(e.targetFState != null) {
160           if(!e.targetFState.equals(targetFState)) {
161             return false;
162           }
163         } else if(this.targetFState != null) {
164           return false;
165         }
166       if(e.fedge != null) {
167         return e.fedge.equals(fedge);
168       } else if(this.fedge == null) {
169         return true;
170       }
171     }
172     return false;
173   }
174
175   public int hashCode() {
176     int hashcode = gid^uid^label.hashCode()^target.hashCode()^source.hashCode()^fstate.hashCode()^
177                    sourceCNode.hashCode()^targetCNode.hashCode()^newRate^(int)probability^
178                    type^(int)transTime^(int)listExeTime;
179     if(targetFState != null) {
180       hashcode ^= targetFState.hashCode();
181     }
182     if(fedge != null) {
183       hashcode ^= fedge.hashCode();
184     }
185     return hashcode;
186   }
187
188   public void setProbability(double prob) {
189     this.probability = prob;
190   }
191
192   public void setNewRate(int nr) {
193     this.newRate = nr;
194   }
195
196   public long getTransTime() {
197     return this.transTime;
198   }
199
200   public void setTransTime(long transTime) {
201     this.transTime = transTime;
202   }
203
204   public long getListExeTime() {
205     if(listExeTime == -1) {
206       // calculate the lisExeTime
207       listExeTime = ((ScheduleNode) this.getTarget()).getExeTime() + this.getTransTime() * this.getNewRate();
208       Iterator it_edges = this.getTarget().edges();
209       long temp = 0;
210       if(it_edges.hasNext()) {
211         temp = ((ScheduleEdge)it_edges.next()).getListExeTime();
212       }
213       while(it_edges.hasNext()) {
214         long tetime = ((ScheduleEdge)it_edges.next()).getListExeTime();
215         if(temp < tetime) {
216           temp = tetime;
217         }
218       }
219       listExeTime += temp;
220     }
221     return this.listExeTime;
222   }
223
224   public void resetListExeTime() {
225     this.listExeTime = -1;
226   }
227 }