Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Adding new functionalities.
[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 The parameter(s)
125          * @return  The state of setting parameter(s)
126          */
127         public abstract boolean setParams( Object[] _params ) ;
128         
129         /**
130          * Return the string identifier of the algorithm.
131          * @return The algorithm's identifier
132          */
133         public String getIdS()
134         {
135                 return ids ;
136         }
137         
138         
139         /**
140          * Set the name of the mapping algorithm.
141          * @param _n The new name
142          */
143         public void setName( String _n )
144         {
145                 if( _n != null )
146                 {
147                         name = _n ;
148                 }
149         }
150         
151         
152         /**
153          * Return the name of the mapping algorithm.
154          * @return The algorithm's name
155          */
156         public String getName()
157         {
158                 return name ;
159         }
160 }
161
162 /** La programmation est un art, respectons ceux qui la pratiquent !! **/