start of new file
[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 int probability;
30     private int transTime;
31     private int 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, String label, FlagState fstate, int type, int gid) {
42          super(target);
43          this.uid = ScheduleEdge.nodeID++;
44          this.gid = gid;
45          this.fedge = null;
46          this.targetFState = null;
47          this.sourceCNode = null;
48          this.targetCNode = null;
49          this.label = label;
50          this.fstate = fstate;
51          this.newRate = -1;
52          this.probability = 100;
53          this.transTime = -1;
54          this.listExeTime = -1;
55          this.isclone = false;
56          this.type = type;
57      }
58
59      public boolean isclone() {
60          return isclone;
61      }
62
63      public void setIsclone(boolean isclone) {
64          this.isclone = isclone;
65      }
66
67      public void setTarget(GraphNode sn) {
68          this.target = sn;
69      }
70      
71      public int getType() {
72          return type;
73      }
74
75      public String getLabel() {
76          String completeLabel = label;
77          if(ScheduleEdge.NEWEDGE == this.type) {
78              completeLabel += ":" + Integer.toString(this.newRate);
79          }
80          completeLabel += ":(" + Integer.toString(this.probability) + "%)" + ":[" + Integer.toString(this.transTime) + "]";
81          return completeLabel;
82      }
83
84      public FlagState getFstate() {
85          return fstate;
86      }
87
88      public FEdge getFEdge() {
89          return this.fedge;
90      }
91
92      public void setFEdge(FEdge fEdge) {
93          this.fedge = fEdge;
94      }
95
96      public FlagState getSourceFState() {
97          if(this.fedge == null) {
98              return null;
99          }
100          return (FlagState)this.fedge.getTarget();
101      }
102
103      public void setTargetFState(FlagState targetFState) {
104          this.targetFState = targetFState;
105      }
106
107      public FlagState getTargetFState() {
108          return this.targetFState;
109      }
110
111      public int getProbability() {
112          return this.probability;
113      }
114
115      public int getNewRate() {
116          return this.newRate;
117      }
118
119      public ClassNode getSourceCNode() {
120          return this.sourceCNode;
121      }
122
123      public void setSourceCNode(ClassNode sourceCNode) {
124          this.sourceCNode = sourceCNode;
125      }
126
127      public ClassNode getTargetCNode() {
128          return this.targetCNode;
129      }
130
131      public void setTargetCNode(ClassNode targetCNode) {
132          this.targetCNode = targetCNode;
133          this.transTime = targetCNode.getTransTime();
134      }
135
136      public boolean equals(Object o) {
137          if (o instanceof ScheduleEdge) {
138              ScheduleEdge e=(ScheduleEdge)o;
139              if(e.gid == this.gid) {
140                  if(e.uid != this.uid) {
141                      return false;
142                  }
143              }
144              if ((e.label.equals(label))&&
145                      (e.target.equals(target))&&
146                      (e.source.equals(source)) && 
147                      (e.fstate.equals(fstate)) &&
148                      (e.sourceCNode.equals(sourceCNode)) &&
149                      (e.targetCNode.equals(targetCNode)) &&
150                      (e.newRate == newRate) && 
151                      (e.probability == probability) && 
152                      (e.type == type) && 
153                      (e.transTime == transTime) && 
154                      (e.listExeTime == listExeTime))
155                  if(e.targetFState != null) {
156                      if(!e.targetFState.equals(targetFState)) {
157                          return false;
158                      }
159                  } else if(this.targetFState != null) {
160                      return false;
161                  } 
162              if(e.fedge != null) {
163                  return e.fedge.equals(fedge);
164              } else if(this.fedge == null) {
165                  return true;
166              } 
167          }
168          return false;
169      }
170
171      public int hashCode(){
172          int hashcode = gid^uid^label.hashCode()^target.hashCode()^source.hashCode()^fstate.hashCode()^
173                         sourceCNode.hashCode()^targetCNode.hashCode()^newRate^probability^
174                         type^transTime^listExeTime;
175          if(targetFState != null) {
176              hashcode ^= targetFState.hashCode();
177          }
178          if(fedge != null) {
179              hashcode ^= fedge.hashCode();
180          }
181          return hashcode;
182      }
183
184      public void setProbability(int prob) {
185          this.probability = prob;
186      }
187
188      public void setNewRate(int nr) {
189          this.newRate = nr;
190      }
191
192      public int getTransTime() {
193          return this.transTime;
194      }
195
196      public void setTransTime(int transTime) {
197          this.transTime = transTime;
198      }
199
200      public int getListExeTime() {
201          if(listExeTime == -1) {
202              // calculate the lisExeTime
203              listExeTime = ((ScheduleNode)this.getTarget()).getExeTime() + this.getTransTime() * this.getNewRate();
204              Iterator it_edges = this.getTarget().edges();
205              int temp = 0;
206              if(it_edges.hasNext()) {
207                  temp = ((ScheduleEdge)it_edges.next()).getListExeTime();
208              }
209              while(it_edges.hasNext()) {
210                  int tetime = ((ScheduleEdge)it_edges.next()).getListExeTime();
211                  if(temp < tetime) {
212                      temp = tetime;
213                  }
214              }
215              listExeTime += temp;
216          }
217          return this.listExeTime;
218      }
219
220      public void resetListExeTime() {
221          this.listExeTime = -1;
222      }
223 }