Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Improvement of the Maheve algorithm.
authorSébastien Miquée <sebastien.miquee@univ-fcomte.fr>
Mon, 3 Jan 2011 15:37:22 +0000 (16:37 +0100)
committerSébastien Miquée <sebastien.miquee@univ-fcomte.fr>
Mon, 3 Jan 2011 16:01:15 +0000 (17:01 +0100)
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.

src/and/Mapping/Maheve.java

index a8f0472..c22bfc9 100644 (file)
@@ -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<Cluster> sortedCluster = null ;
@@ -23,6 +23,8 @@ public class Maheve extends Algo
        {
                super() ;
                name = "MAHEVE_2" ;
+               minNode = 5 ;
+               nbSave = 2 ;
                sortedCluster = new ArrayList<Cluster>() ;
        }
        
@@ -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." ) ;
                        }
                }