Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Adding new functionalities.
[mapping.git] / src / and / Mapping / DefaultMapping.java
index 5cdb0a2..f322659 100644 (file)
@@ -2,6 +2,7 @@ package and.Mapping ;
 
 
 import java.util.ArrayList;
+import java.util.Random;
 
 
 /**
@@ -23,6 +24,7 @@ public class DefaultMapping extends Algo
        public DefaultMapping()
        {
                super() ;
+               name = "DefaultMapping" ;
        }
        
 
@@ -35,6 +37,7 @@ public class DefaultMapping extends Algo
        {
                super( _gr, _gd ) ;
                archi = _gnodes ;
+               name = "DefaultMapping" ;
        }
        
 
@@ -42,7 +45,7 @@ public class DefaultMapping extends Algo
        @Override
        public void map() 
        {
-               /* If the mapping is possible ... */
+               /** If the mapping is possible ... **/
                if( gr.getNbGTask() <= gl.getNbGNode() )
                {
                        atraiter = gr.getGraph() ;
@@ -68,9 +71,28 @@ public class DefaultMapping extends Algo
        {
                GNode ret = null ;
                
-               if( _dead != null )
+               if( _dead != null && _ag != null )
                {
-                       return _ag.get( 0 ) ;
+                       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 )
+                       {
+                               Random r = new Random() ;
+                               ret = _ag.get( r.nextInt( _ag.size() ) ) ;
+                               
+                       } else {
+                               System.err.println( "Not enought available nodes in gnodes to replace one !" ) ;
+                               return null ;
+                       }       
+                       
+                       nb_fault++ ;
                }
                
                return ret ;
@@ -78,9 +100,21 @@ public class DefaultMapping extends Algo
 
 
        @Override
-       public GNode getOtherGNode() {
-               // 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( 0 ) ;
+               } 
+               
+               return null ;
+       }
+
+
+       @Override
+       public boolean setParams(Object[] _params) {
+               return true ;
        }
 }