1 | #ifndef GENETIC_H |
---|
2 | #define GENETIC_H |
---|
3 | |
---|
4 | #include <vector> |
---|
5 | using namespace std; |
---|
6 | |
---|
7 | /** |
---|
8 | * Class containing one gene's representation |
---|
9 | */ |
---|
10 | class Gene{ |
---|
11 | |
---|
12 | public: |
---|
13 | /** |
---|
14 | * the index of the task |
---|
15 | */ |
---|
16 | int task_index; |
---|
17 | |
---|
18 | /** |
---|
19 | * the index of the processor where the task is asigned |
---|
20 | */ |
---|
21 | int proc_index; |
---|
22 | |
---|
23 | /** |
---|
24 | * the topological level of the task |
---|
25 | */ |
---|
26 | int level; |
---|
27 | |
---|
28 | public: |
---|
29 | /** |
---|
30 | * Default constructor. |
---|
31 | */ |
---|
32 | Gene(); |
---|
33 | |
---|
34 | /** |
---|
35 | * Constructor |
---|
36 | * |
---|
37 | * @param task the index of the task |
---|
38 | * @param proc the index of the processor |
---|
39 | * @param lev the topological level of the task |
---|
40 | */ |
---|
41 | Gene(int task,int proc,int lev); |
---|
42 | |
---|
43 | /** |
---|
44 | * Copy operator |
---|
45 | */ |
---|
46 | Gene& operator=(const Gene& clone); |
---|
47 | |
---|
48 | /** |
---|
49 | * Method printing the gene's configuration |
---|
50 | */ |
---|
51 | void print(); |
---|
52 | }; |
---|
53 | |
---|
54 | /** |
---|
55 | * The implicit (default) gene |
---|
56 | */ |
---|
57 | static Gene null_gene = Gene(-1,-1,-1); |
---|
58 | |
---|
59 | /** |
---|
60 | * Class containing the chromosome's representation |
---|
61 | */ |
---|
62 | class Chromosome{ |
---|
63 | public: |
---|
64 | /** |
---|
65 | * the list of genes |
---|
66 | */ |
---|
67 | vector<Gene> genes; |
---|
68 | |
---|
69 | /** |
---|
70 | * the list of floating nodes |
---|
71 | */ |
---|
72 | vector<int> f_nodes; |
---|
73 | |
---|
74 | /** |
---|
75 | * the chromosome's makespan |
---|
76 | */ |
---|
77 | double makespan; |
---|
78 | |
---|
79 | /** |
---|
80 | * the chromosome's fitness |
---|
81 | */ |
---|
82 | double fitness; |
---|
83 | |
---|
84 | /** |
---|
85 | * load balancing evaluation |
---|
86 | */ |
---|
87 | double evalT1; |
---|
88 | |
---|
89 | /** |
---|
90 | * idle time evaluation |
---|
91 | */ |
---|
92 | double evalT2; |
---|
93 | |
---|
94 | /** |
---|
95 | * makespan evalutaion considering the whole population |
---|
96 | */ |
---|
97 | double evalT3; |
---|
98 | |
---|
99 | /** |
---|
100 | * currently load balance |
---|
101 | */ |
---|
102 | double loadBalance; |
---|
103 | public: |
---|
104 | /** |
---|
105 | * constructor |
---|
106 | */ |
---|
107 | Chromosome(); |
---|
108 | |
---|
109 | /** |
---|
110 | * Copy operator |
---|
111 | */ |
---|
112 | Chromosome& operator=(const Chromosome& clone); |
---|
113 | |
---|
114 | /** |
---|
115 | * Iterator operator |
---|
116 | */ |
---|
117 | Gene& operator[](int poz); |
---|
118 | |
---|
119 | /** |
---|
120 | * Method that adds a gene to the genes list |
---|
121 | * |
---|
122 | * @param g the new gene |
---|
123 | */ |
---|
124 | void append(Gene &g); |
---|
125 | |
---|
126 | /** |
---|
127 | * Method that initializes the population |
---|
128 | */ |
---|
129 | void init(); |
---|
130 | |
---|
131 | /** |
---|
132 | * Method that inserts a gene to the genes list in the specified position |
---|
133 | * |
---|
134 | * @param g the new gene |
---|
135 | * @param poz the position in the list |
---|
136 | */ |
---|
137 | void insert(Gene g,int poz); |
---|
138 | |
---|
139 | /** |
---|
140 | * Method that removes a gene from the genes list |
---|
141 | * |
---|
142 | * @param poz the gene's position |
---|
143 | * @return the removed gene |
---|
144 | */ |
---|
145 | Gene remove(int poz); |
---|
146 | |
---|
147 | /** |
---|
148 | * Method that returns the size of the genes list |
---|
149 | * |
---|
150 | * @return the size |
---|
151 | */ |
---|
152 | int size(); |
---|
153 | |
---|
154 | /** |
---|
155 | * Method that prints the chromosome's configuration |
---|
156 | */ |
---|
157 | void print() const; |
---|
158 | }; |
---|
159 | |
---|
160 | |
---|
161 | |
---|
162 | #endif |
---|