-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·102 lines (92 loc) · 2.12 KB
/
main.cpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#define TAM_POP 20
#define DIMENSION 2
#define SCENARIO 1
#define ITERATIONS 1000
#define RUNS 5
#define NUM_CLANS 4
#include <string>
#include <cmath>
#include "algorithms/particle_swarm.hpp"
#include "algorithms/clan_particle_swarm.hpp"
#include "benchmarcks/problem.hpp"
#include "benchmarcks/problem_factory.hpp"
using namespace std;
string getProblem();
int getAlgorithm();
int main(int argc, char **argv) {
string value;
int algorithm;
ParticleSwarm *pso;
ClanParticleSwarm *cpso;
value = getProblem();
cout << "opcao escolhida foi: " << value << endl;
ProblemFactory *factory = new ProblemFactory();
Problem *problem = factory->get(value, DIMENSION, SCENARIO);
algorithm = getAlgorithm();
switch (algorithm){
case 1:
pso = new ParticleSwarm(problem, TAM_POP);
pso->evolutionaryCicle(ITERATIONS, RUNS);
break;
case 2:
cpso = new ClanParticleSwarm(problem, TAM_POP, NUM_CLANS);
cpso->evolutionaryCicle(ITERATIONS, RUNS);
break;
default:
cout << "Opcao Invalida" << endl;
getAlgorithm();
}
return 0;
}
string getProblem(){
int index;
string answer;
cout << "Select the problem:" << endl;
cout << "1. Ackley" << endl;
cout << "2. Rastring" << endl;
cout << "3. Rosembrock" << endl;
cout << "4. Griewank" << endl;
cout << "5. Schwefel 1.2" << endl;
cout << "6. Sphere" << endl;
cout << "7. Moving Peaks" << endl;
cin >> index;
switch (index){
case 1:
answer = "ACKLEY";
break;
case 2:
answer = "RASTRING";
break;
case 3:
answer = "ROSEMBROCK";
break;
case 4:
answer = "GRIEWANK";
break;
case 5:
answer = "SCHWEFEL";
break;
case 6:
answer = "SPHERE";
break;
case 7:
answer = "MOVING_PEAKS";
break;
default:
cout << "Opcao Invalida" << endl;
getProblem();
}
return answer;
}
int getAlgorithm(){
int index;
cout << "Select the algorithm:" << endl;
cout << "1. PSO" << endl;
cout << "2. CPSO" << endl;
cin >> index;
return index;
}