ZonoOpt 2.2.0
Loading...
Searching...
No Matches
SolverDataStructures.hpp
Go to the documentation of this file.
1#ifndef ZONOOPT_SOLVER_DATA_STRUCUTURES_HPP_
2#define ZONOOPT_SOLVER_DATA_STRUCUTURES_HPP_
3
15#include <Eigen/Dense>
16#include <sstream>
17
18namespace ZonoOpt
19{
25 {
26 // general settings
27
29 bool verbose = false;
30
33
35 double t_max = std::numeric_limits<double>::max();
36
37 // ADMM settings
38
40 int k_max_admm = 5000;
41
43 zono_float rho = static_cast<zono_float>(10.0);
44
46 zono_float eps_dual = static_cast<zono_float>(1e-2);
47
49 zono_float eps_prim = static_cast<zono_float>(1e-3);
50
52 int k_inf_check = 10;
53
55 bool inf_norm_conv = true;
56
59
62
63 // mixed integer settings
64
66 int search_mode = 0;
67
69 bool polish = true;
70
73
76
78 zono_float eps_r = static_cast<zono_float>(1e-2);
79
81 zono_float eps_a = static_cast<zono_float>(1e-1);
82
84 int k_max_bnb = static_cast<int>(1e5);
85
88
91
94
96 int max_nodes = static_cast<int>(1e5);
97
100
103
106
108 int k_max_admm_fp_ph1 = 10000;
109
111 int k_max_admm_fp_ph2 = 90000;
112
115
117 zono_float eps_perturb = static_cast<zono_float>(1e-3);
118
120 int k_restart = 5000;
121
123 bool enable_rng_seed = false;
124
126 unsigned int rng_seed = 0;
127
128 // validity check
134 bool settings_valid() const
135 {
136 const bool general_valid = t_max > 0 && verbosity_interval > 0;
137 const bool admm_valid = (rho > 0 && k_max_admm > 0 &&
138 eps_dual >= 0 && eps_prim >= 0 && k_inf_check >= 0 && contractor_iter > 0);
139 const bool mi_valid = (eps_r >= 0 && eps_a >= 0 && eps_dual_search > 0 && eps_prim_search > 0 &&
140 k_max_bnb > 0 && n_threads_bnb >= 0 && n_threads_admm_fp >= 0 && max_nodes > 0 &&
143 (search_mode == 0 || search_mode == 1) &&
144 eps_perturb > 0);
145
146 return (general_valid && admm_valid && mi_valid);
147 }
148
154 std::string print() const
155 {
156 std::stringstream ss;
157 ss << "OptSettings structure: " << std::endl;
158 ss << " verbose: " << (verbose ? "true" : "false") << std::endl;
159 ss << " verbosity_interval: " << verbosity_interval << std::endl;
160 ss << " t_max: " << t_max << std::endl;
161 ss << " k_max_admm: " << k_max_admm << std::endl;
162 ss << " rho: " << rho << std::endl;
163 ss << " eps_dual: " << eps_dual << std::endl;
164 ss << " eps_prim: " << eps_prim << std::endl;
165 ss << " k_inf_check: " << k_inf_check << std::endl;
166 ss << " inf_norm_conv: " << (inf_norm_conv ? "true" : "false") << std::endl;
167 ss << " use_interval_contractor: " << (use_interval_contractor ? "true" : "false") << std::endl;
168 ss << " contractor_iter: " << contractor_iter << std::endl;
169 ss << " search_mode: " << search_mode << std::endl;
170 ss << " polish: " << polish << std::endl;
171 ss << " eps_dual_search: " << eps_dual_search << std::endl;
172 ss << " eps_prim_search: " << eps_prim_search << std::endl;
173 ss << " eps_r: " << eps_r << std::endl;
174 ss << " eps_a: " << eps_a << std::endl;
175 ss << " k_max_bnb: " << k_max_bnb << std::endl;
176 ss << " n_threads_bnb: " << n_threads_bnb << std::endl;
177 ss << " n_threads_admm_fp: " << n_threads_admm_fp << std::endl;
178 ss << " single_threaded_admm_fp: " << (single_threaded_admm_fp ? "true" : "false") << std::endl;
179 ss << " max_nodes: " << max_nodes << std::endl;
180 ss << " contractor_tree_search_depth: " << contractor_tree_search_depth << std::endl;
181 ss << " enable_perturb_admm_fp: " << (enable_perturb_admm_fp ? "true" : "false") << std::endl;
182 ss << " k_max_admm_fp_ph1: " << k_max_admm_fp_ph1 << std::endl;
183 ss << " k_max_admm_fp_ph2: " << k_max_admm_fp_ph2 << std::endl;
184 ss << " cycle_detection_buffer_size: " << cycle_detection_buffer_size << std::endl;
185 ss << " eps_perturb: " << eps_perturb << std::endl;
186 ss << " k_restart: " << k_restart << std::endl;
187 ss << " enable_rng_seed: " << (enable_rng_seed ? "true" : "false") << std::endl;
188 ss << " rng_seed: " << rng_seed << std::endl;
189 ss << " enable_restart_admm_fp: " << (enable_restart_admm_fp ? "true" : "false") << std::endl;
190 return ss.str();
191 }
192 };
193
199 {
200 // general
201
203 Eigen::Vector<zono_float, -1> z;
204
206 zono_float J = -std::numeric_limits<zono_float>::infinity();
207
209 double run_time = 0.0;
210
212 double startup_time = 0.0;
213
215 int iter = 0;
216
218 bool converged = false;
219
221 bool infeasible = false;
222
223 // admm-specific
224
226 Eigen::Vector<zono_float, -1> x;
227
229 Eigen::Vector<zono_float, -1> u;
230
232 zono_float primal_residual = std::numeric_limits<zono_float>::infinity();
233
235 zono_float dual_residual = std::numeric_limits<zono_float>::infinity();
236
242 std::string print() const
243 {
244 std::stringstream ss;
245 ss << "OptSolution structure:" << std::endl;
246 ss << " z: vector of length " << z.size() << std::endl;
247 ss << " J: " << J << std::endl;
248 ss << " run_time: " << run_time << std::endl;
249 ss << " startup_time: " << startup_time << std::endl;
250 ss << " iter: " << iter << std::endl;
251 ss << " converged: " << (converged ? "true" : "false") << std::endl;
252 ss << " infeasible: " << (infeasible ? "true" : "false") << std::endl;
253 ss << " x: vector of length " << x.size() << std::endl;
254 ss << " u: vector of length " << u.size() << std::endl;
255 ss << " primal_residual: " << primal_residual << std::endl;
256 ss << " dual_residual: " << dual_residual << std::endl;
257 return ss.str();
258 }
259 };
260} // end namespace ZonoOpt
261
262#endif
#define zono_float
Defines the floating-point type used in ZonoOpt.
Definition ZonoOpt.hpp:45
Definition ZonoOpt.hpp:58
Settings for optimization routines in ZonoOpt library.
Definition SolverDataStructures.hpp:25
bool polish
flag to perform solution polishing
Definition SolverDataStructures.hpp:69
int k_inf_check
check infeasibility every k_inf_check iterations
Definition SolverDataStructures.hpp:52
int k_restart
perform restart operation if primal residual does not improve over this many iterations in ADMM-FP
Definition SolverDataStructures.hpp:120
bool use_interval_contractor
flag to use interval contractor for constraint tightening / implication
Definition SolverDataStructures.hpp:58
double t_max
max time for optimization
Definition SolverDataStructures.hpp:35
int k_max_bnb
max number of branch-and-bound iterations
Definition SolverDataStructures.hpp:84
unsigned int rng_seed
rng seed for ADMM-FP
Definition SolverDataStructures.hpp:126
bool enable_rng_seed
enable rng seed for ADMM-FP
Definition SolverDataStructures.hpp:123
int cycle_detection_buffer_size
in ADMM-FP, this is the max size of the buffer that checks for cycles
Definition SolverDataStructures.hpp:114
zono_float eps_r
relative convergence tolerance
Definition SolverDataStructures.hpp:78
bool enable_restart_admm_fp
enable restarts (significant perturbations) in ADMM-FP
Definition SolverDataStructures.hpp:105
zono_float eps_a
absolute convergence tolerance
Definition SolverDataStructures.hpp:81
bool verbose
display optimization progress
Definition SolverDataStructures.hpp:29
std::string print() const
displays settings as string
Definition SolverDataStructures.hpp:154
int n_threads_bnb
max threads for branch and bound
Definition SolverDataStructures.hpp:87
zono_float eps_prim_search
primal residual convergence tolerance during branch and bound and search
Definition SolverDataStructures.hpp:75
int contractor_tree_search_depth
when applying interval contractor in branch and bound, this is how deep to search the constraint tree...
Definition SolverDataStructures.hpp:99
zono_float eps_prim
primal convergence tolerance
Definition SolverDataStructures.hpp:49
int k_max_admm_fp_ph2
max ADMM iterations for ADMM-FP phase 2 (no objective)
Definition SolverDataStructures.hpp:111
bool inf_norm_conv
use infinity norm for convergence check (if false, scaled 2-norm is used)
Definition SolverDataStructures.hpp:55
int verbosity_interval
print every verbose_interval iterations
Definition SolverDataStructures.hpp:32
zono_float rho
admm penalty parameter, higher prioritizes feasibility during iterations, lower prioritizes optimalit...
Definition SolverDataStructures.hpp:43
int k_max_admm_fp_ph1
max ADMM iterations for ADMM-FP phase 1 (objective included)
Definition SolverDataStructures.hpp:108
int k_max_admm
max convex admm iterations
Definition SolverDataStructures.hpp:40
zono_float eps_dual
dual convergence tolerance
Definition SolverDataStructures.hpp:46
bool enable_perturb_admm_fp
enable perturbations in ADMM-FP
Definition SolverDataStructures.hpp:102
int max_nodes
terminate if more than this many nodes are in branch and bound queue
Definition SolverDataStructures.hpp:96
zono_float eps_perturb
relative tolerance for cycle detection, triggers perturbation
Definition SolverDataStructures.hpp:117
int search_mode
0: best first, 1: best dive
Definition SolverDataStructures.hpp:66
zono_float eps_dual_search
dual residual convergence tolerance during branch and bound and search
Definition SolverDataStructures.hpp:72
bool settings_valid() const
Checks whether settings struct is valid.
Definition SolverDataStructures.hpp:134
bool single_threaded_admm_fp
enables single-threaded ADMM-FP solution, overrides n_threads_bnb, n_threads_admm_fp
Definition SolverDataStructures.hpp:93
int contractor_iter
number of interval contractor iterations
Definition SolverDataStructures.hpp:61
int n_threads_admm_fp
max threads for ADMM-FP
Definition SolverDataStructures.hpp:90
Solution data structure for optimization routines in ZonoOpt library.
Definition SolverDataStructures.hpp:199
zono_float dual_residual
dual residual, corresponds to optimality
Definition SolverDataStructures.hpp:235
bool infeasible
true if optimization problem is provably infeasible
Definition SolverDataStructures.hpp:221
Eigen::Vector< zono_float, -1 > x
ADMM primal variable, approximately equal to z when converged.
Definition SolverDataStructures.hpp:226
Eigen::Vector< zono_float, -1 > z
solution vector
Definition SolverDataStructures.hpp:203
double run_time
time to compute solution
Definition SolverDataStructures.hpp:209
std::string print() const
displays solution as string
Definition SolverDataStructures.hpp:242
zono_float J
objective
Definition SolverDataStructures.hpp:206
zono_float primal_residual
primal residual, corresponds to feasibility
Definition SolverDataStructures.hpp:232
int iter
number of iterations
Definition SolverDataStructures.hpp:215
double startup_time
time to factorize matrices and run interval contractors
Definition SolverDataStructures.hpp:212
bool converged
true if optimization has converged
Definition SolverDataStructures.hpp:218
Eigen::Vector< zono_float, -1 > u
ADMM dual variable.
Definition SolverDataStructures.hpp:229