4 import java.io.Serializable;
5 import java.util.ArrayList;
10 * Class representing a computing grid, composed of multiple clusters
11 * @author Sébastien Miquée
13 public class Grid implements Serializable
15 private static final long serialVersionUID = 1L;
18 private int nb_cluster ;
20 private ArrayList<Cluster> clusters ;
21 private ArrayList<GNode> gnodesList;
22 private boolean gnodesList_done;
32 clusters = new ArrayList<Cluster>() ;
34 gnodesList_done = false ;
39 * Add a cluster in the grid.
40 * @param c Cluster to be add
42 public void addCluster( Cluster c )
48 nb_node += c.getNbGNode() ;
54 * Add a clusters list in the grid.
55 * @param al List of clusters to be add
57 public void addClusters( ArrayList<Cluster> al )
61 for( int i = 0 ; i < al.size() ; i++ )
63 clusters.add( al.get( i ) ) ;
65 nb_node += al.get( i ).getNbGNode() ;
72 * Return the amount of clusters in the grid.
73 * @return The amount of clusters
75 public int getNbCluster()
82 * Return the amount of computing nodes in the grid.
83 * @return The amount of computing nodes
85 public int getNbGNode()
92 * Return the grid in a clusters list view.
93 * @return Clusters list
95 public ArrayList<Cluster> getClusters()
102 * Initialization of clusters.
104 public void initClusters()
106 for( int i = 0 ; i < nb_cluster ; i++ )
108 clusters.get( i ).initIndice() ;
114 * Compute and return the distance between two clusters.
115 * @param _g1 First cluster
116 * @param _g2 Second cluster
117 * @return The distance between the two clusters
119 public double getDistance( GNode _g1, GNode _g2 )
123 if( _g1.equals( _g2 ) )
128 String cluster1 = "c1", cluster2 = "c2", site1 = "s1", site2 = "s2" ;
130 for( int i = 0 ; i < clusters.size() ; i++ )
132 if( clusters.get( i ).isIn( _g1) )
134 cluster1 = clusters.get( i ).getName() ;
135 site1 = clusters.get( i ).getSite() ;
138 if( clusters.get( i ).isIn( _g2) )
140 cluster2 = clusters.get( i ).getName() ;
141 site2 = clusters.get( i ).getSite() ;
147 if( cluster1.compareTo( cluster2 ) == 0 )
151 if( site1.compareTo( site2 ) == 0 )
164 * Return the list of computing nodes in the grid.
165 * @return The list of computing nodes
167 public ArrayList<GNode> getGNodes()
169 if( ! gnodesList_done )
171 gnodesList = new ArrayList<GNode>() ;
173 for( int i = 0 ; i < clusters.size() ; i++ )
175 ArrayList<GNode> ar = clusters.get( i ).getGNodes() ;
177 for( int j = 0 ; j < ar.size() ; j++ )
179 gnodesList.add( ar.get( j ) ) ;
183 gnodesList_done = true ;
194 public void updateGrid( ArrayList<GNode> _gnodes )
196 if( _gnodes != null && _gnodes.size() != 0 )
198 for( int i = 0 ; i < _gnodes.size() ; i++ )
203 gnodesList_done = false ;
209 * Remove a computing node from the grid.
210 * @param _dead The node to be removed
212 public void removeGNode( GNode _dead )
216 if( _dead.getMapped() )
218 String site = "", cluster = "" ;
220 site = _dead.getSite() ;
221 cluster = _dead.getCluster() ;
223 /* Removing GNode from its cluster */
224 for( int j = 0 ; j < clusters.size() ; j++ )
226 if( clusters.get( j ).getName().equals( cluster ) && clusters.get( j ).getSite().equals( site ))
228 clusters.get( j ).removeGNode( _dead ) ;
235 /* Removing the dead node from the global list */
236 for( int i = 0 ; i < nb_node ; i++ )
238 if( _dead.getId() == gnodesList.get( i ).getId() )
240 gnodesList.remove( i ) ;
247 gnodesList_done = false ;
252 * Compute the heterogeneity degree of the grid.
253 * This is based on a ratio between the average and the
254 * standard deviation of computing nodes' power.
255 * @return The heterogeneity degree of the grid
257 public double getHeterogenityDegre()
267 * Print a comprehensible text version of the grid.
271 System.out.println();
272 System.out.println( "\t=> Grid composition :\n" ) ;
273 for( int i = 0 ; i < nb_cluster ; i++ )
275 System.out.println( "\t\tCluster \""+ clusters.get(i).getName() +"\" : " + clusters.get(i).getNbGNode() ) ;
278 System.out.println();
284 /** La programmation est un art, respectons ceux qui la pratiquent !! **/