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