source: proiecte/GAIIA/GeneticOperators.h @ 122

Last change on this file since 122 was 122, checked in by (none), 14 years ago
File size: 3.1 KB
Line 
1#ifndef GENETIC_OPERATORS
2#define GENETIC_OPERATORS
3
4#include "Genetic.h"
5#include "Graf.h"
6#include <vector>
7
8using namespace std;
9
10/**
11* Class implementing the crossover operator
12*/
13class Crossover{
14        public:
15                /**
16                * the default constructor
17                */
18                Crossover(){};
19
20                /**
21                * Method that applies the crossover on 2 parents obtaining 2 children
22                *
23                * @param p1 the parent #1
24                * @param p2 the parent #2
25                * @param c1 the child #1
26                * @param c2 the child #2
27                */
28                void crossover(Chromosome & p1, Chromosome & p2, Chromosome & c1, Chromosome &c2);
29
30                /**
31                * Method that applies the crossover on a list of chromosomes
32                *
33                * @param chs the list of chromosomes
34                */
35                void applyCrossover(vector<Chromosome> &chs);
36};
37
38
39/**
40* class implementing the simple mutation
41*/
42class SimpleMutation{
43        public:
44                /**
45                * the number of processors
46                */
47                int nr_procs;
48           
49                /**
50                * the maximum topological level
51                */
52                int max_level;
53   
54                /**
55                * the simple mutation probability
56                */
57                double mutation_pb;
58        public:
59                /**
60                * constructor
61                *
62                * @param p the number of processors
63                * @param l the maximum topological level
64                * @param prob the simple mutation probability
65                */
66                SimpleMutation(int p = 0 , int l = 0, double prob = 0);
67
68                /**
69                * method applying the simple mutation on a chromosome
70                *
71                * @param ch the chromosome we want to mutate
72                */
73                void mutateIndividual(Chromosome & ch);
74};
75
76/**
77* class implementing the swap gene mutation
78*/
79class SwapMutation{
80        public:
81                /**
82                * the number of processors
83                */
84                int nr_procs;
85
86                /**
87                * the maximum topological level
88                */
89                int max_level;
90   
91                /**
92                * the swap gene mutation probability
93                */
94                double mutation_pb;
95        public:
96                /**
97                * constructor
98                *
99                * @param p the number of processors
100                * @param l the maximum topological level
101                * @param prob the swap gene mutation probability
102                */
103                SwapMutation(int p = 0 , int l = 0, double prob = 0);
104
105                /**
106                * method applying the swap gene mutation on a chromosome
107                *
108                * @param ch the chromosome we want to mutate
109                */
110                void mutateIndividual(Chromosome & ch);
111};
112
113/**
114* class implementing the hyper-mutation
115*/
116class HyperMutation {
117        public:
118                /**
119                * the graph of tasks
120                */
121                TaskGraf tasks;
122
123                /**
124                * the hyper-mutation probability
125                */
126                double mutation_pb;
127        public:
128                /**
129                * the default constructor
130                */
131                HyperMutation();
132
133                /**
134                * constructor
135                *
136                * @param t the graph of tasks
137                * @param prob the hyper-mutation probability
138                */
139                HyperMutation(TaskGraf &tgraf, double prob);
140
141                /**
142                * Method that increases the topological level of the current task, then analyzes its predecessors
143                in order to find if there is another free floating node to be moved in the floating nodes list;
144                finally deletes the current node.
145                *
146                * @param ch the current chromosome
147                * @param task_id the current task id
148                */
149                void increaseTopoLvl(Chromosome &ch , int task_id);
150
151                /**
152                * method applying the hyper-mutation on a chromosome
153                *
154                * @param ch the chromosome we want to mutate
155                */
156                void mutateIndividual(Chromosome &ch);
157
158                /**
159                * method applying the hyper-mutation on a list of chromosomes
160                *
161                * @param pop the chromosomes list we want to mutate
162                */
163                void mutate(vector<Chromosome> &pop);
164};
165
166#endif
Note: See TracBrowser for help on using the repository browser.