Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ab4a895e678ef749814c8b80f525f88715017dab
[mapping.git] / src / and / Mapping / Algo.java
1 package and.Mapping ;
2
3 import java.io.Serializable;
4 import java.util.ArrayList;
5
6
7 /**
8  * Abstract class defining the structure for mapping algorithms
9  * @author Sébastien Miquée
10  */
11 public abstract class Algo implements Serializable
12 {
13         private static final long serialVersionUID = 1L;
14
15         /* Variables */
16         protected Graph gr ;
17         protected Grid gl ;
18         protected Mapping mp ;
19         protected String ids ;
20         protected String name ;
21         protected int nb_fault ;
22         
23         
24         /**
25          * Default constructor.
26          */
27         public Algo() 
28         {
29                 gr = new Graph() ;
30                 gl = new Grid() ;
31                 mp = new Mapping() ;
32                 ids = "" ;
33                 name = "" ;
34                 nb_fault = 0 ;
35         }
36         
37         
38         /**
39          * Constructor.
40          * @param _gr Tasks graph to be mapped
41          * @param _gl Grid graph
42          */
43         public Algo( Graph _gr, Grid _gl )
44         {
45                 gr =  _gr ;
46                 gl = _gl ;
47                 mp = new Mapping() ;
48                 ids = "" ;
49                 name = "" ;
50                 nb_fault = 0 ;
51         }
52         
53         
54         /**
55          * Mapping function.
56          */
57         public abstract void map() ;
58         
59         
60         /**
61          * Replace a fallen node by a new one, according to the mapping policy.
62          * @param _dead The fallen node to be replaced
63          * @param _ag The list of all available computing nodes
64          * @return The new node
65          */
66         public abstract GNode replaceNode( GNode _dead, ArrayList<GNode> _ag ) ;
67         
68         
69         /**
70          * Find a new node, which may not takes part into the computation process.
71          * Typically such kind of node is used to create a new spawner or a new super-node,
72          * in order to bring fault tolerance. 
73          * @return Another node which will not compute
74          */
75         public abstract GNode getOtherGNode( ArrayList<GNode> _ag ) ;
76         
77         
78         /**
79          * Return mapping done.
80          * @return The mapping done
81          */
82         public Mapping getMapping()
83         {
84                 return mp ;
85         }       
86         
87         
88         /**
89          * Return the grid used in the algorithm.
90          * @return The Grid
91          */
92         public Grid getGrid()
93         {
94                 return gl ;
95         }
96         
97         
98         /**
99          * Return the graph used in the algorithm.
100          * @return The Graph
101          */
102         public Graph getGraph()
103         {
104                 return gr ;
105         }
106         
107         
108         /**
109          * Set the string identifier for the algorithm.
110          * @param _s The algorithm's identifier
111          */
112         public void setIdS( String _s )
113         {
114                 if( _s != null )
115                 {
116                         ids = _s ;
117                 }
118         }
119         
120         
121         /**
122          * Set the algorithms parameters when this one is instanciated 
123          * by a class load mechanism.
124          * @param _params
125          * @return
126          */
127         public boolean setParams( Object[] _params )
128         {
129                 if( _params.length >= 2 )
130                 {
131                         gr = (Graph) _params[0] ;
132                         gl = (Grid) _params[1];
133                 } else {
134                         System.err.println( "Not enough parameters!" ) ;
135                         return false ;
136                 }
137                 
138                 return true ;
139         }
140         
141         /**
142          * Return the string identifier of the algorithm.
143          * @return The algorithm's identifier
144          */
145         public String getIdS()
146         {
147                 return ids ;
148         }
149         
150         
151         /**
152          * Set the name of the mapping algorithm.
153          * @param _n The new name
154          */
155         public void setName( String _n )
156         {
157                 if( _n != null )
158                 {
159                         name = _n ;
160                 }
161         }
162         
163         
164         /**
165          * Return the name of the mapping algorithm.
166          * @return The algorithm's name
167          */
168         public String getName()
169         {
170                 return name ;
171         }
172 }
173
174 /** La programmation est un art, respectons ceux qui la pratiquent !! **/