- In DefaultMapping, it returns in both cases the next node in the list.
- In QM, it returns the best computing power node for the replacement,
and a node from the cluster which has the most amount of free nodes
for another node.
- In LSM (Edge-cuts), it returns the nearest node for the replacement,
and a node from the cluster which has the most amount of free nodes
for another node.
- Simple does the same thing as DefaultMapping.
@Override
public GNode getOtherGNode( ArrayList<GNode> _ag )
{
+ /** Returning the first node in the list **/
if( _ag.size() > 0 )
{
return _ag.get( 1 ) ;
{
if( _g != null )
{
+ /** Change in the cluster **/
getClusterOfNode( _g ).setGNodeStatus( _g, _status ) ;
+ /** Change in local list **/
for( int i = 0 ; i < gnodesList.size() ; i++ )
{
if( _g.getId() == gnodesList.get( i ).getId() )
if( _dead != null )
{
ArrayList<GNode> ac = new ArrayList<GNode>() ;
+ GNode tmp = null ;
+ /** Searching if clusters have some free nodes **/
for( int i = 0 ; i < gl.getNbCluster() ; i++ )
{
if( gl.getClusters().get( i ).getNbFreeNodes() > 0 )
{
- ac.add( gl.getClusters().get( i ).nextGNode() ) ;
+ tmp = gl.getClusters().get( i ).nextGNode() ;
+
+ if( tmp != null )
+ {
+ ac.add( tmp ) ;
+ }
}
}
+
+ /** If there some nodes in clusters **/
+ if( ac.size() > 0 )
+ {
+ double dist = -1, best = -1 ;
+ int bestNode = -1 ;
+
+ /** Searching the replacing node with the lower distance
+ * between it and the failed node
+ */
+ for( int i = 0 ; i < ac.size() ; i++ )
+ {
+ dist = gl.getDistance( _dead, ac.get( i ) ) ;
+
+ if( best == -1 )
+ {
+ best = dist ;
+ bestNode = i ;
+ } else {
+ if( dist < best )
+ {
+ best = dist ;
+ bestNode = i ;
+ }
+ }
+ }
+
+ /** Is there any node candidate ? **/
+ if( bestNode != -1 )
+ {
+ ret = ac.get( bestNode ) ;
+ }
+ }
}
/** Update in cluster the status of nodes **/
@Override
public GNode getOtherGNode( ArrayList<GNode> _ag )
{
+ GNode ret = null ;
- return null;
+ /** Updating the grid if there is any modification **/
+ if( _ag != null && _ag.size() != 0 )
+ {
+ gl.updateGrid( _ag ) ;
+ }
+
+ int free[] = new int[ gl.getNbCluster() ] ;
+
+ /** Searching if clusters have some free nodes **/
+ for( int i = 0 ; i < gl.getNbCluster() ; i++ )
+ {
+ free[ i ] = gl.getClusters().get( i ).getNbFreeNodes() ;
+ }
+
+ /** Returning a node from the cluster which has the most
+ * available nodes
+ */
+ int most = -1, max = 0 ;
+
+ for( int i = 0 ; i < free.length ; i++ )
+ {
+ if( free[ i ] > max )
+ {
+ max = free[ i ] ;
+ most = i ;
+ }
+ }
+
+ /** Is there any cluster candidate ? **/
+ if( most != -1 )
+ {
+ ret = gl.getClusters().get( most ).nextGNode() ;
+ }
+
+
+ return ret ;
}
}
@Override
public GNode replaceNode(GNode _dead, ArrayList<GNode> _ag )
{
+ GNode ret = null ;
+
+ /** Updating the grid if there is any modification **/
+ if( _ag != null && _ag.size() != 0 )
+ {
+ gl.updateGrid( _ag ) ;
+ }
+
+ /** If something has to be done **/
+ if( _dead != null )
+ {
+ ArrayList<GNode> ac = new ArrayList<GNode>() ;
+ GNode tmp = null ;
+
+ /** Searching if clusters have some free nodes **/
+ for( int i = 0 ; i < gl.getNbCluster() ; i++ )
+ {
+ if( gl.getClusters().get( i ).getNbFreeNodes() > 0 )
+ {
+ tmp = gl.getClusters().get( i ).nextGNode() ;
+
+ if( tmp != null )
+ {
+ ac.add( tmp ) ;
+ }
+ }
+ }
+
+ /** If there some nodes in clusters **/
+ if( ac.size() > 0 )
+ {
+ double power = -1, best = -1 ;
+ int bestNode = -1 ;
+
+ /** Searching the replacing node with the higher
+ * computing power
+ */
+ for( int i = 0 ; i < ac.size() ; i++ )
+ {
+ power = ac.get( i ).getPower() ;
+
+ if( best == -1 )
+ {
+ best = power ;
+ bestNode = i ;
+ } else {
+ if( power < best )
+ {
+ best = power ;
+ bestNode = i ;
+ }
+ }
+ }
+
+ /** Is there any node candidate ? **/
+ if( bestNode != -1 )
+ {
+ ret = ac.get( bestNode ) ;
+ }
+ }
+ }
+
/** Update in cluster the status of nodes **/
updateGrid() ;
- return null;
+
+ return ret ;
}
@Override
- public GNode getOtherGNode( ArrayList<GNode> _ag ) {
- // TODO Auto-generated method stub
- return null;
+ public GNode getOtherGNode( ArrayList<GNode> _ag )
+ {
+ GNode ret = null ;
+
+ /** Updating the grid if there is any modification **/
+ if( _ag != null && _ag.size() != 0 )
+ {
+ gl.updateGrid( _ag ) ;
+ }
+
+ int free[] = new int[ gl.getNbCluster() ] ;
+
+ /** Searching if clusters have some free nodes **/
+ for( int i = 0 ; i < gl.getNbCluster() ; i++ )
+ {
+ free[ i ] = gl.getClusters().get( i ).getNbFreeNodes() ;
+ }
+
+ /** Returning a node from the cluster which has the most
+ * available nodes
+ */
+ int most = -1, max = 0 ;
+
+ for( int i = 0 ; i < free.length ; i++ )
+ {
+ if( free[ i ] > max )
+ {
+ max = free[ i ] ;
+ most = i ;
+ }
+ }
+
+ /** Is there any cluster candidate ? **/
+ if( most != -1 )
+ {
+ ret = gl.getClusters().get( most ).nextGNode() ;
+ }
+
+
+ return ret ;
}
}
@Override
- public GNode replaceNode(GNode replaced, ArrayList<GNode> _ag )
+ public GNode replaceNode(GNode _dead, ArrayList<GNode> _ag )
{
- // TODO
+ GNode ret = null ;
+
+ if( _dead != null )
+ {
+ int pos = 0 ;
+ pos = mp.getIdOfAssociation( _dead ) ;
+
+ if( pos == -1 )
+ {
+ System.err.println( "GNode "+_dead+" does not exist in the mapping!" ) ;
+ return null ;
+ }
+
+ if( _ag.size() > 0 )
+ {
+ ret = _ag.get( 0 ) ;
+
+
+ } else {
+ System.err.println( "Not enought available nodes in gnodes to replace one !" ) ;
+ return null ;
+ }
+ }
/** Update in cluster the status of nodes **/
updateGrid() ;
-
- return null ;
+ return ret ;
}
@Override
- public GNode getOtherGNode( ArrayList<GNode> _ag ) {
- // TODO Auto-generated method stub
- return null;
+ public GNode getOtherGNode( ArrayList<GNode> _ag )
+ {
+ /** Returning the first node in the list **/
+ if( _ag.size() > 0 )
+ {
+ return _ag.get( 1 ) ;
+ }
+
+ return null ;
}
}