-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
76 lines (65 loc) · 3.16 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
#include <iostream>
#include <cstring>
#include <cerrno>
#include "Partition.h"
int main(int argc, char* argv[]) {
if(argc == 1) {
std::cerr << "Usage: SimulatedAnnealing.exe 'filename.txt' 'number of steps' 'number of restarts'" << std::endl;
std::cerr << "Use '?' and 'input size' 'input sets' instead of filename to generate a random input" << std::endl;
std::exit(-1);
}
errno = 0;
char* p;
Partition partition;
long num_restarts;
long num_steps;
if(strcmp((char *)(argv[1]), "?") == 0) {
long input_size = strtol(argv[2], &p, 10);
if (errno != 0 || *p != '\0' || input_size > INT32_MAX) {
std::cerr << "Invalid format for random input size" << std::endl;
std::cerr << "Usage: SimulatedAnnealing.exe '?' 'input size' 'input sets' 'number of steps' 'number of restarts'" << std::endl;
std::exit(-2);
}
long input_sets = strtol(argv[3], &p, 10);
if (errno != 0 || *p != '\0' || input_size > INT32_MAX) {
std::cerr << "Invalid format for random input size" << std::endl;
std::cerr << "Usage: SimulatedAnnealing.exe '?' 'input size' 'input sets' 'number of steps' 'number of restarts'" << std::endl;
std::exit(-2);
}
partition.generateInput(input_size, input_sets);
partition.createInputFile("random_input.txt");
num_steps = strtol(argv[4], &p, 10);
if (errno != 0 || *p != '\0' || num_steps > INT32_MAX) {
std::cerr << "Invalid format for simulation steps" << std::endl;
std::cerr << "Usage: SimulatedAnnealing.exe '?' 'input size' 'input sets' 'number of steps' 'number of restarts'" << std::endl;
std::exit(-3);
}
num_restarts = strtol(argv[5], &p, 10);
if (errno != 0 || *p != '\0' || num_restarts > INT32_MAX) {
std::cerr << "Invalid format for simulation restarts" << std::endl;
std::cerr << "Usage: SimulatedAnnealing.exe '?' 'input size' 'input sets' 'number of steps' 'number of restarts'" << std::endl;
std::exit(-4);
}
} else {
num_steps = strtol(argv[2], &p, 10);
if (errno != 0 || *p != '\0' || num_steps > INT32_MAX) {
std::cerr << "Invalid format for simulation steps" << std::endl;
std::cerr << "Usage: SimulatedAnnealing.exe 'filename.txt' 'number of steps' 'number of restarts'" << std::endl;
std::exit(-3);
}
num_restarts = strtol(argv[3], &p, 10);
if (errno != 0 || *p != '\0' || num_restarts > INT32_MAX) {
std::cerr << "Invalid format for simulation restarts" << std::endl;
std::cerr << "Usage: SimulatedAnnealing.exe 'filename.txt' 'number of steps' 'number of restarts'" << std::endl;
std::exit(-4);
}
}
partition.simulate(num_steps,num_restarts);
std::cout << partition.getSolutionCost(partition.getBestSolution()).distance << std::endl << std::endl;
for(const std::list<Point>& set : partition.getBestSolution()) {
for(const Point& point : set) {
std::cout << point << std::endl;
}
std::cout << std::endl;
}
}