-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEGAResult.cpp
50 lines (47 loc) · 1.31 KB
/
EGAResult.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
// EGAResult.cpp: îïðåäåëÿåò òî÷êó âõîäà äëÿ êîíñîëüíîãî ïðèëîæåíèÿ.
//
#include "stdafx.h"
#include "GeneticAlgorithm.h"
#include <fstream>
//#include "tests.h"
/*1 5 24
2 9 4
3 20 14
4 29 10
5 19 12
6 30 15
7 27 27
8 9 8
9 23 17
10 6 13
11 10 13
12 9 19
13 22 13
14 9 7
15 6 6*/
int main()
{
srand(5);
std::ofstream out("log.txt");
std::clog.rdbuf(out.rdbuf());
vector<BackpackObject> objects;
int maxW = 65;
vector<weightvalue> weights ={24, 4, 14, 10, 12, 15, 27, 8, 17, 13, 13, 19, 13, 7, 6};
vector<weightvalue> costs = { 5, 9, 20, 29, 19, 30, 27, 9, 23, 6, 10, 9, 22, 9, 6 };
cout << "Things" << endl;
for (size_t i = 0; i < 50; i++)
{
costvalue cost =/* costs[i];*/ rand() % 29 + 1;
weightvalue weight =/* weights[i];*/ rand() % 20 + 1;
cout << i + 1 << " cost:" << cost << " weight:" << weight << endl;
objects.push_back(BackpackObject(weight,cost));
//objects.push_back(BackpackObject(weights[i],costs[i]));
}
cout << "Max weight:" << maxW << endl;
cout << "Parents in populations:" << 50 << endl;
cout << "Max iterations:"<<100 << endl;
GeneticAlgorithm alg = GeneticAlgorithm(50,100);
cout << alg.find(objects, maxW);
getchar();
return 0;
}