Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Adding new functionalities.
[mapping.git] / src / and / Mapping / DefaultMapping.java
index 4123be8..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,7 +71,7 @@ public class DefaultMapping extends Algo
        {
                GNode ret = null ;
                
-               if( _dead != null )
+               if( _dead != null && _ag != null )
                {
                        int pos = 0 ;
                        pos = mp.getIdOfAssociation( _dead ) ;
@@ -81,14 +84,15 @@ public class DefaultMapping extends Algo
                        
                        if( _ag.size() > 0 )
                        {
-                               ret = _ag.get( 0 ) ;
+                               Random r = new Random() ;
+                               ret = _ag.get( r.nextInt( _ag.size() ) ) ;
                                
-                               mp.getMapping().get( pos ).setGNode( ret ) ;
                        } else {
                                System.err.println( "Not enought available nodes in gnodes to replace one !" ) ;
                                return null ;
-                       }
+                       }       
                        
+                       nb_fault++ ;
                }
                
                return ret ;
@@ -98,13 +102,20 @@ public class DefaultMapping extends Algo
        @Override
        public GNode getOtherGNode( ArrayList<GNode> _ag ) 
        {
+               /** Returning the first node in the list **/
                if( _ag.size() > 0 )
                {
-                       return _ag.get( 1 ) ;
+                       return _ag.get( 0 ) ;
                } 
                
                return null ;
        }
+
+
+       @Override
+       public boolean setParams(Object[] _params) {
+               return true ;
+       }
 }