Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
142b8a6df3a69c092f999ee4ef693ac186d2f2a0
[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         
21         
22         /**
23          * Default constructor.
24          */
25         public Algo() 
26         {
27                 gr = new Graph() ;
28                 gl = new Grid() ;
29                 mp = new Mapping() ;
30                 ids = "" ;
31         }
32         
33         
34         /**
35          * Constructor.
36          * @param _gr Tasks graph to be mapped
37          * @param _gl Grid graph
38          */
39         public Algo( Graph _gr, Grid _gl )
40         {
41                 gr =  _gr ;
42                 gl = _gl ;
43                 mp = new Mapping() ;
44                 ids = "" ;
45         }
46         
47         
48         /**
49          * Mapping function.
50          */
51         public abstract void map() ;
52         
53         
54         /**
55          * Replace a fallen node by a new one, according to the mapping policy.
56          * @param _dead The fallen node to be replaced
57          * @param _ag The list of all available computing nodes
58          * @return The new node
59          */
60         public abstract GNode replaceNode( GNode _dead, ArrayList<GNode> _ag ) ;
61         
62         
63         /**
64          * Find a new node, which may not takes part into the computation process.
65          * Typically such kind of node is used to create a new spawner or a new super-node,
66          * in order to bring fault tolerance. 
67          * @return Another node which will not compute
68          */
69         public abstract GNode getOtherGNode( ArrayList<GNode> _ag ) ;
70         
71         
72         /**
73          * Return mapping done.
74          * @return The mapping done
75          */
76         public Mapping getMapping()
77         {
78                 return mp ;
79         }       
80         
81         
82         /**
83          * Return the grid used in the algorithm.
84          * @return The Grid
85          */
86         public Grid getGrid()
87         {
88                 return gl ;
89         }
90         
91         
92         /**
93          * Return the graph used in the algorithm.
94          * @return The Graph
95          */
96         public Graph getGraph()
97         {
98                 return gr ;
99         }
100         
101         
102         /**
103          * Set the string identifier for the algorithm.
104          * @param _s The algorithm's identifier
105          */
106         public void setIdS( String _s )
107         {
108                 ids = _s ;
109         }
110         
111         
112         /**
113          * Return the string identifier of the algorithm.
114          * @return The algorithm's identifier
115          */
116         public String getIdS()
117         {
118                 return ids ;
119         }
120         
121         
122         /**
123          * Update the grid status after having done the mapping.
124          */
125         public void updateGrid()
126         {
127                 if( mp.getMappedGNodes().size() > 0 )
128                 {
129                         ArrayList<GNode> temp = mp.getMappedGNodes() ;
130                         for( int i = 0 ; i < temp.size() ; i++ )
131                         {
132                                 gl.getClusterOfNode( temp.get( i ) ).setGNodeStatus( temp.get( i ), true ) ;
133                                 
134                                 gl.setMappedStatus( temp.get( i ), true ) ;
135                         }
136                 }
137         }
138 }
139
140 /** La programmation est un art, respectons ceux qui la pratiquent !! **/