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