1 | #ifndef GRAF |
---|
2 | #define GRAF |
---|
3 | |
---|
4 | #include <stdio.h> |
---|
5 | #include <stdlib.h> |
---|
6 | #include <vector> |
---|
7 | |
---|
8 | using namespace std; |
---|
9 | |
---|
10 | /** |
---|
11 | * class implementing a general node of a graph |
---|
12 | */ |
---|
13 | class Nod |
---|
14 | { |
---|
15 | public: |
---|
16 | /** |
---|
17 | * the node's id |
---|
18 | */ |
---|
19 | int id; |
---|
20 | |
---|
21 | /** |
---|
22 | * the node's corresponding cost |
---|
23 | */ |
---|
24 | double cost; |
---|
25 | |
---|
26 | /** |
---|
27 | * the number of predecessors |
---|
28 | */ |
---|
29 | int nr_pred; |
---|
30 | |
---|
31 | /** |
---|
32 | * the number of successors |
---|
33 | */ |
---|
34 | int nr_succ; |
---|
35 | |
---|
36 | /** |
---|
37 | * the list of predecesors |
---|
38 | */ |
---|
39 | void ** predecesori; |
---|
40 | |
---|
41 | /** |
---|
42 | * the list of successors |
---|
43 | */ |
---|
44 | void ** succesori; |
---|
45 | |
---|
46 | public: |
---|
47 | /** |
---|
48 | * the constructor |
---|
49 | * |
---|
50 | * @param i the id |
---|
51 | * @param c the cost |
---|
52 | */ |
---|
53 | Nod(int i = 0, double c = 0); |
---|
54 | |
---|
55 | /** |
---|
56 | * Method printing the node's information |
---|
57 | */ |
---|
58 | void print(); |
---|
59 | |
---|
60 | /** |
---|
61 | * Method adding a predecessor |
---|
62 | * |
---|
63 | * @param p the new predecessor |
---|
64 | */ |
---|
65 | void addPredecesor(void *p); |
---|
66 | |
---|
67 | /** |
---|
68 | * Method adding a successor |
---|
69 | * |
---|
70 | * @param s the new successor |
---|
71 | */ |
---|
72 | void addSuccesor(void * s); |
---|
73 | }; |
---|
74 | |
---|
75 | /** |
---|
76 | * class implementing a node of a tasks graph |
---|
77 | */ |
---|
78 | class Task:public Nod |
---|
79 | { |
---|
80 | public: |
---|
81 | /** |
---|
82 | * the minimum topological level |
---|
83 | */ |
---|
84 | int niv_topo_min; |
---|
85 | |
---|
86 | /** |
---|
87 | * the maximum topological level |
---|
88 | */ |
---|
89 | int niv_topo_max; |
---|
90 | |
---|
91 | /** |
---|
92 | * the current topological level |
---|
93 | */ |
---|
94 | int niv_topo; |
---|
95 | |
---|
96 | /** |
---|
97 | * the id of the associated processor |
---|
98 | */ |
---|
99 | int procesor_id; |
---|
100 | |
---|
101 | /** |
---|
102 | * the start moment for the current task |
---|
103 | */ |
---|
104 | int start; |
---|
105 | |
---|
106 | /** |
---|
107 | * the stop moment for the current task |
---|
108 | */ |
---|
109 | int stop; |
---|
110 | public: |
---|
111 | /** |
---|
112 | * the constructor |
---|
113 | * |
---|
114 | * @param i the id |
---|
115 | * @param c the cost |
---|
116 | */ |
---|
117 | Task(int i = 0, double c = 0); |
---|
118 | |
---|
119 | /** |
---|
120 | * Method that assocites to the current task a processor scheduling it to be executed between "st" and "fin" |
---|
121 | * |
---|
122 | * @param id the id of the associated processor |
---|
123 | * @param st the start moment |
---|
124 | * @param fin the stop moment |
---|
125 | */ |
---|
126 | void setProcesor(int id,int st, int fin); |
---|
127 | |
---|
128 | /** |
---|
129 | * the default initialization |
---|
130 | */ |
---|
131 | void init(); |
---|
132 | |
---|
133 | /** |
---|
134 | * method printing the task's information |
---|
135 | */ |
---|
136 | void print(); |
---|
137 | }; |
---|
138 | |
---|
139 | /** |
---|
140 | * class implementing a node of a processors graph |
---|
141 | */ |
---|
142 | class Procesor:public Nod |
---|
143 | { |
---|
144 | public: |
---|
145 | /** |
---|
146 | * the total number of tasks we want to schedule |
---|
147 | */ |
---|
148 | int nr_tasks; |
---|
149 | |
---|
150 | /** |
---|
151 | * the total number of processors we can use |
---|
152 | */ |
---|
153 | int nr_procs; |
---|
154 | |
---|
155 | /** |
---|
156 | * the queue of associated tasks |
---|
157 | */ |
---|
158 | int * queue; |
---|
159 | |
---|
160 | /** |
---|
161 | * current time used in the fitness computation |
---|
162 | */ |
---|
163 | int time; |
---|
164 | |
---|
165 | /** |
---|
166 | * the list containing the communication costs with neighbours |
---|
167 | */ |
---|
168 | int * cost_comm; |
---|
169 | public: |
---|
170 | /** |
---|
171 | * the constructor |
---|
172 | * |
---|
173 | * @param i the processor's index |
---|
174 | * @param c the processor's cost |
---|
175 | */ |
---|
176 | Procesor(int i = 0, int c = 0); |
---|
177 | |
---|
178 | /** |
---|
179 | * Method adding a task in the tasks queue |
---|
180 | * |
---|
181 | * @param task_id the index of the task we add in the list |
---|
182 | */ |
---|
183 | void addTask(int task_id); |
---|
184 | |
---|
185 | /** |
---|
186 | * Method initializing a processor to the default values |
---|
187 | */ |
---|
188 | void init(); |
---|
189 | |
---|
190 | /** |
---|
191 | * method adding the communication costs for the specified number of processors |
---|
192 | * |
---|
193 | * @param v the list of communication costs |
---|
194 | * @param n the number of processors |
---|
195 | */ |
---|
196 | void addCosts(int v[], int n); |
---|
197 | |
---|
198 | /** |
---|
199 | * Method printing the processor's information |
---|
200 | */ |
---|
201 | void print(); |
---|
202 | }; |
---|
203 | |
---|
204 | /** |
---|
205 | * class implementing a graph edge |
---|
206 | */ |
---|
207 | class Muchie |
---|
208 | { |
---|
209 | public: |
---|
210 | /** |
---|
211 | * the predecessor node |
---|
212 | */ |
---|
213 | Nod * predecesor; |
---|
214 | |
---|
215 | /** |
---|
216 | * the successor node |
---|
217 | */ |
---|
218 | Nod * succesor; |
---|
219 | |
---|
220 | /** |
---|
221 | * the edge's communication cost |
---|
222 | */ |
---|
223 | double cost; |
---|
224 | public: |
---|
225 | /** |
---|
226 | * the constructor |
---|
227 | * |
---|
228 | * @param p the predecessor node |
---|
229 | * @param s the successor node |
---|
230 | * @param c the edge's communication cost |
---|
231 | */ |
---|
232 | Muchie(Nod * p = NULL, Nod * s = NULL, double c = 0); |
---|
233 | |
---|
234 | /** |
---|
235 | * Method printing the edge's information |
---|
236 | */ |
---|
237 | void print(); |
---|
238 | }; |
---|
239 | |
---|
240 | /** |
---|
241 | * class implementing a graph |
---|
242 | */ |
---|
243 | class Graf |
---|
244 | { |
---|
245 | public: |
---|
246 | /** |
---|
247 | * the nodes list |
---|
248 | */ |
---|
249 | Nod * noduri; |
---|
250 | |
---|
251 | /** |
---|
252 | * the edges list |
---|
253 | */ |
---|
254 | Muchie * muchii; |
---|
255 | |
---|
256 | /** |
---|
257 | * the number of nodes |
---|
258 | */ |
---|
259 | int nr_noduri; |
---|
260 | |
---|
261 | /** |
---|
262 | * the number of edges |
---|
263 | */ |
---|
264 | int nr_muchii; |
---|
265 | public: |
---|
266 | /** |
---|
267 | * the constructor |
---|
268 | * |
---|
269 | * @param n the number of nodes |
---|
270 | * @param m the number of edges |
---|
271 | */ |
---|
272 | Graf(int n = 0, int m = 0); |
---|
273 | |
---|
274 | /** |
---|
275 | * the constructor |
---|
276 | * |
---|
277 | * @param filename the input filename |
---|
278 | */ |
---|
279 | Graf(char * filename); |
---|
280 | |
---|
281 | /** |
---|
282 | * method printing the graph's information |
---|
283 | */ |
---|
284 | void print(); |
---|
285 | |
---|
286 | /** |
---|
287 | * copy operator |
---|
288 | */ |
---|
289 | Graf& operator=(const Graf& clone); |
---|
290 | }; |
---|
291 | |
---|
292 | /** |
---|
293 | * class implementing a graph of tasks |
---|
294 | */ |
---|
295 | class TaskGraf: public Graf |
---|
296 | { |
---|
297 | public: |
---|
298 | /** |
---|
299 | * the list of nodes (tasks) |
---|
300 | */ |
---|
301 | Task * noduri; |
---|
302 | |
---|
303 | /** |
---|
304 | * the maximum topological level |
---|
305 | */ |
---|
306 | int max_level; |
---|
307 | |
---|
308 | /** |
---|
309 | * the list of floating nodes |
---|
310 | */ |
---|
311 | vector<int> f_nodes; |
---|
312 | public: |
---|
313 | /** |
---|
314 | * method initializing a graph of tasks to the structure specified in the file |
---|
315 | * |
---|
316 | * @param filename the input filename containing the configuration |
---|
317 | */ |
---|
318 | void init(char * filename); |
---|
319 | |
---|
320 | /** |
---|
321 | * the constructor |
---|
322 | * |
---|
323 | * @param n the number of tasks |
---|
324 | * @param m the number of communication links |
---|
325 | */ |
---|
326 | TaskGraf(int n = 0, int m = 0); |
---|
327 | |
---|
328 | /** |
---|
329 | * method that computes the topological sort |
---|
330 | * |
---|
331 | * @return the maximum topological level |
---|
332 | */ |
---|
333 | int sortare_topologica(); |
---|
334 | |
---|
335 | /** |
---|
336 | * method that computes the reverse topological sort |
---|
337 | */ |
---|
338 | void sortare_topologica_inversa(); |
---|
339 | |
---|
340 | /** |
---|
341 | * method that computes the list of free floating nodes |
---|
342 | */ |
---|
343 | void computeFreeFloatingNodes(); |
---|
344 | |
---|
345 | /** |
---|
346 | * method that initializes the structure with the default configuration |
---|
347 | */ |
---|
348 | void init(); |
---|
349 | |
---|
350 | /** |
---|
351 | * method that computes the topological sort |
---|
352 | */ |
---|
353 | void sort_topo(); |
---|
354 | |
---|
355 | /** |
---|
356 | * method that prints the information about the graph of tasks |
---|
357 | */ |
---|
358 | void print(); |
---|
359 | |
---|
360 | /** |
---|
361 | * the copy operator |
---|
362 | */ |
---|
363 | TaskGraf& operator=(const TaskGraf& clone); |
---|
364 | }; |
---|
365 | |
---|
366 | /** |
---|
367 | * class implementing a graph of processors |
---|
368 | */ |
---|
369 | class ProcesorGraf: public Graf |
---|
370 | { |
---|
371 | public: |
---|
372 | /** |
---|
373 | * the list of processors |
---|
374 | */ |
---|
375 | Procesor * noduri; |
---|
376 | |
---|
377 | public: |
---|
378 | /** |
---|
379 | * method initializing a graph of processors to the structure specified in the file |
---|
380 | * |
---|
381 | * @param filename the input filename containing the configuration |
---|
382 | */ |
---|
383 | void init(char * filename); |
---|
384 | |
---|
385 | /** |
---|
386 | * the constructor |
---|
387 | * |
---|
388 | * @param n the number of processors |
---|
389 | * @param m the number of communication links |
---|
390 | */ |
---|
391 | ProcesorGraf(int n = 0, int m = 0); |
---|
392 | |
---|
393 | /** |
---|
394 | * method that initializes the structure with the default configuration |
---|
395 | */ |
---|
396 | void init(); |
---|
397 | |
---|
398 | /** |
---|
399 | * method that prints the information about the graph of processors |
---|
400 | */ |
---|
401 | void print(); |
---|
402 | |
---|
403 | /** |
---|
404 | * the copy operator |
---|
405 | */ |
---|
406 | ProcesorGraf& operator=(const ProcesorGraf& clone); |
---|
407 | }; |
---|
408 | |
---|
409 | #endif |
---|