11#include "delpi/delpi.h"
12#include "delpi/util/error.h"
15 "file,solver,result,delta,actual_delta,precision,iterations,refinements,obj_lb,obj_ub,time_unit,parser_time,solver_" \
17#define CSV_FORMAT "{},{},{},{},{},{},{},{},{},{},s,{},{},{}"
18#define CSV_PARTIAL_FORMAT "{},{},partial-{},{},{},{},{},{},{},{},s,{},{},{}"
23 const std::vector<mpq_class>&,
const mpq_class& obj_lb,
const mpq_class& obj_ub) {
24 if (lp_solver.config().silent())
return;
26 const mpq_class actual_delta = obj_ub - obj_lb;
29 DELPI_ASSERT(actual_delta <= config.delta(),
"Expected actual delta to be <= delta");
32 fmt::println(CSV_FORMAT, config.filename(), config.lp_solver(), result, config.delta(), actual_delta.get_d(),
39 DELPI_ASSERT(actual_delta == 0,
"Expected actual delta to be 0");
40 fmt::println(
"{}, objective value = {} ( = {})", result, obj_lb, obj_lb.get_d());
43 DELPI_ASSERT(actual_delta > 0,
"Expected actual delta to be > 0");
44 fmt::println(
"{} with delta = {} ( = {}), range = [{}, {}] ( = [{}, {}])", result, actual_delta.get_d(),
45 actual_delta, obj_lb, obj_ub, obj_lb.get_d(), obj_ub.get_d());
48 fmt::println(
"{}", result);
50 if (config.with_timings()) {
53 if (config.produce_models()) fmt::println(
"Model: {}", lp_solver.model(x));
54 std::cout << std::flush;
58 const std::vector<mpq_class>&,
const mpq_class& obj_lb,
const mpq_class& obj_ub) {
59 if (lp_solver.config().silent())
return true;
61 const mpq_class actual_delta = obj_ub - obj_lb;
64 DELPI_ASSERT(actual_delta > lp_solver.config().delta(),
"Expected diff to be > delta");
67 fmt::println(CSV_PARTIAL_FORMAT, config.filename(), config.lp_solver(), result, actual_delta.get_d(),
69 obj_lb.get_d(), obj_ub.get_d(), stats.
parser_stats.timer().seconds(),
70 stats.
solver_stats.timer().seconds(), global_timer.seconds());
73 fmt::println(
"PARTIAL: {} with delta = {} ( = {}), range = [{}, {}]", result, actual_delta.get_d(), actual_delta,
75 if (config.with_timings()) {
78 if (config.produce_models()) fmt::println(
"Model: {}", lp_solver.model(x));
79 std::cout << std::flush;
84 if (lp_solver.config().silent())
return;
90 fmt::println(CSV_PARTIAL_FORMAT, config.filename(), config.lp_solver(), result,
"",
"", stats.
precision,
92 stats.
solver_stats.timer().seconds(), global_timer.seconds());
95 fmt::println(
"Interrupted: {}", result);
96 if (config.with_timings()) {
99 std::cout << std::flush;
102int main(
const int argc,
const char* argv[]) {
106 parser.
Parse(argc, argv);
113 const std::unique_ptr lp_solver{delpi::LpSolver::GetInstance(config)};
114 lp_solver->m_solve_cb() = &OnSolve;
115 lp_solver->m_partial_solve_cb() = &OnPartialSolve;
117 if (!lp_solver->Parse()) {
118 std::cerr <<
"Error parsing the input" << std::endl;
123 if (config.csv()) std::cout << CSV_HEADER << std::endl;
125 if (config.dry_run()) {
126 DELPI_INFO(
"Dry run enabled, skipping solving the LP problem");
132 mpq_class delta{config.delta()};
135 if (config.silent())
return ExitCode(result);
138 if (!lp_solver->CheckAgainstExpected(result)) {
139 std::cerr <<
"WARNING: Expected " << lp_solver->expected() <<
" but got " << result << std::endl;
142 if (lp_solver->Verify())
143 std::cout <<
"Model correctly satisfies the input" << std::endl;
145 std::cerr <<
"WARNING: Model does not satisfy the input" << std::endl;
Used to parse command line arguments and produce a corresponding Config object to be used throughout ...
void Parse(int argc, const char **argv)
Parse the command line arguments.
Config ToConfig() const
Convert the parser to a Config.
Simple dataclass used to store the configuration of the program.
Facade class that hides the underlying LP solver used by delpi.
The TimeGuard wraps a timer object and pauses it when the guard object is destructed.
Timer class using the a steady clock.
LpResult
Possible outcomes of the LP solver.
@ DELTA_OPTIMAL
The delta-relaxation of the problem is optimal.
@ OPTIMAL
The problem is optimal.
@ UNSOLVED
The solver has not yet been run.
bool IsFeasible(const LpResult result)
Check if the result obtained by the LpSolver implies that the problem is feasible.
int ExitCode(const LpResult result)
Convert the result in.
Collection of statistics for the LP solver.
IterationStats solver_stats
Time spent in the solver and number of iterations.
std::size_t precision
Number of bits of precision used in the last iteration.
std::size_t refinements
Number of iterative refinements. Only meaningful for iterative refinement solvers.
Stats parser_stats
Time spent in the parser.