Add support for multi-parameter tasks as well as tag in multi-core version
[IRC.git] / Robust / src / Analysis / Scheduling / Schedule.java
1 package Analysis.Scheduling;
2
3 import java.util.Hashtable;
4 import java.util.LinkedList;
5 import java.util.Queue;
6 import java.util.Vector;
7
8 import Analysis.TaskStateAnalysis.FlagState;
9 import IR.TaskDescriptor;
10
11 /** This class holds flag transition diagram(s) can be put on one core.
12  */
13 public class Schedule {
14     private int coreNum;
15     private Vector<TaskDescriptor> tasks;
16     private Hashtable<FlagState, Queue<Integer>> targetCores;
17     private Hashtable<FlagState, FlagState> targetFState;
18     private Vector<Integer> ancestorCores;
19     private Vector<Integer> childCores;
20     private Hashtable<FlagState, Vector<Integer>> allyCores;
21     private Hashtable<TaskDescriptor, Vector<FlagState>> td2fs;
22     
23     public Schedule(int coreNum) {
24         super();
25         this.coreNum = coreNum;
26         this.tasks = null;
27         this.targetCores = null;
28         this.targetFState = null;
29         this.ancestorCores = null;
30         this.allyCores = null;
31         this.td2fs = null;
32     }
33
34     public int getCoreNum() {
35         return coreNum;
36     }
37     
38     public Hashtable<FlagState, Queue<Integer>> getTargetCoreTable() {
39         return targetCores;
40     }
41     
42     public Queue<Integer> getTargetCores(FlagState fstate) {
43         if(targetCores == null) {
44             return null;
45         }
46         return targetCores.get(fstate);
47     }
48     
49     public Hashtable<FlagState, FlagState> getTargetFStateTable() {
50         return targetFState;
51     }
52     
53     public FlagState getTargetFState(FlagState fstate) {
54         if(targetFState == null) {
55             return null;
56         }
57         return targetFState.get(fstate);
58     }
59     
60     public Hashtable<FlagState, Vector<Integer>> getAllyCoreTable() {
61         return this.allyCores;
62     }
63     
64     public Vector<Integer> getAllyCores(FlagState fstate) {
65         if(this.allyCores == null) {
66             return null;
67         }
68         return this.allyCores.get(fstate);
69     }
70     
71     public Hashtable<TaskDescriptor, Vector<FlagState>> getTd2FsTable() {
72         return this.td2fs;
73     }
74     
75     public Vector<FlagState> getFStates4TD(TaskDescriptor td) {
76         if(this.td2fs == null) {
77             return null;
78         }
79         return this.td2fs.get(td);
80     }
81
82     public void addTargetCore(FlagState fstate, Integer targetCore/*, Integer num*/) {
83         if(this.targetCores == null) {
84             this.targetCores = new Hashtable<FlagState, Queue<Integer>>();
85         }
86         if(!this.targetCores.containsKey(fstate)) {
87             this.targetCores.put(fstate, new LinkedList<Integer>());
88         }
89         //if(!this.targetCores.get(fstate).contains(targetCore)) {
90             this.targetCores.get(fstate).add(targetCore); // there may have some duplicate items,
91                                                           // which reflects probabilities.
92         //}
93     }
94     
95     public void addTargetCore(FlagState fstate, Integer targetCore, FlagState tfstate) {
96         if(this.targetCores == null) {
97             this.targetCores = new Hashtable<FlagState, Queue<Integer>>();
98         }
99         if(!this.targetCores.containsKey(fstate)) {
100             this.targetCores.put(fstate, new LinkedList<Integer>());
101         }
102         //if(!this.targetCores.get(fstate).contains(targetCore)) {
103             this.targetCores.get(fstate).add(targetCore);
104         //}
105         if(this.targetFState == null) {
106             this.targetFState = new Hashtable<FlagState, FlagState>();
107         }
108         //if(!this.targetFState.containsKey(fstate)) {
109             this.targetFState.put(fstate, tfstate);
110         //}
111     }
112     
113     public void addAllyCore(FlagState fstate, Integer targetCore/*, Integer num*/) {
114         if(this.allyCores == null) {
115             this.allyCores = new Hashtable<FlagState, Vector<Integer>>();
116         }
117         if(!this.allyCores.containsKey(fstate)) {
118             this.allyCores.put(fstate, new Vector<Integer>());
119         }
120         if((this.coreNum != targetCore.intValue()) && (!this.allyCores.get(fstate).contains(targetCore))) {
121             this.allyCores.get(fstate).add(targetCore); // there may have some duplicate items,
122                                                           // which reflects probabilities.
123         }
124     }
125     
126     public void addFState4TD(TaskDescriptor td, FlagState fstate) {
127         if(this.td2fs == null) {
128             this.td2fs = new Hashtable<TaskDescriptor, Vector<FlagState>>();
129         }
130         if(!this.td2fs.containsKey(td)) {
131             this.td2fs.put(td, new Vector<FlagState>());
132         }
133         if(!this.td2fs.get(td).contains(fstate)) {
134             this.td2fs.get(td).add(fstate);
135         }
136     }
137
138     public Vector<TaskDescriptor> getTasks() {
139         return tasks;
140     }
141
142     public void addTask(TaskDescriptor task) {
143         if(this.tasks == null) {
144             this.tasks = new Vector<TaskDescriptor>();
145         }
146         if(!this.tasks.contains(task)) {
147             this.tasks.add(task);
148         }
149     }
150
151     public Vector<Integer> getAncestorCores() {
152         return ancestorCores;
153     }
154
155     public void setAncestorCores(Vector<Integer> ancestorCores) {
156         this.ancestorCores = ancestorCores;
157     }
158
159     public void addAncestorCores(Integer ancestorCore) {
160         if(this.ancestorCores == null) {
161             this.ancestorCores = new Vector<Integer>();
162         }
163         if((ancestorCore.intValue() != this.coreNum) && (!this.ancestorCores.contains(ancestorCore))) {
164             this.ancestorCores.addElement(ancestorCore);
165         }
166     }
167     
168     public int ancestorCoresNum() {
169         if(this.ancestorCores == null) {
170             return 0;
171         }
172         return this.ancestorCores.size();
173     }
174
175     public Vector<Integer> getChildCores() {
176         return childCores;
177     }
178
179     public void setChildCores(Vector<Integer> childCores) {
180         this.childCores = childCores;
181     }
182     
183     public void addChildCores(Integer childCore) {
184         if(this.childCores == null) {
185             this.childCores = new Vector<Integer>();
186         }
187         if((childCore.intValue() != this.coreNum) && (!this.childCores.contains(childCore))) {
188             this.childCores.addElement(childCore);
189         }
190     }
191     
192     public int childCoresNum() {
193         if(this.childCores == null) {
194             return 0;
195         }
196         return this.childCores.size();
197     }
198     
199 }