3 import java.io.Serializable;
4 import java.util.ArrayList;
8 * Class representing the tasks mapping on clusters and/or nodes
9 * @author Sébastien Miquée
12 public class Mapping implements Serializable
14 private static final long serialVersionUID = 1L;
16 /* Two kinds of Mapping, according to algorithms' goal */
17 private ArrayList<Association> mapping ;
18 private ArrayList<Association> mapping2 ;
19 private int type ; // 0 : mapping task/node ; 1 : mapping tasks/cluster
27 mapping = new ArrayList<Association>() ;
28 mapping2 = new ArrayList<Association>() ;
34 * Initialization of the Mapping variables
36 public void initMapping()
38 mapping = new ArrayList<Association>() ;
39 mapping2 = new ArrayList<Association>() ;
45 * Add in the mapping an association between a cluster and tasks set.
46 * @param c Cluster of the association
47 * @param at Tasks set to be associated
49 public void addMapping( Cluster c, ArrayList<GTask> at )
51 mapping2.add( new Association( c, at ) ) ;
53 if( type == 1 || type == -1 )
57 System.err.println( "Mapping type mismatch !" ) ;
61 /** For the usage of algorithms which map groups of tasks on cluster **/
62 for( int i = 0 ; i < at.size() ; i++ )
64 insertMapping( new Association( c.nextGNode(), at.get( i ) ) ) ;
70 * Add a mapping association in the general mapping.
71 * @param _a Association between a task and a node
73 public void addMapping( Association _a )
75 if( type == 0 || type == -1 )
79 System.err.println( "Mapping type mismatch !" ) ;
88 * Insert the association at the right place.
89 * @param _a The association to be inserted
91 public void insertMapping( Association _a )
93 if( _a != null && _a.getGNode() != null && _a.getGTask() != null )
95 int ind = _a.getGTask().getNum() ;
97 mapping.add( ind - 1, _a ) ;
103 * Remove a failed node from the mapping.
104 * @param _deadNode The failed node
105 * @return The task associated with the failed node
107 public GTask removeGNode( GNode _deadNode )
111 for( int i = 0 ; i < mapping.size() ; i++ )
113 if( mapping.get( i ).getGNode().getId() == _deadNode.getId() )
115 gt = mapping.get( i ).getGTask() ;
116 mapping.remove( i ) ;
126 * Return the list of GNodes on which tasks are mapped, in order
127 * of the task number.
128 * @return The ordered list, according to the GTasks id, of GNodes involved in the mapping
130 public ArrayList<GNode> getMappedGNodes()
132 ArrayList<GNode> ar = new ArrayList<GNode>() ;
134 if( mapping.size() != 0 )
138 // ArrayList<Association> tmp = (ArrayList<Association>) mapping.clone() ;
140 for( int i = 0 ; i < mapping.size() ; i++ )
142 // for( int j = 0 ; j < tmp.size() ; j++ )
144 // if( tmp.get( j ).getGTask().getNum() == i )
146 ar.add( mapping.get( i ).getGNode() ) ;
148 // j = tmp.size() + 2 ;
156 // ArrayList<Association> tmp = (ArrayList<Association>) mapping2.clone() ;
158 // for( int i = 0 ; i < mapping2.size() ; i++ )
160 // for( int j = 0 ; j < tmp.size() ; j++ )
162 // if( tmp.get( j ).getGTask().getNum() == i )
164 // ar.add( tmp.get( j ).getGNode() ) ;
166 // j = tmp.size() + 2 ;
178 * Print the status of the mapping done, according to its type.
182 System.out.println();
183 System.out.println( "\t=> Mapping done :\n" ) ;
187 ArrayList<GNode> ar = getMappedGNodes() ;
189 for( int i = 0 ; i < ar.size() ; i++ )
191 System.out.println( "Task " + i + " on " + ar.get( i ).getName() ) ;
194 System.out.println() ;
199 for( int i = 0 ; i < mapping2.size() ; i++ )
201 System.out.print( "\t\tCluster \"" + mapping2.get( i ).getCluster().getName() + "\" => { ") ;
202 for( int j = 0 ; j < mapping2.get( i ).getGtask().size() ; j++ )
204 System.out.print( mapping2.get( i ).getGtask().get( j ).getNum() ) ;
206 if( j != mapping2.get( i ).getGtask().size() - 1 )
208 System.out.print( ", " ) ;
211 System.out.println( " } " ) ;
212 System.out.println() ;
219 * Return the mapping done.
220 * @return The mapping
222 public ArrayList<Association> getMapping()
229 * Return the amount of external tasks dependencies, in cluster point of view.
230 * @return The amount of external dependencies
232 public int calcDepExt()
235 ArrayList<GTask> ar ;
236 ArrayList<GTask> deps ;
238 for( int i = 0 ; i < mapping.size() ; i++ )
240 ar = mapping.get(i).getGtask() ;
242 for( int j = 0 ; j < ar.size() ; j++ )
244 deps = ar.get(j).getDependencies() ;
246 for( int k = 0 ; k < deps.size() ; k++ )
248 if( ! ar.contains( deps.get(k) ) )
256 return ( depExt / 2 ) ;
261 /** La programmation est un art, respectons ceux qui la pratiquent !! **/