Turbo Constraint Solver
Loading...
Searching...
No Matches
statistics.hpp
Go to the documentation of this file.
1// Copyright 2021 Pierre Talbot
2
3#ifndef TURBO_STATISTICS_HPP
4#define TURBO_STATISTICS_HPP
5
6#include <chrono>
7#include <algorithm>
8#include "battery/utility.hpp"
9#include "battery/allocator.hpp"
10#include "lala/logic/ast.hpp"
11
12inline void print_memory_statistics(const char* key, size_t bytes) {
13 printf("%% %s=%zu [", key, bytes);
14 if(bytes < 1000 * 1000) {
15 printf("%.2fKB", static_cast<double>(bytes) / 1000);
16 }
17 else if(bytes < 1000 * 1000 * 1000) {
18 printf("%.2fMB", static_cast<double>(bytes) / (1000 * 1000));
19 }
20 else {
21 printf("%.2fGB", static_cast<double>(bytes) / (1000 * 1000 * 1000));
22 }
23 printf("]\n");
24}
25
26struct Statistics {
27 size_t variables;
30 int64_t duration;
32 size_t nodes;
33 size_t fails;
34 size_t solutions;
35 size_t depth_max;
36 size_t exhaustive;
46
57
58 CUDA Statistics(): Statistics(0,0,false) {}
59 Statistics(const Statistics&) = default;
60 Statistics(Statistics&&) = default;
61
77
78private:
79 CUDA void print_stat(const char* name, size_t value) const {
80 printf("%%%%%%mzn-stat: %s=%" PRIu64 "\n", name, value);
81 }
82
83 CUDA void print_stat(const char* name, double value) const {
84 printf("%%%%%%mzn-stat: %s=%lf\n", name, value);
85 }
86
87 CUDA double to_sec(int64_t dur) const {
88 return ((double) dur / 1000.);
89 }
90
91public:
92 CUDA void print_mzn_statistics() const {
93 print_stat("nodes", nodes);
94 print_stat("failures", fails);
95 print_stat("variables", variables);
96 print_stat("propagators", constraints);
97 print_stat("peakDepth", depth_max);
98 print_stat("initTime", to_sec(interpretation_duration));
99 print_stat("solveTime", to_sec(duration));
100 print_stat("num_solutions", solutions);
101 print_stat("eps_num_subproblems", eps_num_subproblems);
102 print_stat("eps_solved_subproblems", eps_solved_subproblems);
103 print_stat("eps_skipped_subproblems", eps_skipped_subproblems);
104 print_stat("num_blocks_done", num_blocks_done);
105 print_stat("fixpoint_iterations", fixpoint_iterations);
106 print_stat("eliminated_variables", eliminated_variables);
107 print_stat("eliminated_formulas", eliminated_formulas);
108#ifdef TURBO_PROFILE_MODE
109 print_stat("search_time", search_time);
110 print_stat("propagation_time", propagation_time);
111#endif
112 }
113
114 CUDA void print_mzn_end_stats() const {
115 printf("%%%%%%mzn-stat-end\n");
116 }
117
118 CUDA void print_mzn_objective(const auto& obj, bool is_minimization) const {
119 printf("%%%%%%mzn-stat: objective=");
120 if(is_minimization) {
121 obj.lb().template deinterpret<lala::TFormula<battery::standard_allocator>>().print(false);
122 }
123 else {
124 obj.ub().template deinterpret<lala::TFormula<battery::standard_allocator>>().print(false);
125 }
126 printf("\n");
127 }
128
129 CUDA void print_mzn_separator() const {
130 printf("----------\n");
131 }
132
133 CUDA void print_mzn_final_separator() const {
134 if(solutions > 0) {
135 if(exhaustive) {
136 printf("==========\n");
137 }
138 }
139 else {
140 assert(solutions == 0);
141 if(exhaustive) {
142 printf("=====UNSATISFIABLE=====\n");
143 }
144 else if(optimization) {
145 printf("=====UNBOUNDED=====\n");
146 }
147 else {
148 printf("=====UNKNOWN=====\n");
149 }
150 }
151 }
152};
153
154#endif
void print_memory_statistics(const char *key, size_t bytes)
Definition statistics.hpp:12
Definition statistics.hpp:26
size_t eps_num_subproblems
Definition statistics.hpp:37
size_t fails
Definition statistics.hpp:33
size_t depth_max
Definition statistics.hpp:35
size_t fixpoint_iterations
Definition statistics.hpp:41
CUDA void print_mzn_statistics() const
Definition statistics.hpp:92
Statistics(Statistics &&)=default
size_t num_blocks_done
Definition statistics.hpp:40
size_t constraints
Definition statistics.hpp:28
size_t eps_solved_subproblems
Definition statistics.hpp:38
CUDA void print_mzn_objective(const auto &obj, bool is_minimization) const
Definition statistics.hpp:118
double search_time
Definition statistics.hpp:44
size_t eps_skipped_subproblems
Definition statistics.hpp:39
CUDA Statistics()
Definition statistics.hpp:58
CUDA void meet(const Statistics &other)
Definition statistics.hpp:62
double propagation_time
Definition statistics.hpp:45
int64_t interpretation_duration
Definition statistics.hpp:31
CUDA void print_mzn_end_stats() const
Definition statistics.hpp:114
Statistics(const Statistics &)=default
size_t eliminated_variables
Definition statistics.hpp:42
CUDA void print_mzn_final_separator() const
Definition statistics.hpp:133
CUDA Statistics(size_t variables, size_t constraints, bool optimization)
Definition statistics.hpp:47
size_t nodes
Definition statistics.hpp:32
size_t eliminated_formulas
Definition statistics.hpp:43
size_t solutions
Definition statistics.hpp:34
size_t variables
Definition statistics.hpp:27
int64_t duration
Definition statistics.hpp:30
CUDA void print_mzn_separator() const
Definition statistics.hpp:129
bool optimization
Definition statistics.hpp:29
size_t exhaustive
Definition statistics.hpp:36