forked from GeomScale/volesti
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsos.cpp
More file actions
90 lines (78 loc) · 3.3 KB
/
sos.cpp
File metadata and controls
90 lines (78 loc) · 3.3 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
77
78
79
80
81
82
83
84
85
86
87
88
89
// VolEsti (volume computation and sampling library)
//
// Copyright (c) 2020 Bento Natura
//
// Licensed under GNU LGPL.3, see LICENCE file
#include "NonSymmetricIPM.h"
#include "../../examples/EnvelopeProblemSOS/EnvelopeProblemSOS.h"
#include "spdlog/spdlog.h"
#include "spdlog/cfg/env.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include <fstream>
int main(int const argc, char **argv) {
srand(time(nullptr));
auto console = spdlog::stdout_color_mt("console");
console->info("Logger level is {}", console->level());
// Eigen::setNbThreads(1);
console->info("Num threads: {}", Eigen::nbThreads());
std::ifstream instance_file;
std::ifstream config_file;
std::string instance_file_str;
if (argc < 2) {
console->info("No data file provided. The default file will be used instead.");
instance_file_str = "../config/instance.json";
instance_file.open(instance_file_str);
if (not instance_file.is_open()) {
instance_file_str = "config/instance.json";
instance_file.open(instance_file_str);
}
if (not instance_file.is_open()) {
console->error("Could not locate file.");
return 1;
}
} else {
instance_file_str = argv[1];
instance_file.open(std::string(instance_file_str));
if (not instance_file.is_open()) {
console->error("Could not locate file {}", argv[1]);
return 1;
}
}
std::string config_file_str;
if (argc < 3) {
console->info("No configuration file provided. The default file will be used instead.");
config_file_str = "../../../include/sos/config/config.json";
config_file.open(config_file_str);
if (not config_file.is_open()) {
config_file_str = "../../include/sos/config/config.json";
config_file.open(config_file_str);
}
if (not config_file.is_open()) {
console->error("Could not locate file.");
return 1;
}
} else {
config_file_str = argv[2];
config_file.open(config_file_str);
if (not config_file.is_open()) {
console->error("Could not locate config file {}", argv[2]);
return 1;
}
}
EnvelopeProblemSOS<double> envelopeProblemSos(instance_file_str, config_file_str);
Instance<double> instance_interp = envelopeProblemSos.construct_SOS_instance();
NonSymmetricIPM<double> sos_solver_interp(instance_interp, config_file_str);
int outcome = sos_solver_interp.run_solver();
if(outcome == NonSymmetricIPM<double>::Termination::SUCCESS){
envelopeProblemSos.print_solution(sos_solver_interp.get_solution());
envelopeProblemSos.plot_polynomials_and_solution(sos_solver_interp.get_solution());
} else if (sos_solver_interp._type_cast_if_unsuccessful) {
console->error("Switch to more precise double type");
NonSymmetricIPM<long double> *long_double_solver = sos_solver_interp.cast_with_product_barrier<long double>();
long_double_solver->run_solver();
Solution<long double> long_double_sol = long_double_solver->get_solution();
envelopeProblemSos.print_solution(long_double_sol.cast<double>());
envelopeProblemSos.plot_polynomials_and_solution(long_double_sol.cast<double>());
}
return 0;
}