X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/mapping.git/blobdiff_plain/1dec4110ab1efff39af4617c38a52199d443e6db..04237b062ba76603c6be49d9ba84121691aa4009:/src/and/Mapping/Mapping.java diff --git a/src/and/Mapping/Mapping.java b/src/and/Mapping/Mapping.java index 1136d55..e8320c4 100644 --- a/src/and/Mapping/Mapping.java +++ b/src/and/Mapping/Mapping.java @@ -16,6 +16,7 @@ public class Mapping implements Serializable /* Two kinds of Mapping, according to algorithms' goal */ private ArrayList mapping ; private ArrayList mapping2 ; + private ArrayList other ; private int type ; // 0 : mapping task/node ; 1 : mapping tasks/cluster @@ -26,6 +27,7 @@ public class Mapping implements Serializable { mapping = new ArrayList() ; mapping2 = new ArrayList() ; + other = new ArrayList() ; type = -1 ; } @@ -37,6 +39,7 @@ public class Mapping implements Serializable { mapping = new ArrayList() ; mapping2 = new ArrayList() ; + other = new ArrayList() ; type = -1 ; } @@ -59,9 +62,17 @@ public class Mapping implements Serializable } /** For the usage of algorithms which map groups of tasks on cluster **/ + GNode tmp = null ; for( int i = 0 ; i < at.size() ; i++ ) { - insertMapping( new Association( c.nextGNode(), at.get( i ) ) ) ; + tmp = c.moreGNode() ; + if( tmp != null ) + { + insertMapping( new Association( tmp, at.get( i ) ) ) ; + } else { + System.err.println( "Error during reception of the next GNode !" ) ; + break ; + } } } @@ -92,14 +103,78 @@ public class Mapping implements Serializable { 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 @@ -131,59 +206,30 @@ public class Mapping implements Serializable public ArrayList getMappedGNodes() { ArrayList ar = new ArrayList() ; - + if( mapping.size() != 0 ) { -// if( type == 0 ) -// { -// ArrayList tmp = (ArrayList) 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 tmp = (ArrayList) 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" ) ; + System.out.println( "\t=> Mapping done:\n" ) ; - if( type == 0 ) + if( type_print == 0 ) { ArrayList ar = getMappedGNodes() ; @@ -195,7 +241,7 @@ public class Mapping implements Serializable System.out.println() ; } - if( type == 1 ) + if( type_print == 1 ) { for( int i = 0 ; i < mapping2.size() ; i++ ) { @@ -249,6 +295,59 @@ public class Mapping implements Serializable } + /** + * 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