Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New version of MAHEVE plus corrections.
[mapping.git] / src / and / Mapping / DefaultMapping.java
index 2f096b8..5aa64e5 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" ;
        }
        
 
@@ -31,10 +33,10 @@ public class DefaultMapping extends Algo
         * @param _gr Tasks graph to be mapped
         * @param _gd Grid graph
         */
-       public DefaultMapping( Graph _gr, Grid _gd, ArrayList<GNode> _gnodes )
+       public DefaultMapping( Graph _gr, Grid _gd )
        {
                super( _gr, _gd ) ;
-               archi = _gnodes ;
+               name = "DefaultMapping" ;
        }
        
 
@@ -46,6 +48,8 @@ public class DefaultMapping extends Algo
                if( gr.getNbGTask() <= gl.getNbGNode() )
                {
                        atraiter = gr.getGraph() ;
+                       archi = gl.getFreeGNodes() ;
+                       
                        
                        System.out.println( "*******************************************" ) ;
                        System.out.println( "* Launching the Default Mapping algorithm *" ) ;
@@ -54,15 +58,14 @@ public class DefaultMapping extends Algo
                        /** Save the Mapping **/
                        for( int i = 0 ; i < atraiter.size() ; i++ )
                        {
-                               mp.addMapping( new Association( archi.get( i ), atraiter.get( i ) ) ) ;
+                               Random r = new Random() ;
+                               int ret = r.nextInt( archi.size() ) ;
+                               mp.addMapping( archi.remove( ret ), atraiter.get( i ) ) ;
                        }
                
                } else {
                        System.err.println( "\n\n!!! Unable to map application !\n\n" ) ;
                }
-               
-               /** Update in cluster the status of nodes **/
-               updateGrid() ;
        }
 
 
@@ -71,7 +74,7 @@ public class DefaultMapping extends Algo
        {
                GNode ret = null ;
                
-               if( _dead != null )
+               if( _dead != null && _ag != null )
                {
                        int pos = 0 ;
                        pos = mp.getIdOfAssociation( _dead ) ;
@@ -84,18 +87,17 @@ public class DefaultMapping extends Algo
                        
                        if( _ag.size() > 0 )
                        {
-                               ret = _ag.get( 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++ ;
                }
                
-               /** Update in cluster the status of nodes **/
-               updateGrid() ;
-               
                return ret ;
        }
 
@@ -106,11 +108,17 @@ public class DefaultMapping extends Algo
                /** 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 ;
+       }
 }