-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
43 lines (40 loc) · 1.03 KB
/
main.cpp
File metadata and controls
43 lines (40 loc) · 1.03 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
#include <iostream>
#include <cstring>
#include "knapsackProblem.h"
#include "dp.h"
#include "ga.h"
using namespace std;
int main(int argc, char* argv[]) {
if (argc != 2) {
printf("ilegal command line\n");
return 1;
}
cout << atoi(argv[1]) << endl;
KnapSackProblem problem(atoi(argv[1]));
problem.WriteInputFile();
int* ans;
ans = (int*)malloc(sizeof(int) * problem.n);
memset(ans, 0, sizeof(int) * problem.n);
// DP
ofstream writing_file;
DP dp(problem);
int score = dp.solve(ans);
writing_file.open("ans.txt");
cout << "score:" << score << endl;
writing_file << "score:" << score << endl;
for (int i = 0; i < problem.n; i++) {
cout << ans[i] << " ";
writing_file << ans[i] << " ";
}
writing_file << endl;
cout << endl;
writing_file.close();
// GA
GA ga(problem);
score = ga.solve(ans);
cout << "score:" << score << endl;
for (int i = 0; i < problem.n; i++) {
cout << ans[i] << " ";
}
cout << endl;
}