Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New version of MAHEVE plus corrections.
[mapping.git] / src / and / Mapping / Simple.java
index 8bf957a..7db86a9 100644 (file)
@@ -5,7 +5,7 @@ import java.util.ArrayList;
 
 
 /**
- * Implementation of Simple Mapping algorithm
+ * Implementation of the Simple Mapping algorithm (no fault tolerance mechanism)
  * @author Sébastien Miquée
  * @version 1.0
  */
@@ -23,6 +23,7 @@ public class Simple extends Algo
        public Simple()
        {
                super() ;
+               name = "Simple" ;
        }
        
 
@@ -34,6 +35,8 @@ public class Simple extends Algo
        public Simple( Graph _gr, Grid _gd )
        {
                super( _gr, _gd ) ;
+               
+               name = "Simple" ;
        }
        
        /**
@@ -48,7 +51,7 @@ public class Simple extends Algo
                {
                        grn = new ArrayList<GNode>() ;
                        
-                       // Tri des clusters suivant leur taille
+                       // Sorting clusters according to their "size"
                    ArrayList<Cluster> cl = gl.getClusters() ;
                    ArrayList<Cluster> cl2 = new ArrayList<Cluster>() ;
                    
@@ -106,35 +109,65 @@ public class Simple extends Algo
                        /** Save the Mapping **/
                        for( int i = 0 ; i < atraiter.size() ; i++ )
                        {
-                               mp.addMapping( new Association( archi.get( i ), atraiter.get( i ) ) ) ;
+                               mp.addMapping( archi.get( i ), atraiter.get( i ) ) ;
                        }
                
                } else {
                        System.err.println( "\n\n!!! Unable to map application !\n\n" ) ;
                }
                
-               /** Update in cluster the status of nodes **/
-               updateGrid() ;
        }
 
 
        @Override
-       public GNode replaceNode(GNode replaced, ArrayList<GNode> _ag ) 
+       public GNode replaceNode(GNode _dead, ArrayList<GNode> _ag ) 
        {
-               // TODO
+               GNode ret = null ;
                
-               /** Update in cluster the status of nodes **/
-               updateGrid() ;
+               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 ;
+                       }       
+                       
+                       nb_fault++ ;
+               }
                
+               return ret ;
+       }
+
+
+       @Override
+       public GNode getOtherGNode( ArrayList<GNode> _ag ) 
+       {
+               /** Returning the first node in the list **/
+               if( _ag.size() > 0 )
+               {
+                       return _ag.get( 1 ) ;
+               } 
                
                return null ;
        }
 
 
        @Override
-       public GNode getOtherGNode( ArrayList<GNode> _ag ) {
-               // TODO Auto-generated method stub
-               return null;
+       public boolean setParams(Object[] _params) {
+               return true ;
        }
 }