Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Many modifications in order to make a more efficient library for GNode creation
[mapping.git] / src / and / Mapping / Grid.java
index b9a6efa..16e46b1 100644 (file)
@@ -30,7 +30,7 @@ public class Grid implements Serializable
                nb_cluster = 0 ;
                nb_node = 0 ;
                clusters = new ArrayList<Cluster>() ;
-               gnodesList = null ;
+               gnodesList = new ArrayList<GNode>() ;
                gnodesList_done = false ;
        }
        
@@ -58,11 +58,19 @@ public class Grid implements Serializable
        {
                if( al != null )
                {
+                       int nbCLusterNodes = 0 ;
+                       
                        for( int i = 0 ; i < al.size() ; i++ )
                        {
                                clusters.add( al.get( i ) ) ;
                                nb_cluster ++ ;
-                               nb_node += al.get( i ).getNbGNode() ;
+                               nbCLusterNodes = al.get( i ).getNbGNode() ;
+                               nb_node += nbCLusterNodes ;
+                               
+                               for( int j = 0 ; j < nbCLusterNodes ; j++ )
+                               {
+                                       gnodesList.add( al.get( i ).getGNodes().get( j ) ) ;
+                               }
                        }
                }
        }
@@ -250,14 +258,48 @@ public class Grid implements Serializable
        
        /**
         * Compute the heterogeneity degree of the grid.
-        * This is based on a ratio between the average and the 
-        * standard deviation of computing nodes' power.
+        * This is based on the relative standard deviation.
         * @return The heterogeneity degree of the grid
         */
        public double getHeterogenityDegre()
        {
+               if( nb_node != gnodesList.size() )
+               {
+                       System.err.println( "Mapping - Heterogeneity degree computation! " +
+                                       "List's size not corresponding!" ) ;
+                       return -1 ;
+               }
+               
                double hd = -1 ;
                
+               double average = 0 ;
+               double std = 0 ;
+               double temp = 0 ;
+               
+               /** Computation of the average power of computing nodes **/
+               for( int i = 0 ; i < nb_node ; i++ )
+               {
+                       temp += gnodesList.get(i).getPower() ;
+               }
+               
+               average = temp / nb_node ;
+               
+               /** Computation of the variance **/
+               temp = 0 ;
+               for( int i = 0 ; i < nb_node ; i++ )
+               {
+                       temp += Math.pow( ( gnodesList.get(i).getPower() - average ), 2 ) ;
+               }
+               
+               /** Computation of the standard deviation **/
+               temp = temp / nb_node ;
+               std = Math.sqrt( temp ) ;
+               
+               /** Computation of the relative standard deviation
+                * plus modifications 
+                */
+               hd = 100 * std / average / 10 ;
+               
                
                return hd ;
        }