/* Two kinds of Mapping, according to algorithms' goal */
private ArrayList<Association> mapping ;
private ArrayList<Association> mapping2 ;
+ private ArrayList<GNode> other ;
private int type ; // 0 : mapping task/node ; 1 : mapping tasks/cluster
{
mapping = new ArrayList<Association>() ;
mapping2 = new ArrayList<Association>() ;
+ other = new ArrayList<GNode>() ;
type = -1 ;
}
{
mapping = new ArrayList<Association>() ;
mapping2 = new ArrayList<Association>() ;
+ other = new ArrayList<GNode>() ;
type = -1 ;
}
GNode tmp = null ;
for( int i = 0 ; i < at.size() ; i++ )
{
- tmp = c.nextGNode() ;
+ tmp = c.moreGNode() ;
if( tmp != null )
{
insertMapping( new Association( tmp, at.get( i ) ) ) ;
{
if( _a != null && _a.getGNode() != null && _a.getGTask() != null )
{
-// int ind = _a.getGTask().getNum() ;
-//
-// mapping.add( ind - 1, _a ) ;
mapping.add( _a ) ;
}
}
+ /**
+ * Determine if a node is used as an other node in the mapping.
+ * @param _g The node to search
+ * @return The position of the node
+ */
+ private int searchOther( GNode _g )
+ {
+ int pos = -1 ;
+
+ if( _g != null )
+ {
+ for( int i = 0 ; i < other.size() ; i++ )
+ {
+ if( _g.getId() == other.get( i ).getId() )
+ {
+ pos = i ;
+ break ;
+ }
+ }
+ }
+
+ return pos ;
+ }
+
+
+ /**
+ * Add a new node in the other nodes list.
+ * @param _g The other node
+ */
+ public void addOtherNode( GNode _g )
+ {
+ if( _g != null )
+ {
+ int pos = searchOther( _g ) ;
+
+ if( pos != -1 )
+ {
+ other.add( _g ) ;
+ } else {
+ System.out.println( "This node already exist in OtherNodes! " +
+ "I replace it" ) ;
+ other.set( pos, _g ) ;
+ }
+ }
+ }
+
+
+ /**
+ * Remove a node in the other nodes list.
+ * @param _g The node to be removed
+ */
+ public void removeOtherNode( GNode _g )
+ {
+ if( _g != null )
+ {
+ int pos = searchOther( _g ) ;
+
+ if( pos != -1 )
+ {
+ other.remove( pos ) ;
+ } else {
+ System.err.println( "This node does not exist in OtherNodes!" ) ;
+ }
+ }
+ }
+
+
/**
* Remove a failed node from the mapping.
* @param _deadNode The failed node
public ArrayList<GNode> getMappedGNodes()
{
ArrayList<GNode> ar = new ArrayList<GNode>() ;
-
+
if( mapping.size() != 0 )
{
-// if( type == 0 )
-// {
-// ArrayList<Association> tmp = (ArrayList<Association>) mapping.clone() ;
-
- for( int i = 0 ; i < mapping.size() ; i++ )
- {
-// for( int j = 0 ; j < tmp.size() ; j++ )
-// {
-// if( tmp.get( j ).getGTask().getNum() == i )
-// {
- ar.add( mapping.get( i ).getGNode() ) ;
-// tmp.remove( j ) ;
-// j = tmp.size() + 2 ;
-// }
-// }
- }
-// }
-//
-// if( type == 1 )
-// {
-// ArrayList<Association> tmp = (ArrayList<Association>) mapping2.clone() ;
-//
-// for( int i = 0 ; i < mapping2.size() ; i++ )
-// {
-// for( int j = 0 ; j < tmp.size() ; j++ )
-// {
-// if( tmp.get( j ).getGTask().getNum() == i )
-// {
-// ar.add( tmp.get( j ).getGNode() ) ;
-// tmp.remove( j ) ;
-// j = tmp.size() + 2 ;
-// }
-// }
-// }
-// }
+ for( int i = 0 ; i < mapping.size() ; i++ )
+ {
+ ar.add( mapping.get( i ).getGNode() ) ;
+ }
}
-
+
return ar ;
}
-
+
/**
* Print the status of the mapping done, according to its type.
*/
- public void print()
+ public void print( int _type )
{
+ int type_print = _type ;
+
System.out.println();
System.out.println( "\t=> Mapping done:\n" ) ;
- if( type == 0 )
+ if( type_print == 0 )
{
ArrayList<GNode> ar = getMappedGNodes() ;
System.out.println() ;
}
- if( type == 1 )
+ if( type_print == 1 )
{
for( int i = 0 ; i < mapping2.size() ; i++ )
{
}
+ /**
+ * Return the association of the given position.
+ * @param _id The position of the Association
+ * @return The Association requested
+ */
+ public Association getAssociation( int _id )
+ {
+ if( _id >= 0 && _id < mapping.size() )
+ {
+ return mapping.get( _id ) ;
+ } else {
+ return null ;
+ }
+ }
+
+
+ /**
+ * Remove the association of the given position.
+ * @param _id The position of the Association
+ * @return The Association removed
+ */
+ public Association removeAssociation( int _id )
+ {
+ if( _id >= 0 && _id < mapping.size() )
+ {
+ return mapping.remove( _id ) ;
+ } else {
+ return null ;
+ }
+ }
+
+ /**
+ * Return the position of the association containing
+ * the GTask of a specified rank.
+ * @param _taskRank The rank of the task
+ * @return The position of the association
+ */
+ public int getIdOfAssociation( int _taskRank )
+ {
+ int ret = -1 ;
+
+ for( int i = 0 ; i < mapping.size() ; i++ )
+ {
+ if( mapping.get( i ).getGTask().getNum() == _taskRank )
+ {
+ ret = i ;
+ break ;
+ }
+ }
+
+ return ret ;
+ }
+
/**
* Return the amount of external tasks dependencies, in cluster point of view.
* @return The amount of external dependencies