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