-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcalgo.cpp
More file actions
76 lines (65 loc) · 1.76 KB
/
mcalgo.cpp
File metadata and controls
76 lines (65 loc) · 1.76 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
67
68
69
70
71
72
73
74
75
76
#include <fstream>
#include <iostream>
#include <sstream>
#include <ctime>
//#include "Graph.h"
//#include "Gene.h"
#include "Gasolver.h"
using namespace std;
#define INITIAL 1000
#define ITERTIME 5
#define CHILDNUM 40
int main(int argc, char *argv[]) {
clock_t start_time = clock();
clock_t diff_time;
string filePath = argv[1]; // "maxcut.in";
int vtxnum, edgenum;
int v1, v2, weight;
int iteration = 0;
vector<pair<pair<int, int>, int>> we;
Graph gh;
Gasolver gas;
ifstream openFile(filePath.data());
if (openFile.is_open()) {
string line;
int num;
stringstream ss;
getline(openFile, line);
// first line
ss.str(line);
ss >> vtxnum >> edgenum;
ss.clear();
//cout << "vtx: " << vtxnum << endl;
//cout << "edge: " << edgenum << endl;
// other lines
while(getline(openFile, line)) {
ss.str(line);
//cout << "cur_line: " << line << endl;
ss >> v1 >> v2 >> weight;
we.push_back(make_pair(make_pair(v1, v2), weight));
ss.clear();
}
openFile.close();
}
gh = Graph(vtxnum, edgenum, we);
gas = Gasolver(gh, INITIAL);
vector<Gene> gas_vector = gas.get_gene_vector();
//cout << "Graph length: " << gh.get_edges().size() << endl;
//cout << "GAS: " << gas.get_gas_size() << endl;
//for (int j = 0; j < gas.get_gas_size(); j ++) {
// cout << gas_vector[j].get_soln_value() << endl;
//}
do {
//cout << "Hi " << endl;
iteration ++;
//cout << "Hi 1" << endl;
gas = gas.generation(CHILDNUM);
//cout << "Hi 2" << endl;
cout << "iter : " << iteration << "max : " << gas.get_maxcut() << endl;
diff_time = (float) (clock() - start_time) / CLOCKS_PER_SEC;
} while(diff_time <= ITERTIME);
return 0;
}
//Graph string_parser(string fpath) {
//
//}