dol: initial dol commit
[jump.git] / dol / src / dol / datamodel / mapping / Mapping.java
1 package dol.datamodel.mapping;
2
3 import java.util.Iterator;
4 import java.util.Vector;
5
6 import dol.datamodel.architecture.Architecture;
7 import dol.datamodel.architecture.Processor;
8 import dol.datamodel.pn.Process;
9 import dol.datamodel.pn.ProcessNetwork;
10 import dol.visitor.MapVisitor;
11
12     
13 /**
14  * This class defines a mapping.
15  */    
16 public class Mapping extends MapResource
17 {
18     public Mapping(String name)
19     {
20         super(name);
21         _compBindList = new Vector<ComputationBinding>();
22         _commBindList = new Vector<CommunicationBinding>();
23         _scheduleList = new Vector<Schedule>();
24         _variableList = new Vector<Variable>();
25         /**
26          * For some code generation back end, traversing via architecture
27          * model rather than mapping model is more convenient, since the 
28          * mapping model is a flattened view of the binding where one can
29          * not access all the binded processes from a processor. Therefore
30          * we annotate the binding information back to processor.
31          */
32         _processList = new Vector<Process>();
33         _processorList = new Vector<Processor>();
34     }
35
36     /**
37      * Accept a visitor
38      *
39      * @param x visitor object
40      */
41     public void accept(MapVisitor x) {
42         x.visitComponent(this);
43     }
44     
45     
46     /**
47      * Clone this Mapping.
48      *
49      * @return new instance of the Mapping
50      */
51     @SuppressWarnings("unchecked")
52     public Object clone() {
53         Mapping newObj = (Mapping) super.clone();
54         newObj.setCompBindList((Vector<ComputationBinding>)_compBindList.clone());
55         newObj.setCommBindList((Vector<CommunicationBinding>)_commBindList.clone());
56         newObj.setScheduleList((Vector<Schedule>)_scheduleList.clone());
57         newObj.setVarList((Vector<Variable>)_variableList.clone());
58         newObj.setProcessorList((Vector<Processor>)_processorList.clone());
59         newObj.setProcessList((Vector<Process>)_processList.clone());
60         return (newObj);
61     }
62     
63     /** Get the process network. */
64     public ProcessNetwork getPN() { return _pn; }
65     
66     /** Store a reference to the process network. */
67     public void setPN(ProcessNetwork pn) { _pn = pn; }
68     
69     /** Get the architecture */
70     public Architecture getArch() { return _arch; }
71     
72     /** Store a reference to the architecture. */
73     public void setArch(Architecture arch) { _arch = arch; }
74     
75     /**
76      * Get a list of computation bindings in this Mapping.
77      *
78      * @return the binding list
79      */
80     public Vector<ComputationBinding> getCompBindList() {
81         return _compBindList;
82     }
83
84     /**
85      * Get a list of processes in this Mapping.
86      *
87      * @return the process list
88      */
89     public Vector<Process> getProcessList() {
90         return _processList;
91     }
92
93     /**
94      * Return a process which has a specific name. Return null if
95      * process cannot be found.
96      *
97      * @param name the name of the process to search for.
98      * @return the process with the specific name or null if not found.
99      */    
100     public Process getProcess(String name)
101     {
102         for (Process process : _processList) {
103             if (process.getName().equals(name)) {
104                 return process;
105             }
106         }
107         return null;
108     }
109     /**
110      * Set the computation binding list of this mapping.
111      *
112      * @param compBindList The new list
113      */
114     public void setCompBindList( Vector<ComputationBinding> compBindList ) {
115         _compBindList = compBindList;
116     }
117     
118     /**
119      * Get a list of communication bindings in this Mapping.
120      *
121      * @return the binding list
122      */
123     public Vector<CommunicationBinding> getCommBindList() {
124         return _commBindList;
125     }
126
127     /**
128      * Set the communication binding list of this mapping.
129      *
130      * @param commBindList The new list
131      */
132     public void setCommBindList( Vector<CommunicationBinding> commBindList ) {
133         _commBindList = commBindList;
134     }
135
136     /**
137      * Set the process list of this mapping.
138      *
139      * @param processList The new list
140      */
141     public void setProcessList( Vector<Process> processList ) {
142         _processList = processList;
143     }
144
145     /**
146      * Get the a list of processors in this Mapping.
147      *
148      * @return the processor list
149      */
150     public Vector<Processor> getProcessorList() {
151         return _processorList;
152     }
153
154     /**
155      * Set the processor list of this mapping.
156      *
157      * @param processorList The new list
158      */
159     public void setProcessorList( Vector<Processor> processorList ) {
160         _processorList = processorList;
161     }
162     
163     /**
164      * Return a processor which has a specific name. Return null if
165      * processor cannot be found.
166      *
167      * @param name the name of the processor to search for.
168      * @return the processor with the specific name or null if not found.
169      */    
170     public Processor getProcessor(String name)
171     {
172         Iterator<Processor> i;
173         i = _processorList.iterator();
174         while (i.hasNext()) {
175             Processor processor = i.next();
176             if (processor.getName().equals(name)) {
177                 return processor;
178             }
179         }
180         return null;
181     }
182
183     /**
184      * Get the a list of schedules in this Mapping.
185      *
186      * @return the schedule list
187      */
188     public Vector<Schedule> getScheduleList() {
189         return _scheduleList;
190     }
191
192     /**
193      * Set the schedule list of this mapping.
194      *
195      * @param scheduleList The new list
196      */
197     public void setScheduleList( Vector<Schedule> scheduleList ) {
198         _scheduleList = scheduleList;
199     }
200     
201     /**
202      * Return the schedule for a resource that has a specific name. 
203      * Return null if schedule cannot be found.
204      *
205      * @param  name the name of the resource for which we are looking for the schedule.
206      * @return the schedule for the resource with the specified name.
207      */
208     public Schedule getScheduleByResource(String name) {
209         for(Schedule schedule : _scheduleList) {
210             if (schedule.getResource().getName().equals(name)) {
211                 return schedule;
212             }
213         }
214         return null;
215     }
216     
217     /**
218      * Return the communication binding for a channel that has a specific name. 
219      * Return null if binding cannot be found.
220      *
221      * @param  name the name of the channel for which we are looking for the binding.
222      * @return the binding for the channel with the specified name.
223      */
224     public CommunicationBinding getCommBindingByChannel(String name) {
225         for(CommunicationBinding b : _commBindList) {
226             if (b.getChannel().getName().equals(name)) {
227                 return b;
228             }
229         }
230         return null;
231     }
232     
233     /**
234      * Get the variable list of a Mapping.
235      *
236      * @return the variable list
237      */
238     public Vector<Variable> getVarList() {
239         return _variableList;
240     }
241
242     /**
243      * Set the variable list of a mapping.
244      *
245      * @param variableList The new list
246      */
247     public void setVarList( Vector<Variable> variableList ) {
248         _variableList = variableList;
249     }
250   
251     /** ProcessNetwork Reference **/
252     protected ProcessNetwork _pn = null;
253     
254     /** Architecture Reference **/
255     protected Architecture _arch = null;
256
257     /** List of processes in the mapping **/
258     protected Vector<Process> _processList = null;
259     
260     /** List of processors actually used in the mapping **/
261     protected Vector<Processor> _processorList = null;
262     
263     /** List of computations bindings in the mapping **/
264     protected Vector<ComputationBinding> _compBindList = null;
265     
266     /** List of communication bindings in the mapping **/
267     protected Vector<CommunicationBinding> _commBindList = null;
268     
269     /** List of schedules in the mapping **/
270     protected Vector<Schedule> _scheduleList = null;
271     
272     /** List of variables in the mapping **/
273     protected Vector<Variable> _variableList = null;
274 }