bug fix in scheduling
[IRC.git] / Robust / src / Analysis / Scheduling / SimExecutionEdge.java
1 package Analysis.Scheduling;
2
3 import java.util.Vector;
4
5 import IR.TaskDescriptor;
6 import Util.Edge;
7
8 public class SimExecutionEdge extends Edge {
9     
10     private int eid;
11     private static int nodeID=0;
12     
13     private int coreNum;
14     private TaskDescriptor td;
15     private Vector<Integer> taskparams;
16     private long weight;
17     
18     private long bestStartPoint;
19     private SimExecutionNode lastpredicatenode;
20     private SimExecutionEdge lastpredicateedge;
21     private Vector<SimExecutionEdge> predicates;
22     private boolean isFixedTime;
23
24     public SimExecutionEdge(SimExecutionNode target,
25                             int corenum,
26                             TaskDescriptor td,
27                             long weight,
28                             Vector<Integer> taskparams) {
29         super(target);
30         this.eid = SimExecutionEdge.nodeID++;
31         this.coreNum = corenum;
32         this.td = td;
33         this.taskparams = taskparams;
34         this.weight = weight;
35         this.bestStartPoint = -1;
36         this.lastpredicatenode = null;
37         this.lastpredicateedge = null;
38         this.predicates = null;
39         this.isFixedTime = true;
40     }
41     
42     public long getBestStartPoint() {
43         if(this.bestStartPoint == -1) {
44             if((this.predicates != null) && (this.predicates.size() > 0)) {
45                 // have predicates
46                 long starttime = 0;
47                 // check the latest finish time of all the predicates
48                 for(int j = 0; j < this.predicates.size(); j++) {
49                     SimExecutionEdge predicate = this.predicates.elementAt(j);
50                     long tmptime = predicate.getBestStartPoint() + predicate.getWeight();
51                     if(tmptime > starttime) {
52                         starttime = tmptime;
53                         this.lastpredicateedge = predicate;
54                         if(predicate.getTd() != null) {
55                             this.lastpredicatenode = (SimExecutionNode)predicate.getTarget();
56                         } else {
57                             // transfer edge
58                             this.lastpredicatenode = (SimExecutionNode)predicate.getSource();
59                         }
60                     }
61                 }
62                 this.bestStartPoint = starttime;
63             } else {
64                 // no predicates
65                 this.bestStartPoint = 0;
66             }
67         }
68         return bestStartPoint;
69     }
70
71     public void setBestStartPoint(long bestStartPoint) {
72         this.bestStartPoint = bestStartPoint;
73     }
74     
75     public Vector<SimExecutionEdge> getPredicates() {
76         return predicates;
77     }
78     
79     public void addPredicate(SimExecutionEdge predicate) {
80         if(this.predicates == null) {
81             this.predicates = new Vector<SimExecutionEdge>();
82         }
83         if(!this.predicates.contains(predicate)) {
84             this.predicates.add(predicate);
85         }
86     }
87
88     public Vector<Integer> getTaskparams() {
89         return taskparams;
90     }
91
92     public TaskDescriptor getTd() {
93         return td;
94     }
95
96     public long getWeight() {
97         return weight;
98     }
99
100     public void setWeight(int weight) {
101         this.weight = weight;
102     }
103
104     public int getCoreNum() {
105         return coreNum;
106     }
107
108     public SimExecutionNode getLastpredicateNode() {
109         return lastpredicatenode;
110     }
111
112     public void setLastpredicateNode(SimExecutionNode lastpredicatenode) {
113         this.lastpredicatenode = lastpredicatenode;
114     }
115
116     public SimExecutionEdge getLastpredicateEdge() {
117         return lastpredicateedge;
118     }
119
120     public void setLastpredicateEdge(SimExecutionEdge lastpredicateedge) {
121         this.lastpredicateedge = lastpredicateedge;
122     }
123
124     public boolean isFixedTime() {
125         return isFixedTime;
126     }
127
128     public void setFixedTime(boolean isFixedTime) {
129         this.isFixedTime = isFixedTime;
130     }
131
132     public String getLabel() {
133         String completeLabel = (this.td != null? this.td.getSymbol():"")
134                                + "(" + this.weight + " | " + this.bestStartPoint + ")";
135         return completeLabel;
136     }
137     
138     public void destroy() {
139         this.td = null;
140         if(this.taskparams != null) {
141             this.taskparams.clear();
142             this.taskparams = null;
143         }
144         this.lastpredicatenode = null;
145         this.lastpredicateedge = null;
146         if(this.predicates != null) {
147             this.predicates.clear();
148             this.predicates = null;
149         }
150         this.source.getEdgeVector().clear();
151         this.source.getInedgeVector().clear();
152         this.source = null;
153         this.target.getEdgeVector().clear();
154         this.target.getInedgeVector().clear();
155         this.target = null;
156     }
157 }