1 package dol.datamodel.mapping;
3 import java.util.Iterator;
4 import java.util.Vector;
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;
14 * This class defines a mapping.
16 public class Mapping extends MapResource
18 public Mapping(String name)
21 _compBindList = new Vector<ComputationBinding>();
22 _commBindList = new Vector<CommunicationBinding>();
23 _scheduleList = new Vector<Schedule>();
24 _variableList = new Vector<Variable>();
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.
32 _processList = new Vector<Process>();
33 _processorList = new Vector<Processor>();
39 * @param x visitor object
41 public void accept(MapVisitor x) {
42 x.visitComponent(this);
49 * @return new instance of the Mapping
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());
63 /** Get the process network. */
64 public ProcessNetwork getPN() { return _pn; }
66 /** Store a reference to the process network. */
67 public void setPN(ProcessNetwork pn) { _pn = pn; }
69 /** Get the architecture */
70 public Architecture getArch() { return _arch; }
72 /** Store a reference to the architecture. */
73 public void setArch(Architecture arch) { _arch = arch; }
76 * Get a list of computation bindings in this Mapping.
78 * @return the binding list
80 public Vector<ComputationBinding> getCompBindList() {
85 * Get a list of processes in this Mapping.
87 * @return the process list
89 public Vector<Process> getProcessList() {
94 * Return a process which has a specific name. Return null if
95 * process cannot be found.
97 * @param name the name of the process to search for.
98 * @return the process with the specific name or null if not found.
100 public Process getProcess(String name)
102 for (Process process : _processList) {
103 if (process.getName().equals(name)) {
110 * Set the computation binding list of this mapping.
112 * @param compBindList The new list
114 public void setCompBindList( Vector<ComputationBinding> compBindList ) {
115 _compBindList = compBindList;
119 * Get a list of communication bindings in this Mapping.
121 * @return the binding list
123 public Vector<CommunicationBinding> getCommBindList() {
124 return _commBindList;
128 * Set the communication binding list of this mapping.
130 * @param commBindList The new list
132 public void setCommBindList( Vector<CommunicationBinding> commBindList ) {
133 _commBindList = commBindList;
137 * Set the process list of this mapping.
139 * @param processList The new list
141 public void setProcessList( Vector<Process> processList ) {
142 _processList = processList;
146 * Get the a list of processors in this Mapping.
148 * @return the processor list
150 public Vector<Processor> getProcessorList() {
151 return _processorList;
155 * Set the processor list of this mapping.
157 * @param processorList The new list
159 public void setProcessorList( Vector<Processor> processorList ) {
160 _processorList = processorList;
164 * Return a processor which has a specific name. Return null if
165 * processor cannot be found.
167 * @param name the name of the processor to search for.
168 * @return the processor with the specific name or null if not found.
170 public Processor getProcessor(String name)
172 Iterator<Processor> i;
173 i = _processorList.iterator();
174 while (i.hasNext()) {
175 Processor processor = i.next();
176 if (processor.getName().equals(name)) {
184 * Get the a list of schedules in this Mapping.
186 * @return the schedule list
188 public Vector<Schedule> getScheduleList() {
189 return _scheduleList;
193 * Set the schedule list of this mapping.
195 * @param scheduleList The new list
197 public void setScheduleList( Vector<Schedule> scheduleList ) {
198 _scheduleList = scheduleList;
202 * Return the schedule for a resource that has a specific name.
203 * Return null if schedule cannot be found.
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.
208 public Schedule getScheduleByResource(String name) {
209 for(Schedule schedule : _scheduleList) {
210 if (schedule.getResource().getName().equals(name)) {
218 * Return the communication binding for a channel that has a specific name.
219 * Return null if binding cannot be found.
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.
224 public CommunicationBinding getCommBindingByChannel(String name) {
225 for(CommunicationBinding b : _commBindList) {
226 if (b.getChannel().getName().equals(name)) {
234 * Get the variable list of a Mapping.
236 * @return the variable list
238 public Vector<Variable> getVarList() {
239 return _variableList;
243 * Set the variable list of a mapping.
245 * @param variableList The new list
247 public void setVarList( Vector<Variable> variableList ) {
248 _variableList = variableList;
251 /** ProcessNetwork Reference **/
252 protected ProcessNetwork _pn = null;
254 /** Architecture Reference **/
255 protected Architecture _arch = null;
257 /** List of processes in the mapping **/
258 protected Vector<Process> _processList = null;
260 /** List of processors actually used in the mapping **/
261 protected Vector<Processor> _processorList = null;
263 /** List of computations bindings in the mapping **/
264 protected Vector<ComputationBinding> _compBindList = null;
266 /** List of communication bindings in the mapping **/
267 protected Vector<CommunicationBinding> _commBindList = null;
269 /** List of schedules in the mapping **/
270 protected Vector<Schedule> _scheduleList = null;
272 /** List of variables in the mapping **/
273 protected Vector<Variable> _variableList = null;