A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
mapping.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
| inline |
side by side
New stable version with the add of the Maheve algorithm.
[mapping.git]
/
src
/
and
/
Mapping
/
Grid.java
diff --git
a/src/and/Mapping/Grid.java
b/src/and/Mapping/Grid.java
index
d93b65e
..
57345cd
100644
(file)
--- a/
src/and/Mapping/Grid.java
+++ b/
src/and/Mapping/Grid.java
@@
-14,9
+14,6
@@
public class Grid implements Serializable
{
private static final long serialVersionUID = 1L;
-
-// private int nb_cluster ;
-// private int nb_node ;
private ArrayList<Cluster> clusters ;
private ArrayList<GNode> gnodesList;
private boolean gnodesList_done;
@@
-27,8
+24,6
@@
public class Grid implements Serializable
*/
public Grid()
{
-// nb_cluster = 0 ;
-// nb_node = 0 ;
clusters = new ArrayList<Cluster>() ;
gnodesList = new ArrayList<GNode>() ;
gnodesList_done = false ;
@@
-49,8
+44,6
@@
public class Grid implements Serializable
{
gnodesList.add( c.getGNodes().get( i ) ) ;
}
-// nb_cluster++ ;
-// nb_node += c.getNbGNode() ;
}
}
@@
-68,9
+61,7
@@
public class Grid implements Serializable
for( int i = 0 ; i < al.size() ; i++ )
{
clusters.add( al.get( i ) ) ;
-// nb_cluster++ ;
nbCLusterNodes = al.get( i ).getNbGNode() ;
-// nb_node += nbCLusterNodes ;
for( int j = 0 ; j < nbCLusterNodes ; j++ )
{
@@
-88,7
+79,6
@@
public class Grid implements Serializable
public int getNbCluster()
{
return clusters.size() ;
-// return nb_cluster ;
}
@@
-99,7
+89,6
@@
public class Grid implements Serializable
public int getNbGNode()
{
return gnodesList.size() ;
-// return nb_node ;
}
@@
-113,18
+102,6
@@
public class Grid implements Serializable
}
-// /**
-// * Initialization of clusters.
-// */
-// public void initClusters()
-// {
-// for( int i = 0 ; i < nb_cluster ; i++ )
-// {
-// clusters.get( i ).initIndice() ;
-// }
-// }
-
-
/**
* Compute and return the distance between two clusters.
* @param _g1 First cluster
@@
-157,8
+134,6
@@
public class Grid implements Serializable
}
}
- //
-
if( cluster1.compareTo( cluster2 ) == 0 )
{
d = 1 ;
@@
-227,8
+202,7
@@
public class Grid implements Serializable
_gnodes.get( i ).setInCluster( true ) ;
_gnodes.get( i ).setMapped( false ) ;
- clusters.get( i ).addGNode( _gnodes.get( j ) ) ;
-// nb_node++ ;
+ clusters.get( j ).addGNode( _gnodes.get( i ) ) ;
gnodesList.add( _gnodes.get( i ) ) ;
} else {
@@
-260,10
+234,8
@@
public class Grid implements Serializable
_gnodes.get( i ).setCluster( cluster ) ;
nClust.addGNode( _gnodes.get( i ) ) ;
-// nb_cluster++ ;
clusters.add( nClust ) ;
-// nb_node++ ;
gnodesList.add( _gnodes.get( i ) ) ;
}
}
@@
-274,34
+246,92
@@
public class Grid implements Serializable
/**
- *
Remove a computing node from the grid
.
- * @param _
dead The node to be removed
+ *
Upgrade the grid with a new node
.
+ * @param _
g The new node
*/
- public void
removeGNode( GNode _dead )
+ public void
addGNode( GNode _g )
{
- if( _
dead
!= null )
+ if( _
g
!= null )
{
- if( _dead.getMapped() )
+ /** Searching the cluster in which the node should be added **/
+ int j = 0 ;
+ for( j = 0; j < clusters.size(); j++ )
{
- String site = "", cluster = "" ;
-
- site = _dead.getSite() ;
- cluster = _dead.getCluster() ;
-
- /** Removing GNode from its cluster **/
- for( int j = 0 ; j < clusters.size() ; j++ )
+ if( _g.getCluster().equalsIgnoreCase( clusters.get( j ).getName() ) )
{
- if( clusters.get( j ).getName().equals( cluster ) && clusters.get( j ).getSite().equals( site ))
+ int pos = clusters.get( j ).isIn( _g ) ;
+
+ if( pos == -1 )
{
- clusters.get( j ).removeGNode( _dead ) ;
-
- break ;
+ _g.setSite( clusters.get( j ).getSite() ) ;
+ _g.setInCluster( true ) ;
+ _g.setMapped( false ) ;
+
+ clusters.get( j ).addGNode( _g ) ;
+ gnodesList.add( _g ) ;
+
+ } else {
+ clusters.get( j ).removeGNode( _g ) ;
+ clusters.get( j ).addGNode( _g ) ;
}
+
+ 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( _g.getName() ) ;
+
+ cluster = names[ 1 ] ;
+ site = names[ 2 ] ;
+
+ System.out.println("** (Grid) Creation of cluster: "+cluster);
+
+ nClust.setName( cluster ) ;
+ nClust.setSite( site ) ;
+
+ _g.setInCluster( true ) ;
+ _g.setMapped( false ) ;
+ _g.setSite( site ) ;
+ _g.setCluster( cluster ) ;
+
+ nClust.addGNode( _g ) ;
+
+ clusters.add( nClust ) ;
+ gnodesList.add( _g ) ;
+ }
+ }
+ gnodesList_done = false ;
+ }
+
+
+ /**
+ * Remove a computing node from the grid.
+ * @param _dead The node to be removed
+ */
+ public void removeGNode( GNode _dead )
+ {
+ if( _dead != null )
+ {
+ /** Removing GNode from its cluster **/
+ int id = getClusterOfNode( _dead ) ;
+
+ if( id != -1 )
+ {
+ clusters.get( id ).removeGNode( _dead ) ;
+ } else {
+ System.err.println( "(Grid) Cluster of dead node not found!" ) ;
+ }
+
/** Removing the dead node from the global list **/
- for( int i = 0 ; i < gnodesList.size() ; i++ )
+ int i = 0 ;
+ for( i = 0 ; i < gnodesList.size() ; i++ )
{
if( _dead.getId() == gnodesList.get( i ).getId() )
{
@@
-309,9
+339,11
@@
public class Grid implements Serializable
break ;
}
}
+
+ } else {
+ System.err.println( "(Grid) The GNode to be deleted is null!" ) ;
}
-
-// nb_node-- ;
+
gnodesList_done = false ;
}
@@
-326,7
+358,14
@@
public class Grid implements Serializable
if( _g != null )
{
/** Change in the cluster **/
- getClusterOfNode( _g ).setGNodeStatus( _g, _status ) ;
+ int id = getClusterOfNode( _g ) ;
+
+ if( id != -1 )
+ {
+ clusters.get(id).setGNodeStatus( _g, _status ) ;
+ } else {
+ System.err.println( "(Grid) Cluster "+_g.getCluster()+" not found!" ) ;
+ }
/** Change in local list **/
for( int i = 0 ; i < gnodesList.size() ; i++ )
@@
-346,20
+385,26
@@
public class Grid implements Serializable
* @param _g A node
* @return The cluster containing the node
*/
- public
Cluster
getClusterOfNode( GNode _g )
+ public
int
getClusterOfNode( GNode _g )
{
+ int ret = -1 ;
+
if( _g != null )
{
for( int i = 0 ; i < clusters.size() ; i++ )
{
if( _g.getCluster().equalsIgnoreCase( clusters.get( i ).getName() ) )
{
- return clusters.get( i ) ;
+ if( _g.getSite().equalsIgnoreCase( clusters.get( i ).getSite() ) )
+ {
+ ret = i ;
+ break ;
+ }
}
}
}
- return
null
;
+ return
ret
;
}
/**
@@
-401,10
+446,14
@@
public class Grid implements Serializable
temp = temp / gnodesList.size() ;
std = Math.sqrt( temp ) ;
- /** Computation of the relative standard deviation
- * plus modifications
- */
- hd = 100 * std / average / 10 ;
+ /** Computation of the relative standard deviation **/
+ hd = std / average ;
+
+ /** Correction of the maximum value **/
+ if( hd > 1 )
+ {
+ hd = 1 ;
+ }
return hd ;
@@
-447,7
+496,14
@@
public class Grid implements Serializable
{
setMappedStatus( _ag.get( i ), false ) ;
- getClusterOfNode( _ag.get( i ) ).setGNodeStatus( _ag.get( i ), false ) ;
+ int id = getClusterOfNode( _ag.get( i ) ) ;
+
+ if( id != -1 )
+ {
+ clusters.get(id).setGNodeStatus( _ag.get( i ), false ) ;
+ } else {
+ System.err.println( "Cluster not found" ) ;
+ }
}
}
}
@@
-468,6
+524,47
@@
public class Grid implements Serializable
System.out.println();
}
+
+
+ /**
+ * Return the average power of the grid, by computing the average for
+ * eac cluster.
+ * @return The average power of the grid
+ */
+ public double getAvgFreePower()
+ {
+ double ret = 0 ;
+ int nb = 0 ;
+
+ if( clusters != null && clusters.size() > 0 )
+ {
+ for( int i = 0 ; i < clusters.size() ; i++ )
+ {
+ nb++ ;
+
+ ret += clusters.get( i ).getAvailablePower() / clusters.get( i ).getNbFreeNodes() ;
+ }
+
+ ret = ret / nb ;
+
+ }
+
+ return ret ;
+ }
+
+
+ /**
+ * Return the amount of freenodes available in the whole grid.
+ * @return The amount of available nodes
+ */
+ public int getNbFreenodes()
+ {
+ int ret = 0 ;
+
+ for( int i = 0 ; i < clusters.size() ; i++ )
+ ret += clusters.get(i).getNbFreeNodes() ;
+ return ret ;
+ }
}