Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Adding new functionalities.
[mapping.git] / src / and / Mapping / Maheve.java
index a8f0472..f38b9fc 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." ) ;
                        }
                }
                
@@ -303,7 +374,12 @@ public class Maheve extends Algo
                        
                        ArrayList<Double> calcMark = new ArrayList<Double>() ;
                        
-                       hd = gl.getHeterogenityDegre() ;
+                       double hd_g = gl.getHeterogenityDegre() ;
+                       
+                       /* Correction of hd */
+                       hd =  calcNewHd( hd_g ) ; 
+                       
+                       System.out.println("Corrected hd value: " + hd + " (" + hd_g + ")" ) ;
 
                        /** Sorting clusters **/
                        ArrayList<Cluster> tmp = gl.getClusters() ;
@@ -328,8 +404,8 @@ public class Maheve extends Algo
                                normP = tmp.get( i ).getAvgAvailablePower() * 100 / Pm ;
                                
                                /** The magic formula :P **/
-                               calcLoc = Math.sqrt( Math.pow( (normP * hd), 2) +
-                                                 Math.pow( (normN *(1 - hd)), 2 ) ) ;
+                               calcLoc = Math.pow( (normP * hd), 2) +
+                                                 Math.pow( (normN * (1 - hd)), 2 ) ;
                                
                                ok = false ;
                                
@@ -361,6 +437,28 @@ public class Maheve extends Algo
        }
 
 
+       /**
+        * Compute the new value of hd, by taking care of the application
+        * and execution architecture characteristics.
+        * @param hd_g Original heterogeneity degree
+        * @return The new (corrected) heterogeneity degree
+        */
+       private double calcNewHd( double hd_g ) 
+       {
+               /* Variables */
+               double nhd = 0 ;
+
+               double nbTask = gr.getNbGTask() ;
+               double nbDep = gr.getMaxDep() ;
+               double maxNodes = gl.getMaxClusterNode() ;
+               
+               /* Computation */
+               nhd = hd_g / ( 10 * ( (nbDep / nbTask) + (nbDep / maxNodes) ) ) ;
+               
+               return nhd ;
+       }
+
+
        @Override
        public GNode replaceNode( GNode _dead, ArrayList<GNode> _ag ) 
        {
@@ -435,6 +533,12 @@ public class Maheve extends Algo
                
                return ret ;
        }
+
+
+       @Override
+       public boolean setParams(Object[] _params) {
+               return true ;
+       }
        
 }