Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
1b21ea68b0257111be5e9de45cdc0896f4b99261
[mapping.git] / src / and / Mapping / DefaultMapping.java
1 package and.Mapping ;
2
3
4 import java.util.ArrayList;
5
6
7 /**
8  * Implementation of JaceP2P default mapping
9  * @author Sébastien Miquée
10  * @version 1.0
11  */
12 public class DefaultMapping extends Algo
13 {
14         private static final long serialVersionUID = 1L;
15
16         
17         private ArrayList<GTask> atraiter ;
18         private ArrayList<GNode> archi ;
19         
20         /**
21          * Default constructor.
22          */
23         public DefaultMapping()
24         {
25                 super() ;
26         }
27         
28
29         /**
30          * Constructor.
31          * @param _gr Tasks graph to be mapped
32          * @param _gd Grid graph
33          */
34         public DefaultMapping( Graph _gr, Grid _gd, ArrayList<GNode> _gnodes )
35         {
36                 super( _gr, _gd ) ;
37                 archi = _gnodes ;
38         }
39         
40
41
42         @Override
43         public void map() 
44         {
45                 /** If the mapping is possible ... **/
46                 if( gr.getNbGTask() <= gl.getNbGNode() )
47                 {
48                         atraiter = gr.getGraph() ;
49                         
50                         System.out.println( "*******************************************" ) ;
51                         System.out.println( "* Launching the Default Mapping algorithm *" ) ;
52                         System.out.println( "*******************************************\n\n" ) ;
53                         
54                         /** Save the Mapping **/
55                         for( int i = 0 ; i < atraiter.size() ; i++ )
56                         {
57                                 mp.addMapping( new Association( archi.get( i ), atraiter.get( i ) ) ) ;
58                         }
59                 
60                 } else {
61                         System.err.println( "\n\n!!! Unable to map application !\n\n" ) ;
62                 }
63                 
64                 /** Update in cluster the status of nodes **/
65                 updateGrid() ;
66         }
67
68
69         @Override
70         public GNode replaceNode( GNode _dead, ArrayList<GNode> _ag ) 
71         {
72                 GNode ret = null ;
73                 
74                 if( _dead != null )
75                 {
76                         int pos = 0 ;
77                         pos = mp.getIdOfAssociation( _dead ) ;
78                         
79                         if( pos == -1 )
80                         {
81                                 System.err.println( "GNode "+_dead+" does not exist in the mapping!" ) ;
82                                 return null ;
83                         }
84                         
85                         if( _ag.size() > 0 )
86                         {
87                                 ret = _ag.get( 0 ) ;
88                         } else {
89                                 System.err.println( "Not enought available nodes in gnodes to replace one !" ) ;
90                                 return null ;
91                         }               
92                 }
93                 
94                 /** Update in cluster the status of nodes **/
95                 updateGrid() ;
96                 
97                 return ret ;
98         }
99
100
101         @Override
102         public GNode getOtherGNode( ArrayList<GNode> _ag ) 
103         {
104                 if( _ag.size() > 0 )
105                 {
106                         return _ag.get( 1 ) ;
107                 } 
108                 
109                 return null ;
110         }
111 }
112
113
114
115 /** La programmation est un art, respectons ceux qui la pratiquent !! **/