Add new feature of splitting nodes into Scheduling algorithm and fix some bugs in...
[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 String label;
14     private final ClassDescriptor cd;
15     private boolean isNew = true;
16     
17     private FlagState targetFState;
18     private ClassNode sourceCNode;
19     private ClassNode targetCNode;
20     
21     private int probability;
22     private int transTime;
23     private int listExeTime;
24     
25     private FEdge fedge;
26     private int newRate;
27     
28     /** Class Constructor
29      * 
30      */
31     public ScheduleEdge(ScheduleNode target, String label, ClassDescriptor cd) {
32         super(target);
33         this.fedge = null;
34         this.targetFState = null;
35         this.sourceCNode = null;
36         this.targetCNode = null;
37         this.label = label;
38         this.cd = cd;
39         this.newRate = -1;
40         this.probability = 100;
41         this.transTime = -1;
42         this.listExeTime = -1;
43     }
44     
45     public ScheduleEdge(ScheduleNode target, String label, ClassDescriptor cd, boolean isNew) {
46         super(target);
47         this.fedge = null;
48         this.targetFState = null;
49         this.sourceCNode = null;
50         this.targetCNode = null;
51         this.label = label;
52         this.cd = cd;
53         this.newRate = -1;
54         this.probability = 100;
55         this.transTime = -1;
56         this.listExeTime = -1;
57         this.isNew = isNew;
58     }
59     
60     public void setTarget(GraphNode sn) {
61         this.target = sn;
62     }
63     
64     public String getLabel() {
65         String completeLabel = label;
66         if(isNew) {
67             completeLabel += ":" + Integer.toString(this.newRate);
68         }
69         completeLabel += ":(" + Integer.toString(this.probability) + "%)" + ":[" + Integer.toString(this.transTime) + "]";
70         return completeLabel;
71     }
72     
73     public int hashCode(){
74         return target.hashCode()^label.hashCode();
75     }
76     
77     public ClassDescriptor getClassDescriptor() {
78         return cd;
79     }
80     
81     public boolean getIsNew() {
82         return this.isNew;
83     }
84     
85     public FEdge getFEdge() {
86         return this.fedge;
87     }
88     
89     public void setFEdge(FEdge fEdge) {
90         this.fedge = fEdge;
91     }
92     
93     public FlagState getSourceFState() {
94         if(this.fedge == null) {
95             return null;
96         }
97         return (FlagState)this.fedge.getTarget();
98     }
99     
100     public void setTargetFState(FlagState targetFState) {
101         this.targetFState = targetFState;
102     }
103     
104     public FlagState getTargetFState() {
105         return this.targetFState;
106     }
107     
108     public int getProbability() {
109         return this.probability;
110     }
111     
112     public int getNewRate() {
113         return this.newRate;
114     }
115     
116     public ClassNode getSourceCNode() {
117         return this.sourceCNode;
118     }
119     
120     public void setSourceCNode(ClassNode sourceCNode) {
121         this.sourceCNode = sourceCNode;
122     }
123     
124     public ClassNode getTargetCNode() {
125         return this.targetCNode;
126     }
127     
128     public void setTargetCNode(ClassNode targetCNode) {
129         this.targetCNode = targetCNode;
130         this.transTime = targetCNode.getTransTime();
131     }
132         
133     public boolean equals(Object o) {
134         if (o instanceof ScheduleEdge) {
135             ScheduleEdge e=(ScheduleEdge)o;
136             if ((e.label.equals(label))&&
137                 (e.target.equals(target))&&
138                 (e.source.equals(source)) &&
139                 (e.cd.equals(cd)) && 
140                 (e.fedge.equals(fedge)) &&  
141                 (e.sourceCNode.equals(sourceCNode)) &&
142                 (e.targetCNode.equals(targetCNode)) &&
143                 (e.newRate == newRate) && 
144                 (e.probability == probability) && 
145                 (e.isNew == isNew) && 
146                 (e.transTime == transTime) && 
147                 (e.listExeTime == listExeTime))
148                 if(e.targetFState != null) {
149                     return e.targetFState.equals(targetFState);
150                 } else if(this.targetFState == null) {
151                     return true;
152                 } else {
153                     return false;
154                 }
155         }
156         return false;
157     }
158     
159     public void setProbability(int prob) {
160         this.probability = prob;
161     }
162     
163     public void setNewRate(int nr) {
164         this.newRate = nr;
165     }
166     
167     public int getTransTime() {
168         return this.transTime;
169     }
170     
171     public void setTransTime(int transTime) {
172         this.transTime = transTime;
173     }
174     
175     public int getListExeTime() {
176         if(listExeTime == -1) {
177             // calculate the lisExeTime
178             listExeTime = ((ScheduleNode)this.getTarget()).getExeTime() + this.getTransTime() * this.getNewRate();
179             Iterator it_edges = this.getTarget().edges();
180             int temp = 0;
181             if(it_edges.hasNext()) {
182                    temp = ((ScheduleEdge)it_edges.next()).getListExeTime();
183             }
184             while(it_edges.hasNext()) {
185                 int tetime = ((ScheduleEdge)it_edges.next()).getListExeTime();
186                 if(temp < tetime) {
187                     temp = tetime;
188                 }
189             }
190             listExeTime += temp;
191         }
192         return this.listExeTime;
193     }
194     
195     public void resetListExeTime() {
196         this.listExeTime = -1;
197     }
198 }