forked from Zagrael/TGOC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
102 lines (81 loc) · 1.85 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 <fstream>
#include <string>
#include "QAP.h"
using namespace std;
const char* FILE_DATA = "../instances/nug12.dat";
const char* FILE_SOLUTION = "../instances/nug12.sln";
//const int N_MAX = 1000;
int n;
int f[N_MAX][N_MAX];
int d[N_MAX][N_MAX];
int objectiveValue;
int sol[N_MAX];
bool readData() {
ifstream in(FILE_DATA);
if(!in) {
cout << "Data file not open !" << endl;
return false;
}
// Number of data
in >> n;
// Distances matrix
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
in >> d[i][j];
}
}
// Flow matrix
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
in >> f[i][j];
}
}
in.close();
return true;
}
bool readSolution() {
ifstream in(FILE_SOLUTION);
if(!in) {
cout << "Solution file not open !" << endl;
return false;
}
// Number of data
in >> n;
// Objective value
in >> objectiveValue;
// Solution vector
for(int i = 0; i < n; i++) {
in >> sol[i];
}
in.close();
return true;
}
int main() {
cout << "Hello, World!" << endl;
// Read inputs
if(!readData()) return -1;
cout << "Distances matrix : " << endl;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cout << " " << d[i][j];
}
cout << endl;
}
cout << "Flow matrix : " << endl;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cout << " " << f[i][j];
}
cout << endl;
}
// Read the solution
if(!readSolution()) return -1;
cout << "n = " << n << endl;
cout << "Objective value : " << objectiveValue << endl;
cout << "Optimal solution :";
for(int i = 0; i < n; i++) {
cout << " " << sol[i];
}
return 0;
}