Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New version of MAHEVE plus corrections.
[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                 mp.setGrid( _gl ) ;
52         }
53         
54         
55         /**
56          * Mapping function.
57          */
58         public abstract void map() ;
59         
60         
61         /**
62          * Replace a fallen node by a new one, according to the mapping policy.
63          * @param _dead The fallen node to be replaced
64          * @param _ag The list of all available computing nodes
65          * @return The new node
66          */
67         public abstract GNode replaceNode( GNode _dead, ArrayList<GNode> _ag ) ;
68         
69         
70         /**
71          * Find a new node, which may not takes part into the computation process.
72          * Typically such kind of node is used to create a new spawner or a new super-node,
73          * in order to bring fault tolerance. 
74          * @return Another node which will not compute
75          */
76         public abstract GNode getOtherGNode( ArrayList<GNode> _ag ) ;
77         
78         
79         /**
80          * Return mapping done.
81          * @return The mapping done
82          */
83         public Mapping getMapping()
84         {
85                 return mp ;
86         }       
87         
88         
89         /**
90          * Return the grid used in the algorithm.
91          * @return The Grid
92          */
93         public Grid getGrid()
94         {
95                 return gl ;
96         }
97         
98         
99         /**
100          * Return the graph used in the algorithm.
101          * @return The Graph
102          */
103         public Graph getGraph()
104         {
105                 return gr ;
106         }
107         
108         
109         /**
110          * Set the string identifier for the algorithm.
111          * @param _s The algorithm's identifier
112          */
113         public void setIdS( String _s )
114         {
115                 if( _s != null )
116                 {
117                         ids = _s ;
118                 }
119         }
120         
121         
122         /**
123          * Set the algorithms parameters when this one is instanciated 
124          * by a class load mechanism.
125          * @param _params The parameter(s)
126          * @return  The state of setting parameter(s)
127          */
128         public abstract boolean setParams( Object[] _params ) ;
129         
130         /**
131          * Return the string identifier of the algorithm.
132          * @return The algorithm's identifier
133          */
134         public String getIdS()
135         {
136                 return ids ;
137         }
138         
139         
140         /**
141          * Set the name of the mapping algorithm.
142          * @param _n The new name
143          */
144         public void setName( String _n )
145         {
146                 if( _n != null )
147                 {
148                         name = _n ;
149                 }
150         }
151         
152         
153         /**
154          * Return the name of the mapping algorithm.
155          * @return The algorithm's name
156          */
157         public String getName()
158         {
159                 return name ;
160         }
161 }
162
163 /** La programmation est un art, respectons ceux qui la pratiquent !! **/