Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
9e10bf5b8e07f296c019848399f0c183d94b66c7
[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
65
66         @Override
67         public GNode replaceNode( GNode _dead, ArrayList<GNode> _ag ) 
68         {
69                 GNode ret = null ;
70                 
71                 if( _dead != null )
72                 {
73                         int pos = 0 ;
74                         pos = mp.getIdOfAssociation( _dead ) ;
75                         
76                         if( pos == -1 )
77                         {
78                                 System.err.println( "GNode "+_dead+" does not exist in the mapping!" ) ;
79                                 return null ;
80                         }
81                         
82                         if( _ag.size() > 0 )
83                         {
84                                 ret = _ag.get( 0 ) ;
85                         } else {
86                                 System.err.println( "Not enought available nodes in gnodes to replace one !" ) ;
87                                 return null ;
88                         }
89                         
90                 }
91                 
92                 return ret ;
93         }
94
95
96         @Override
97         public GNode getOtherGNode( ArrayList<GNode> _ag ) 
98         {
99                 if( _ag.size() > 0 )
100                 {
101                         return _ag.get( 1 ) ;
102                 } 
103                 
104                 return null ;
105         }
106 }
107
108
109
110 /** La programmation est un art, respectons ceux qui la pratiquent !! **/