Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Correction of bugs and new functionalities.
[mapping.git] / src / and / Mapping / Grid.java
index eb3fb4f..0370940 100644 (file)
@@ -15,8 +15,8 @@ public class Grid implements Serializable
        private static final long serialVersionUID = 1L;
 
        
-       private int nb_cluster ;
-       private int nb_node ;
+//     private int nb_cluster ;
+//     private int nb_node ;
        private ArrayList<Cluster> clusters ;
        private ArrayList<GNode> gnodesList;
        private boolean gnodesList_done;
@@ -27,8 +27,8 @@ public class Grid implements Serializable
         */
        public Grid()
        {
-               nb_cluster = 0 ;
-               nb_node = 0 ;
+//             nb_cluster = 0 ;
+//             nb_node = 0 ;
                clusters = new ArrayList<Cluster>() ;
                gnodesList = new ArrayList<GNode>() ;
                gnodesList_done = false ;
@@ -44,8 +44,13 @@ public class Grid implements Serializable
                if( c != null )
                {
                        clusters.add( c ) ;
-                       nb_cluster ++ ;
-                       nb_node += c.getNbGNode() ;
+                       
+                       for( int i = 0 ; i < c.getNbGNode() ; i++ )
+                       {
+                               gnodesList.add( c.getGNodes().get( i ) ) ;
+                       }
+//                     nb_cluster++ ;
+//                     nb_node += c.getNbGNode() ;
                }
        }
        
@@ -63,9 +68,9 @@ public class Grid implements Serializable
                        for( int i = 0 ; i < al.size() ; i++ )
                        {
                                clusters.add( al.get( i ) ) ;
-                               nb_cluster ++ ;
+//                             nb_cluster++ ;
                                nbCLusterNodes = al.get( i ).getNbGNode() ;
-                               nb_node += nbCLusterNodes ;
+//                             nb_node += nbCLusterNodes ;
                                
                                for( int j = 0 ; j < nbCLusterNodes ; j++ )
                                {
@@ -82,7 +87,8 @@ public class Grid implements Serializable
         */
        public int getNbCluster()
        {
-               return nb_cluster ;
+               return clusters.size() ;
+//             return nb_cluster ;
        }
        
        
@@ -92,7 +98,8 @@ public class Grid implements Serializable
         */
        public int getNbGNode()
        {
-               return nb_node ;
+               return gnodesList.size() ;
+//             return nb_node ;
        }
        
        
@@ -106,16 +113,16 @@ public class Grid implements Serializable
        }
        
        
-       /**
-        * Initialization of clusters.
-        */
-       public void initClusters()
-       {
-               for( int i = 0 ; i < nb_cluster ; i++ )
-               {
-                       clusters.get( i ).initIndice() ;
-               }
-       }
+//     /**
+//      * Initialization of clusters.
+//      */
+//     public void initClusters()
+//     {
+//             for( int i = 0 ; i < nb_cluster ; i++ )
+//             {
+//                     clusters.get( i ).initIndice() ;
+//             }
+//     }
        
        
        /**
@@ -137,13 +144,13 @@ public class Grid implements Serializable
                
                for( int i = 0 ; i < clusters.size() ; i++ )
                {
-                       if( clusters.get( i ).isIn( _g1) )
+                       if( clusters.get( i ).isIn( _g1 ) != -1 )
                        {
                                cluster1 = clusters.get( i ).getName() ;
                                site1 = clusters.get( i ).getSite() ;
                        }
                        
-                       if( clusters.get( i ).isIn( _g2) )
+                       if( clusters.get( i ).isIn( _g2 ) != -1 )
                        {
                                cluster2 = clusters.get( i ).getName() ;
                                site2 = clusters.get( i ).getSite() ;
@@ -211,7 +218,9 @@ public class Grid implements Serializable
                                {
                                        if( _gnodes.get( i ).getCluster().equalsIgnoreCase( clusters.get( j ).getName() ) )
                                        {
-                                               if( ! clusters.get( j ).isIn( _gnodes.get( i ) ) )
+                                               int pos = clusters.get( j ).isIn( _gnodes.get( i ) ) ;
+                                               
+                                               if( pos == -1 )
                                                {
                                                        _gnodes.get( i ).setCluster( clusters.get( j ).getName() ) ;
                                                        _gnodes.get( i ).setSite( clusters.get( j ).getSite() ) ;
@@ -219,8 +228,11 @@ public class Grid implements Serializable
                                                        _gnodes.get( i ).setMapped( false ) ;
                                                
                                                        clusters.get( i ).addGNode( _gnodes.get( j ) ) ;
-                                                       nb_node++ ;
+//                                                     nb_node++ ;
                                                        gnodesList.add( _gnodes.get( i ) ) ;
+                                                       
+                                               } else {
+                                                       clusters.get( j ).setGNodeStatus( _gnodes.get( i ), _gnodes.get( i ).getMapped() ) ;
                                                }
                                                
                                                break ;
@@ -248,10 +260,10 @@ public class Grid implements Serializable
                                        _gnodes.get( i ).setCluster( cluster ) ;
                                        
                                        nClust.addGNode( _gnodes.get( i ) ) ;
-                                       nb_cluster++ ;
+//                                     nb_cluster++ ;
                                        
                                        clusters.add( nClust ) ;
-                                       nb_node++ ;
+//                                     nb_node++ ;
                                        gnodesList.add( _gnodes.get( i ) ) ;
                                }
                        }
@@ -289,7 +301,7 @@ public class Grid implements Serializable
                        }
                        
                        /** Removing the dead node from the global list **/
-                       for( int i = 0 ; i < nb_node ; i++ )
+                       for( int i = 0 ; i < gnodesList.size() ; i++ )
                        {
                                if( _dead.getId() == gnodesList.get( i ).getId() )
                                {
@@ -299,11 +311,55 @@ public class Grid implements Serializable
                        }
                }
                
-               nb_node-- ;
+//             nb_node-- ;
                gnodesList_done = false ;
        }
        
        
+       /**
+        * Change the mapping status of a node in the grid and in its cluster.
+        * @param _g The node to change the mapping status
+        * @param _status The node's mapping status
+        */
+       public void setMappedStatus( GNode _g, boolean _status )
+       {
+               if( _g != null )
+               {
+                       getClusterOfNode( _g ).setGNodeStatus( _g, _status ) ;
+                       
+                       for( int i = 0 ; i < gnodesList.size() ; i++ )
+                       {
+                               if( _g.getId() == gnodesList.get( i ).getId() )
+                               {
+                                       gnodesList.get( i ).setMapped( _status ) ;
+                                       break ;
+                               }
+                       }
+               }
+       }
+       
+       
+       /**
+        * Search and return the cluster containing the specified node.
+        * @param _g A node
+        * @return The cluster containing the node
+        */
+       public Cluster getClusterOfNode( GNode _g )
+       {
+               if( _g != null )
+               {
+                       for( int i = 0 ; i < clusters.size() ; i++ )
+                       {
+                               if( _g.getCluster().equalsIgnoreCase( clusters.get( i ).getName() ) ) 
+                               {
+                                       return clusters.get( i ) ;
+                               }
+                       }
+               }
+               
+               return null ;
+       }
+       
        /**
         * Compute the heterogeneity degree of the grid.
         * This is based on the relative standard deviation.
@@ -311,7 +367,7 @@ public class Grid implements Serializable
         */
        public double getHeterogenityDegre()
        {
-               if( nb_node != gnodesList.size() )
+               if( ! ( gnodesList.size() > 0 ) )
                {
                        System.err.println( "Mapping - Heterogeneity degree computation! " +
                                        "List's size not corresponding!" ) ;
@@ -325,22 +381,22 @@ public class Grid implements Serializable
                double temp = 0 ;
                
                /** Computation of the average power of computing nodes **/
-               for( int i = 0 ; i < nb_node ; i++ )
+               for( int i = 0 ; i < gnodesList.size() ; i++ )
                {
                        temp += gnodesList.get(i).getPower() ;
                }
                
-               average = temp / nb_node ;
+               average = temp / gnodesList.size() ;
                
                /** Computation of the variance **/
                temp = 0 ;
-               for( int i = 0 ; i < nb_node ; i++ )
+               for( int i = 0 ; i < gnodesList.size() ; i++ )
                {
                        temp += Math.pow( ( gnodesList.get(i).getPower() - average ), 2 ) ;
                }
                
                /** Computation of the standard deviation **/
-               temp = temp / nb_node ;
+               temp = temp / gnodesList.size() ;
                std = Math.sqrt( temp ) ;
                
                /** Computation of the relative standard deviation
@@ -359,8 +415,8 @@ public class Grid implements Serializable
        public void print()
        {
                System.out.println();
-               System.out.println( "\t=> Grid composition :\n" ) ; 
-               for( int i = 0 ; i < nb_cluster ; i++ )
+               System.out.println( "\t=> Grid composition:\n" ) ; 
+               for( int i = 0 ; i < clusters.size() ; i++ )
                {
                        System.out.println( "\t\tCluster \""+ clusters.get(i).getName() +"\" : " + clusters.get(i).getNbGNode() ) ;
                }