From: Sébastien Miquée Date: Mon, 3 Jan 2011 15:37:22 +0000 (+0100) Subject: Improvement of the Maheve algorithm. X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/mapping.git/commitdiff_plain/d5231d68ea145eedd724eb55d1fa56a1c5a7c660 Improvement of the Maheve algorithm. Improvement by adding the possibility to change the parameters "nbSave" and "minNode" to adjust the mapping process. Also a correction in the mapping process, especially in the nodes search, to avoid an error when using clusters with few nodes; with an amount of nodes near the "minNode" limit. --- diff --git a/src/and/Mapping/Maheve.java b/src/and/Mapping/Maheve.java index a8f0472..c22bfc9 100644 --- a/src/and/Mapping/Maheve.java +++ b/src/and/Mapping/Maheve.java @@ -8,8 +8,8 @@ public class Maheve extends Algo { private static final long serialVersionUID = 1L; - private static final int minNode = 5 ; - private static final int nbSave = 2 ; + private static int minNode ; + private static int nbSave ; private double hd ; private ArrayList sortedCluster = null ; @@ -23,6 +23,8 @@ public class Maheve extends Algo { super() ; name = "MAHEVE_2" ; + minNode = 5 ; + nbSave = 2 ; sortedCluster = new ArrayList() ; } @@ -46,6 +48,57 @@ public class Maheve extends Algo } + /** + * Setter for the amount of nodes to preserve on each cluster + * for the fault tolerance (should be 0 in an environment without fault). + * @param _nbSave The amount of nodes to preserve + */ + public void setNbSave( int _nbSave ) + { + if( _nbSave >= 0 ) + { + nbSave = _nbSave ; + } + } + + + /** + * Getter to retrieving the amount of nodes preserved for fault tolerance. + * @return The amount of preserved nodes + */ + public int getNbSave() + { + return nbSave ; + } + + + /** + * Setter for the minimum amount of nodes which should be present in + * a cluster to consider this latter in the mapping process. + * @param _minNode The minimum amount of nodes a cluster should have to be + * considered + */ + public void setMinNode( int _minNode ) + { + if( _minNode >= 0 ) + { + minNode = _minNode ; + } + } + + + /** + * Getter to retrieve the minimum amount of nodes a cluster should have + * to be considered in the mapping process. + * @return The minimum amount of nodes a cluster should have to be + * considered + */ + public int getMinNode() + { + return minNode ; + } + + @Override public void map() { /** If the mapping is possible ... **/ @@ -257,31 +310,49 @@ public class Maheve extends Algo int nbFound = 0 ; int max = 0 ; GNode g = null ; + boolean changeParameter = false ; - for( int i = 0 ; i < sortedCluster.size() ; i++ ) + while( nbFound < _nbTask ) { - /** If there is enough nodes ... **/ - if( sortedCluster.get( i ).getNbFreeNodes() >= minNode ) + int i = 0 ; + + for( i = 0 ; i < sortedCluster.size() ; i++ ) { - max = 0 ; - sortedCluster.get( i ).initMoreGNode() ; + /** If there is enough nodes ... **/ + if( sortedCluster.get( i ).getNbFreeNodes() >= minNode ) + { + max = 0 ; + sortedCluster.get( i ).initMoreGNode() ; - max = sortedCluster.get( i ).getNbFreeNodes() - nbSave ; + max = sortedCluster.get( i ).getNbFreeNodes() - nbSave ; - for( int j = 0 ; j < max ; j++ ) - { - g = sortedCluster.get( i ).moreGNode() ; - ret.add( g ) ; + for( int j = 0 ; j < max ; j++ ) + { + g = sortedCluster.get( i ).moreGNode() ; + ret.add( g ) ; - nbFound ++ ; + nbFound ++ ; - if( nbFound >= _nbTask ) - break ; + if( nbFound >= _nbTask ) + break ; + } } + + if( nbFound >= _nbTask ) + break ; } - if( nbFound >= _nbTask ) - break ; + if( i == sortedCluster.size() && nbFound < _nbTask ) + { + changeParameter = true ; + minNode-- ; + } + } + + if( changeParameter ) + { + System.err.println( "The parameter \"minNode\" has been reduced " + + "to allow the mapping process to be done." ) ; } }