make multicore version PERT benchmark work on RAW(without interruption)
[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; // only affected by transimit edges
18     private Hashtable<FlagState, Vector<Integer>> allyCores;
19     private Hashtable<TaskDescriptor, Vector<FlagState>> td2fs;
20     
21     public Schedule(int coreNum) {
22         super();
23         this.coreNum = coreNum;
24         this.tasks = null;
25         this.targetCores = null;
26         this.targetFState = null;
27         this.allyCores = null;
28         this.td2fs = null;
29     }
30
31     public int getCoreNum() {
32         return coreNum;
33     }
34     
35     public Hashtable<FlagState, Queue<Integer>> getTargetCoreTable() {
36         return targetCores;
37     }
38     
39     public Queue<Integer> getTargetCores(FlagState fstate) {
40         if(targetCores == null) {
41             return null;
42         }
43         return targetCores.get(fstate);
44     }
45     
46     public Hashtable<FlagState, FlagState> getTargetFStateTable() {
47         return targetFState;
48     }
49     
50     public FlagState getTargetFState(FlagState fstate) {
51         if(targetFState == null) {
52             return null;
53         }
54         return targetFState.get(fstate);
55     }
56     
57     public Hashtable<FlagState, Vector<Integer>> getAllyCoreTable() {
58         return this.allyCores;
59     }
60     
61     public Vector<Integer> getAllyCores(FlagState fstate) {
62         if(this.allyCores == null) {
63             return null;
64         }
65         return this.allyCores.get(fstate);
66     }
67     
68     public Hashtable<TaskDescriptor, Vector<FlagState>> getTd2FsTable() {
69         return this.td2fs;
70     }
71     
72     public Vector<FlagState> getFStates4TD(TaskDescriptor td) {
73         if(this.td2fs == null) {
74             return null;
75         }
76         return this.td2fs.get(td);
77     }
78
79     public void addTargetCore(FlagState fstate, Integer targetCore) {
80         if(this.targetCores == null) {
81             this.targetCores = new Hashtable<FlagState, Queue<Integer>>();
82         }
83         if(!this.targetCores.containsKey(fstate)) {
84             this.targetCores.put(fstate, new LinkedList<Integer>());
85         }
86         this.targetCores.get(fstate).add(targetCore); // there may have some duplicate items,
87                                                       // which reflects probabilities.
88     }
89     
90     public void addTargetCore(FlagState fstate, Integer targetCore, FlagState tfstate) {
91         if(this.targetCores == null) {
92             this.targetCores = new Hashtable<FlagState, Queue<Integer>>();
93         }
94         if(!this.targetCores.containsKey(fstate)) {
95             this.targetCores.put(fstate, new LinkedList<Integer>());
96         }
97         this.targetCores.get(fstate).add(targetCore);
98         if(this.targetFState == null) {
99             this.targetFState = new Hashtable<FlagState, FlagState>();
100         }
101         this.targetFState.put(fstate, tfstate);
102     }
103     
104     public void addAllyCore(FlagState fstate, Integer targetCore) {
105         if(this.allyCores == null) {
106             this.allyCores = new Hashtable<FlagState, Vector<Integer>>();
107         }
108         if(!this.allyCores.containsKey(fstate)) {
109             this.allyCores.put(fstate, new Vector<Integer>());
110         }
111         if((this.coreNum != targetCore.intValue()) && (!this.allyCores.get(fstate).contains(targetCore))) {
112             this.allyCores.get(fstate).add(targetCore); // there may have some duplicate items,
113                                                         // which reflects probabilities.
114         }
115     }
116     
117     public void addFState4TD(TaskDescriptor td, FlagState fstate) {
118         if(this.td2fs == null) {
119             this.td2fs = new Hashtable<TaskDescriptor, Vector<FlagState>>();
120         }
121         if(!this.td2fs.containsKey(td)) {
122             this.td2fs.put(td, new Vector<FlagState>());
123         }
124         if(!this.td2fs.get(td).contains(fstate)) {
125             this.td2fs.get(td).add(fstate);
126         }
127     }
128
129     public Vector<TaskDescriptor> getTasks() {
130         return tasks;
131     }
132
133     public void addTask(TaskDescriptor task) {
134         if(this.tasks == null) {
135             this.tasks = new Vector<TaskDescriptor>();
136         }
137         if(!this.tasks.contains(task)) {
138             this.tasks.add(task);
139         }
140     }    
141 }