This repository was archived by the owner on Jun 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
48 lines (44 loc) · 1.31 KB
/
main.cpp
File metadata and controls
48 lines (44 loc) · 1.31 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
#include <iostream>
#include <string>
#include <fstream>
#include "Function.h"
#include "Vector.h"
#include "Particle.h"
#include "PSO.h"
#include "SwarmGenerator.h"
using namespace std;
void studentExample(){
SwarmGenerationProperties sgp;
defaultSettings(sgp);
toFile("studentExample.txt", generateSwarm(sgp, 110));
PSO* pso1 = new PSO("studentExample.txt");
pso1->setMaxV(10);
cout << "Population" << endl;
for(int i=0; i < 10; i++){
cout << "Particle " << i << ": "<< pso1->getParticle(i)->toString() << endl;
}
cout << "Manual Loop" << endl;
for(int i=0; i < 20; i++){
cout << "Generation " << i << endl;
Particle best = pso1->run(Function());
for(int j=0; j < 10; j++){
cout << "\tParticle " << j << ": " << pso1->getParticles()[j]->toString() << endl;
}
cout << "Best particle: " << best.toString() << endl;
cout << endl;
}
delete pso1;
pso1 = new PSO("studentExample.txt");
pso1->setMaxV(10);
Particle** results = pso1->run(20, Function());
for(int i=0; i < 20; i++){
cout << "Generation " << i << " best particle: " << results[i]->toString() << endl;
delete results[i];
}
delete [] results;
delete pso1;
}
int main(int argc, char const *argv[])
{
studentExample();
}