ZonoOpt v2.0.1
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{
20
26{
27 // general settings
28
30 bool verbose = false;
31
34
36 double t_max = std::numeric_limits<double>::max();
37
38 // ADMM settings
39
41 int k_max_admm = 5000;
42
44 zono_float rho = static_cast<zono_float>(10.0);
45
47 zono_float eps_dual = static_cast<zono_float>(1e-2);
48
50 zono_float eps_prim = static_cast<zono_float>(1e-3);
51
53 int k_inf_check = 10;
54
56 bool inf_norm_conv = true;
57
60
63
64 // mixed integer settings
65
67 int search_mode = 0;
68
70 bool polish = true;
71
73 zono_float eps_dual_search = static_cast<zono_float>(1e-1);
74
77
79 zono_float eps_r = static_cast<zono_float>(1e-2);
80
82 zono_float eps_a = static_cast<zono_float>(1e-1);
83
85 int k_max_bnb = static_cast<int>(1e5);
86
89
91 int max_nodes = static_cast<int>(1e5);
92
95
96 // validity check
102 bool settings_valid() const
103 {
104 const bool general_valid = t_max > 0 && verbosity_interval > 0;
105 const bool admm_valid = (rho > 0 && k_max_admm > 0 &&
106 eps_dual >= 0 && eps_prim >= 0 && k_inf_check >= 0 && contractor_iter > 0);
107 const bool mi_valid = (eps_r >= 0 && eps_a >= 0 && eps_dual_search > 0 && eps_prim_search > 0 &&
109 (search_mode == 0 || search_mode == 1));
110
111 return (general_valid && admm_valid && mi_valid);
112 }
113
119 std::string print() const
120 {
121 std::stringstream ss;
122 ss << "OptSettings structure: " << std::endl;
123 ss << " verbose: " << (verbose ? "true" : "false") << std::endl;
124 ss << " verbosity_interval: " << verbosity_interval << std::endl;
125 ss << " t_max: " << t_max << std::endl;
126 ss << " k_max_admm: " << k_max_admm << std::endl;
127 ss << " rho: " << rho << std::endl;
128 ss << " eps_dual: " << eps_dual << std::endl;
129 ss << " eps_prim: " << eps_prim << std::endl;
130 ss << " k_inf_check: " << k_inf_check << std::endl;
131 ss << " inf_norm_conv: " << (inf_norm_conv ? "true" : "false") << std::endl;
132 ss << " use_interval_contractor: " << (use_interval_contractor ? "true" : "false") << std::endl;
133 ss << " contractor_iter: " << contractor_iter << std::endl;
134 ss << " search_mode: " << search_mode << std::endl;
135 ss << " polish: " << polish << std::endl;
136 ss << " eps_dual_search: " << eps_dual_search << std::endl;
137 ss << " eps_prim_search: " << eps_prim_search << std::endl;
138 ss << " eps_r: " << eps_r << std::endl;
139 ss << " eps_a: " << eps_a << std::endl;
140 ss << " k_max_bnb: " << k_max_bnb << std::endl;
141 ss << " n_threads_bnb: " << n_threads_bnb << std::endl;
142 ss << " max_nodes: " << max_nodes << std::endl;
143 ss << " contractor_tree_search_depth: " << contractor_tree_search_depth;
144 return ss.str();
145 }
146};
147
153{
154 // general
155
157 Eigen::Vector<zono_float, -1> z;
158
160 zono_float J = -std::numeric_limits<zono_float>::infinity();
161
163 double run_time = 0.0;
164
166 double startup_time = 0.0;
167
169 int iter = 0;
170
172 bool converged = false;
173
175 bool infeasible = false;
176
177 // admm-specific
178
180 Eigen::Vector<zono_float, -1> x;
181
183 Eigen::Vector<zono_float, -1> u;
184
186 zono_float primal_residual = std::numeric_limits<zono_float>::infinity();
187
189 zono_float dual_residual = std::numeric_limits<zono_float>::infinity();
190
196 std::string print() const
197 {
198 std::stringstream ss;
199 ss << "OptSolution structure:" << std::endl;
200 ss << " z: vector of length " << z.size() << std::endl;
201 ss << " J: " << J << std::endl;
202 ss << " run_time: " << run_time << std::endl;
203 ss << " startup_time: " << startup_time << std::endl;
204 ss << " iter: " << iter << std::endl;
205 ss << " converged: " << (converged ? "true" : "false") << std::endl;
206 ss << " infeasible: " << (infeasible ? "true" : "false") << std::endl;
207 ss << " x: vector of length " << x.size() << std::endl;
208 ss << " u: vector of length " << u.size() << std::endl;
209 ss << " primal_residual: " << primal_residual << std::endl;
210 ss << " dual_residual: " << dual_residual << std::endl;
211 return ss.str();
212 }
213};
214
215
216} // end namespace ZonoOpt
217
218#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:26
bool polish
flag to perform solution polishing
Definition SolverDataStructures.hpp:70
int k_inf_check
check infeasibility every k_inf_check iterations
Definition SolverDataStructures.hpp:53
bool use_interval_contractor
flag to use interval contractor for constraint tightening / implication
Definition SolverDataStructures.hpp:59
double t_max
max time for optimization
Definition SolverDataStructures.hpp:36
int k_max_bnb
max number of branch-and-bound iterations
Definition SolverDataStructures.hpp:85
zono_float eps_r
relative convergence tolerance
Definition SolverDataStructures.hpp:79
zono_float eps_a
absolute convergence tolerance
Definition SolverDataStructures.hpp:82
bool verbose
display optimization progress
Definition SolverDataStructures.hpp:30
std::string print() const
displays settings as string
Definition SolverDataStructures.hpp:119
int n_threads_bnb
max threads for branch and bound
Definition SolverDataStructures.hpp:88
zono_float eps_prim_search
primal residual convergence tolerance during branch and bound and search
Definition SolverDataStructures.hpp:76
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:94
zono_float eps_prim
primal convergence tolerance
Definition SolverDataStructures.hpp:50
bool inf_norm_conv
use infinity norm for convergence check (if false, scaled 2-norm is used)
Definition SolverDataStructures.hpp:56
int verbosity_interval
print every verbose_interval iterations
Definition SolverDataStructures.hpp:33
zono_float rho
admm penalty parameter, higher prioritizes feasibility during iterations, lower prioritizes optimalit...
Definition SolverDataStructures.hpp:44
int k_max_admm
max admm iterations
Definition SolverDataStructures.hpp:41
zono_float eps_dual
dual convergence tolerance
Definition SolverDataStructures.hpp:47
int max_nodes
terminate if more than this many nodes are in branch and bound queue
Definition SolverDataStructures.hpp:91
int search_mode
0: best first, 1: best dive
Definition SolverDataStructures.hpp:67
zono_float eps_dual_search
dual residual convergence tolerance during branch and bound and search
Definition SolverDataStructures.hpp:73
bool settings_valid() const
Checks whether settings struct is valid.
Definition SolverDataStructures.hpp:102
int contractor_iter
number of interval contractor iterations
Definition SolverDataStructures.hpp:62
Solution data structure for optimization routines in ZonoOpt library.
Definition SolverDataStructures.hpp:153
zono_float dual_residual
dual residual, corresponds to optimality
Definition SolverDataStructures.hpp:189
bool infeasible
true if optimization problem is provably infeasible
Definition SolverDataStructures.hpp:175
Eigen::Vector< zono_float, -1 > x
ADMM primal variable, approximately equal to z when converged.
Definition SolverDataStructures.hpp:180
Eigen::Vector< zono_float, -1 > z
solution vector
Definition SolverDataStructures.hpp:157
double run_time
time to compute solution
Definition SolverDataStructures.hpp:163
std::string print() const
displays solution as string
Definition SolverDataStructures.hpp:196
zono_float J
objective
Definition SolverDataStructures.hpp:160
zono_float primal_residual
primal residual, corresponds to feasibility
Definition SolverDataStructures.hpp:186
int iter
number of iterations
Definition SolverDataStructures.hpp:169
double startup_time
time to factorize matrices and run interval contractors
Definition SolverDataStructures.hpp:166
bool converged
true if optimization has converged
Definition SolverDataStructures.hpp:172
Eigen::Vector< zono_float, -1 > u
ADMM dual variable.
Definition SolverDataStructures.hpp:183