Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
abf443d3cc01435daee4a7b03abab732d01ea465
[mapping.git] / src / and / Mapping / Simple.java
1 package and.Mapping ;
2
3
4 import java.util.ArrayList;
5
6
7 /**
8  * Implementation of Simple Mapping algorithm
9  * @author Sébastien Miquée
10  * @version 1.0
11  */
12 public class Simple 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 Simple()
24         {
25                 super() ;
26         }
27         
28
29         /**
30          * Constructor.
31          * @param _gr Application graph to be mapped on
32          * @param _gd Grid graph
33          */
34         public Simple( Graph _gr, Grid _gd )
35         {
36                 super( _gr, _gd ) ;
37         }
38         
39         /**
40          * 
41          * @return
42          */
43         private ArrayList<GNode> sortInitGNode() 
44         {
45                 ArrayList<GNode> grn = null ;
46                 
47                 if( gl != null )
48                 {
49                         grn = new ArrayList<GNode>() ;
50                         
51                         // Tri des clusters suivant leur taille
52                     ArrayList<Cluster> cl = gl.getClusters() ;
53                     ArrayList<Cluster> cl2 = new ArrayList<Cluster>() ;
54                     
55                     int max = 0 ;
56                     Cluster c = null ;
57                     Cluster c2 = null ;
58         
59                     while( cl2.size() != gl.getNbCluster() )
60                     {
61                     
62                         max = 0 ;
63                     
64                         for( int i = 0 ; i < cl.size() ; i++ )
65                         {
66                             c = cl.get( i ) ;
67                             if( c.getNbGNode() > max )
68                             {
69                                 c2 = c ;
70                                 max = c.getNbGNode() ;
71                             }
72                         }
73                     
74                         cl2.add( c2 ) ;
75                         cl.remove( c2 ) ;
76                     }
77         
78                         for( int i = 0 ; i < cl2.size() ; i++ )
79                         {
80                             Cluster tmp = cl2.get( i ) ;
81                             
82                             for( int j = 0 ; j < tmp.getNbGNode() ; j++ )
83                             {
84                                 grn.add( tmp.getGNodes().get( j ) ) ;
85                             }
86                         }
87                 }
88                 
89                 return grn ;
90         }
91
92
93         @Override
94         public void map() 
95         {
96                 /* If the mapping is possible ... */
97                 if( gr.getNbGTask() <= gl.getNbGNode() )
98                 {
99                         archi = sortInitGNode() ;
100                         atraiter = gr.getGraph() ;
101                         
102                         System.out.println( "******************************************" ) ;
103                         System.out.println( "* Launching the Simple Mapping algorithm *" ) ;
104                         System.out.println( "******************************************\n\n" ) ;
105                         
106                         /** Save the Mapping **/
107                         for( int i = 0 ; i < atraiter.size() ; i++ )
108                         {
109                                 mp.addMapping( new Association( archi.get( i ), atraiter.get( i ) ) ) ;
110                         }
111                 
112                 } else {
113                         System.err.println( "\n\n!!! Unable to map application !\n\n" ) ;
114                 }
115         }
116
117
118         @Override
119         public GNode replaceNode(GNode replaced, ArrayList<GNode> _ag ) 
120         {
121                 // TODO
122                 return null ;
123         }
124
125
126         @Override
127         public GNode getOtherGNode( ArrayList<GNode> _ag ) {
128                 // TODO Auto-generated method stub
129                 return null;
130         }
131 }
132
133
134
135 /** La programmation est un art, respectons ceux qui la pratiquent !! **/