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