-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneticAlgorithm.hpp
More file actions
68 lines (54 loc) · 2.23 KB
/
geneticAlgorithm.hpp
File metadata and controls
68 lines (54 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef geneticAlgorithm_hpp
#define geneticAlgorithm_hpp
#include <vector>
#include "customer.hpp"
#include "depot.hpp"
#include <map>
#include "route.hpp"
#include "Graphics.hpp"
#include "types.h"
using Population = std::vector<std::tuple<spChromosome, float>>;
class GeneticAlgorithm
{
int *scale;
float mapSize;
float crossoverRate, intraMutationRate, interMutationRate, elitismRate;
int interMutationInterval;
int penalizeRoutesUntil = 0;
std::vector<Depot>& depots;
std::vector<Customer>& customers;
int preferredVehicleLimit;
Graphics* graphics;
//float cost(
upRouteMap deconstructRoutes(spChromosome& chromosome);
spChromosome reconstructChromosome(upRouteMap& routes);
float cost(upRouteMap& routes);
float cost2(upRouteMap& routes);
float fitness(upRouteMap& routes, int gen);
float euclidDistance(float x1, float y1, float x2, float y2);
int getRandomChromoKey(spChromosome& chromo);
spChromosome mutation(spChromosome& oldChromo);
spChromosome interMutation(spChromosome& oldChromo);
spChromosome insertRouteToDepot(spChromosome& oldChromo, int from, int to);
spChromosome swapMutation(spChromosome& oldChromo);
spChromosome reverseMutation(spChromosome& oldChromo);
spChromosome rerouteMutation(spChromosome& oldChromo);
spChromosome depotSwapMutation(spChromosome& oldChromo);
spChromosome depotInsertMutation(spChromosome& oldChromo);
spChromosome swapBestMutation(spChromosome& oldChromo);
void generateRandomPopulation(Population& population, int populationSize);
spChromosome select(Population& population);
void applyElitism(Population& oldPop, Population& newPop);
std::tuple<spChromosome, spChromosome> crossover(spChromosome& p1, spChromosome& p2);
spChromosome insertBestFeasable(spChromosome oldChromo, int, Customer*);
spChromosome initialChromosome;
Swappable swappable;
public:
GeneticAlgorithm(std::vector<Depot>& depots, std::vector<Customer>& customers, int scale[], int preferredVehicleLimit);
~GeneticAlgorithm()
{
delete graphics;
}
void run(int generationsStepOne, int generationsStepTwo, int populationSize);
};
#endif /* geneticAlgorithm_hpp */