ZonoOpt 2.4.0
Loading...
Searching...
No Matches
SCIPSettings.hpp
Go to the documentation of this file.
1#ifndef ZONOOPT_SCIP_SETTINGS_HPP_
2#define ZONOOPT_SCIP_SETTINGS_HPP_
3
18#include <map>
19#include <optional>
20#include <sstream>
21#include <stdexcept>
22#include <string>
23
25
26namespace ZonoOpt
27{
28 namespace detail
29 {
30 bool scip_available();
31 const std::string& scip_unavailable_reason();
32 }
33
45 {
46 // ---- Limits ----
47 std::optional<double> TimeLimit;
48 std::optional<double> MemLimit;
49 std::optional<int> SolutionLimit;
50 std::optional<int> NodeLimit;
51
52 // ---- Tolerances ----
53 std::optional<double> MIPGap;
54 std::optional<double> MIPGapAbs;
55 std::optional<double> FeasibilityTol;
56
57 // ---- Behavior ----
58 std::optional<int> Threads;
59 std::optional<int> Seed;
60
61 // ---- Display ----
63 std::optional<int> VerbLevel;
64
65 // ---- Escape-hatch maps for any SCIP parameter not exposed above ----
66 // Keys are SCIP's documented parameter names (slash-separated paths),
67 // e.g., real_params["numerics/dualfeastol"] = 1e-9.
68 std::map<std::string, bool> bool_params;
69 std::map<std::string, int> int_params;
70 std::map<std::string, long long> longint_params;
71 std::map<std::string, double> real_params;
72 std::map<std::string, char> char_params;
73 std::map<std::string, std::string> str_params;
74
75 // ---- SolverSettings interface ------------------------------------------
76 std::unique_ptr<SolverSettings> clone() const override
77 {
78 return std::make_unique<SCIPSettings>(*this);
79 }
80
81 void verify_available() const override
82 {
83 if (!detail::scip_available())
84 {
85 throw std::runtime_error("SCIPSettings: " + detail::scip_unavailable_reason());
86 }
87 }
88
89 // ---- Debug print --------------------------------------------------------
90 std::string print() const
91 {
92 std::stringstream ss;
93 ss << "SCIPSettings (unset fields use SCIP defaults):\n";
94 auto opt_int = [&](const char* n, const std::optional<int>& v) { if (v) ss << " " << n << " = " << *v << "\n"; };
95 auto opt_dbl = [&](const char* n, const std::optional<double>& v) { if (v) ss << " " << n << " = " << *v << "\n"; };
96
97 opt_dbl("TimeLimit", TimeLimit);
98 opt_dbl("MemLimit", MemLimit);
99 opt_int("SolutionLimit", SolutionLimit);
100 opt_int("NodeLimit", NodeLimit);
101 opt_dbl("MIPGap", MIPGap);
102 opt_dbl("MIPGapAbs", MIPGapAbs);
103 opt_dbl("FeasibilityTol", FeasibilityTol);
104 opt_int("Threads", Threads);
105 opt_int("Seed", Seed);
106 opt_int("VerbLevel", VerbLevel);
107
108 for (const auto& kv : bool_params) ss << " [bool] " << kv.first << " = " << (kv.second ? "true" : "false") << "\n";
109 for (const auto& kv : int_params) ss << " [int] " << kv.first << " = " << kv.second << "\n";
110 for (const auto& kv : longint_params) ss << " [longint] " << kv.first << " = " << kv.second << "\n";
111 for (const auto& kv : real_params) ss << " [real] " << kv.first << " = " << kv.second << "\n";
112 for (const auto& kv : char_params) ss << " [char] " << kv.first << " = '" << kv.second << "'\n";
113 for (const auto& kv : str_params) ss << " [str] " << kv.first << " = \"" << kv.second << "\"\n";
114 return ss.str();
115 }
116
122
123 std::string solver_name() const override
124 {
125 return "SCIP";
126 }
127 };
128
137 {
139 int status = 0;
140
142 long long node_count = 0;
143
145 double mip_gap = 0.0;
146
148 double dual_bound = 0.0;
149
151 int n_sols_pool = 0;
152
153 std::shared_ptr<ExternalSolverResults> clone() const override
154 {
155 return std::make_shared<SCIPSolverResults>(*this);
156 }
157
158 std::string print() const override
159 {
160 std::stringstream ss;
161 ss << "SCIPSolverResults:\n";
162 ss << " status: " << status << "\n";
163 ss << " node_count: " << node_count << "\n";
164 ss << " mip_gap: " << mip_gap << "\n";
165 ss << " dual_bound: " << dual_bound << "\n";
166 ss << " n_sols_pool: " << n_sols_pool << "\n";
167 return ss.str();
168 }
169 };
170} // namespace ZonoOpt
171
172#endif
int n
Definition GurobiSolver.cpp:83
Optimization settings and solution data structures for ZonoOpt library.
Definition ZonoOpt.hpp:58
Abstract base for external-solver-specific solution metadata.
Definition SolverDataStructures.hpp:267
Settings for the dynamically-loaded SCIP solver backend.
Definition SCIPSettings.hpp:45
SCIPSettings()
Construct a new SCIPSettings object.
Definition SCIPSettings.hpp:121
std::string solver_name() const override
Return name of the solver backend selected by this settings type, e.g., "ZonoOpt",...
Definition SCIPSettings.hpp:123
std::optional< double > MIPGapAbs
absolute MIP optimality gap ("limits/absgap")
Definition SCIPSettings.hpp:54
std::map< std::string, std::string > str_params
Definition SCIPSettings.hpp:73
std::string print() const
Definition SCIPSettings.hpp:90
std::map< std::string, char > char_params
Definition SCIPSettings.hpp:72
std::optional< double > TimeLimit
wall-clock time limit in seconds ("limits/time")
Definition SCIPSettings.hpp:47
std::map< std::string, double > real_params
Definition SCIPSettings.hpp:71
std::optional< double > FeasibilityTol
feasibility tolerance ("numerics/feastol")
Definition SCIPSettings.hpp:55
std::optional< int > SolutionLimit
stop after this many MIP solutions ("limits/solutions")
Definition SCIPSettings.hpp:49
std::map< std::string, bool > bool_params
Definition SCIPSettings.hpp:68
std::optional< int > Seed
random seed shift ("randomization/randomseedshift")
Definition SCIPSettings.hpp:59
std::optional< double > MemLimit
memory limit in MB ("limits/memory")
Definition SCIPSettings.hpp:48
std::optional< int > NodeLimit
max B&B nodes ("limits/totalnodes" → applied to "limits/nodes")
Definition SCIPSettings.hpp:50
std::map< std::string, int > int_params
Definition SCIPSettings.hpp:69
std::optional< int > Threads
worker threads ("parallel/maxnthreads"); SCIP default is sequential unless built with parallel
Definition SCIPSettings.hpp:58
std::optional< int > VerbLevel
SCIP verbosity 0..5 ("display/verblevel"); 0 = silent. SCIP default is 4.
Definition SCIPSettings.hpp:63
void verify_available() const override
Verify the solver backend selected by this settings type is usable.
Definition SCIPSettings.hpp:81
std::optional< double > MIPGap
relative MIP optimality gap ("limits/gap")
Definition SCIPSettings.hpp:53
std::unique_ptr< SolverSettings > clone() const override
Polymorphic copy. Must be overridden by every concrete subclass.
Definition SCIPSettings.hpp:76
std::map< std::string, long long > longint_params
Definition SCIPSettings.hpp:70
Solver-native solution metadata produced by the SCIP backend.
Definition SCIPSettings.hpp:137
int status
Raw SCIP_Status code (see SCIP's status enum; layout differs across versions).
Definition SCIPSettings.hpp:139
std::shared_ptr< ExternalSolverResults > clone() const override
Polymorphic copy; required so callers can deep-copy an OptSolution.
Definition SCIPSettings.hpp:153
double dual_bound
Best dual bound found (SCIPgetDualbound).
Definition SCIPSettings.hpp:148
long long node_count
Total branch-and-bound nodes explored (SCIPgetNTotalNodes).
Definition SCIPSettings.hpp:142
double mip_gap
Relative gap at termination (SCIPgetGap). +infinity if no primal bound found.
Definition SCIPSettings.hpp:145
int n_sols_pool
Number of feasible solutions in SCIP's solution storage at termination (SCIPgetNSols).
Definition SCIPSettings.hpp:151
std::string print() const override
Human-readable summary of the solver-specific fields.
Definition SCIPSettings.hpp:158
Abstract base for all solver settings.
Definition SolverDataStructures.hpp:35