-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
113 lines (91 loc) · 2.13 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
103
104
105
106
107
108
109
110
111
112
#include <fstream>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include "depot.hpp"
#include "customer.hpp"
#include "geneticAlgorithm.hpp"
int main(int argc, char *argv[])
{
srand(1999);
if (argc <= 1)
{
return -1;
}
std::string filename = argv[1];
std::ifstream file(filename);
std::stringstream fileStream;
fileStream << file.rdbuf();
std::string line;
std::getline(fileStream, line);
std::istringstream is(line);
int m, n, t;
is >> m >> n >>t;
is.clear();
is.seekg(0);
std::vector<Depot> depots;
std::vector<Customer> customers;
for(int i = 1; i <= t; ++i)
{
std::getline(fileStream, line);
std::istringstream is2(line);
int D, Q;
is2 >> D >> Q;
depots.push_back(Depot(i, D, Q));
}
int scale[4] = {INT_MAX, INT_MAX, INT_MIN, INT_MIN};
for(int _ = 0; _<n; _++)
{
int i, x, y, d, q;
std::getline(fileStream, line);
std::istringstream is2(line);
is2 >> i >> x >> y >> d >> q;
customers.push_back(Customer(i, x, y, d, q));
if (x< scale[0])
{
scale[0] = x;
}
if (y< scale[1])
{
scale[1] = y;
}
if (x> scale[2])
{
scale[2] = x;
}
if (y> scale[3])
{
scale[3] = y;
}
}
for(int i = 0; i<t; i++)
{
int x, y, dc;
std::getline(fileStream, line);
std::istringstream is2(line);
is2 >> dc >> x >> y ;
depots[i].addCoordinates(x, y);
if (x< scale[0])
{
scale[0] = x;
}
if (y< scale[1])
{
scale[1] = y;
}
if (x> scale[2])
{
scale[2] = x;
}
if (y> scale[3])
{
scale[3] = y;
}
}
GeneticAlgorithm ga(depots, customers, scale, m);
ga.run(5000, 5000, 400);
//ga.run(30000, 200);
//ga.run(10000, 200);
return 0;
}