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;
*/
public Grid()
{
- nb_cluster = 0 ;
- nb_node = 0 ;
+// nb_cluster = 0 ;
+// nb_node = 0 ;
clusters = new ArrayList<Cluster>() ;
- gnodesList = null ;
+ gnodesList = new ArrayList<GNode>() ;
gnodesList_done = false ;
}
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() ;
}
}
{
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() ;
+// nb_cluster++ ;
+ nbCLusterNodes = al.get( i ).getNbGNode() ;
+// nb_node += nbCLusterNodes ;
+
+ for( int j = 0 ; j < nbCLusterNodes ; j++ )
+ {
+ gnodesList.add( al.get( i ).getGNodes().get( j ) ) ;
+ }
}
}
}
*/
public int getNbCluster()
{
- return nb_cluster ;
+ return clusters.size() ;
+// return nb_cluster ;
}
*/
public int getNbGNode()
{
- return nb_node ;
+ return gnodesList.size() ;
+// return nb_node ;
}
}
- /**
- * 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() ;
+// }
+// }
/**
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() ;
/**
- * Plop !!
- * @param _gnodes
+ * Upgrade the grid with new nodes.
+ * @param _gnodes The list of new nodes
*/
public void updateGrid( ArrayList<GNode> _gnodes )
{
{
for( int i = 0 ; i < _gnodes.size() ; i++ )
{
+ /** Searching the cluster in which the node should be added **/
+ int j = 0 ;
+ for( j = 0; j < clusters.size(); j++ )
+ {
+ if( _gnodes.get( i ).getCluster().equalsIgnoreCase( clusters.get( j ).getName() ) )
+ {
+ 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() ) ;
+ _gnodes.get( i ).setInCluster( true ) ;
+ _gnodes.get( i ).setMapped( false ) ;
+
+ clusters.get( i ).addGNode( _gnodes.get( j ) ) ;
+// nb_node++ ;
+ gnodesList.add( _gnodes.get( i ) ) ;
+
+ } else {
+ clusters.get( j ).setGNodeStatus( _gnodes.get( i ), _gnodes.get( i ).getMapped() ) ;
+ }
+
+ break ;
+ }
+ }
+ /** The cluster was not found, so it is a new one **/
+ if( j == clusters.size() )
+ {
+ String site = "", cluster = "" ;
+ Cluster nClust = new Cluster() ;
+
+
+ String names[] = Utils.decodeG5Knames( _gnodes.get( i ).getName() ) ;
+
+ cluster = names[ 1 ] ;
+ site = names[ 2 ] ;
+
+ nClust.setName( cluster ) ;
+ nClust.setSite( site ) ;
+
+ _gnodes.get( i ).setInCluster( true ) ;
+ _gnodes.get( i ).setMapped( false ) ;
+ _gnodes.get( i ).setSite( site ) ;
+ _gnodes.get( i ).setCluster( cluster ) ;
+
+ nClust.addGNode( _gnodes.get( i ) ) ;
+// nb_cluster++ ;
+
+ clusters.add( nClust ) ;
+// nb_node++ ;
+ gnodesList.add( _gnodes.get( i ) ) ;
+ }
}
gnodesList_done = false ;
site = _dead.getSite() ;
cluster = _dead.getCluster() ;
- /* Removing GNode from its cluster */
+ /** Removing GNode from its cluster **/
for( int j = 0 ; j < clusters.size() ; j++ )
{
if( clusters.get( j ).getName().equals( cluster ) && clusters.get( j ).getSite().equals( site ))
}
}
- /* Removing the dead node from the global list */
- for( int i = 0 ; i < nb_node ; i++ )
+ /** Removing the dead node from the global list **/
+ for( int i = 0 ; i < gnodesList.size() ; i++ )
{
if( _dead.getId() == gnodesList.get( i ).getId() )
{
}
}
- 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 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( ! ( gnodesList.size() > 0 ) )
+ {
+ 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 < gnodesList.size() ; i++ )
+ {
+ temp += gnodesList.get(i).getPower() ;
+ }
+
+ average = temp / gnodesList.size() ;
+
+ /** Computation of the variance **/
+ temp = 0 ;
+ for( int i = 0 ; i < gnodesList.size() ; i++ )
+ {
+ temp += Math.pow( ( gnodesList.get(i).getPower() - average ), 2 ) ;
+ }
+
+ /** Computation of the standard deviation **/
+ temp = temp / gnodesList.size() ;
+ std = Math.sqrt( temp ) ;
+
+ /** Computation of the relative standard deviation
+ * plus modifications
+ */
+ hd = 100 * std / average / 10 ;
+
return hd ;
}
+ /**
+ * Initialization of computing nodes in the grid. Set all
+ * of these nodes to be not mapped on, and do the same thing in each
+ * of its clusters.
+ */
+ public void initGNodes()
+ {
+ /** Initialization of the local nodes **/
+ for( int i = 0 ; i < gnodesList.size() ; i++ )
+ {
+ gnodesList.get( i ).setMapped( false ) ;
+ }
+
+ /** Initialization in clusters **/
+ for( int i = 0 ; i < clusters.size() ; i++ )
+ {
+ clusters.get( i ).initGNodes() ;
+ }
+ }
+
+
+
+ /**
+ * Initialization of a set of computing nodes in the grid. Set all
+ * of these given nodes to be not mapped on, and propagates in each
+ * of its clusters.
+ * @param _ag The nodes' list to initialize
+ */
+ public void initGNodes( ArrayList<GNode> _ag )
+ {
+ if( _ag != null && _ag.size() > 0 )
+ {
+ /** Initialization of the local and clusters nodes **/
+ for( int i = 0 ; i < _ag.size() ; i++ )
+ {
+ setMappedStatus( _ag.get( i ), false ) ;
+
+ getClusterOfNode( _ag.get( i ) ).setGNodeStatus( _ag.get( i ), false ) ;
+ }
+ }
+ }
+
+
/**
* Print a comprehensible text version of the grid.
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() ) ;
}