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