OR-Tools  9.6
gscip.h
Go to the documentation of this file.
1 // Copyright 2010-2022 Google LLC
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 // Simplified bindings for the SCIP solver. This is not designed to be used
15 // directly by users, the API is not friendly to a modeler. For most common
16 // cases, use MPSolver instead.
17 //
18 // Notable differences between gSCIP and SCIP:
19 // * Unless callbacks are used, gSCIP only exposes the SCIP stage PROBLEM to
20 // the user through public APIs.
21 // * Instead of the stateful SCIP parameters API, parameters are passed in at
22 // Solve() time and cleared at the end of solve. Parameters that effect
23 // problem creation are thus not supported.
24 // * gSCIP uses std::numeric_limits<double>::infinity(), rather than SCIPs
25 // infinity (a default value of 1e20). Doubles with absolute value >= 1e20
26 // but < inf result in an error. Changing the underlying SCIP's infinity is
27 // not supported.
28 // * absl::Status and absl::StatusOr are used to propagate SCIP errors (and on
29 // a best effort basis, also filter out bad input to gSCIP functions).
30 //
31 // A note on error propagation and reliability:
32 // Many methods on SCIP return an error code. Errors can be triggered by
33 // both invalid input and bugs in SCIP. We propagate these errors back to the
34 // user through gSCIP through Status and StatusOr. If you are solving a single
35 // MIP and you have previously successfully solved similar MIPs, it is unlikely
36 // gSCIP would return any status errors. Depending on your application, CHECK
37 // failing on these errors may be appropriate (e.g. a benchmark that is run by
38 // hand). If you are solving a very large number of MIPs (e.g. in a flume job),
39 // your instances are numerically challenging, or the model/data are drawn from
40 // an unreliable source, or you are running a server that cannot crash, you may
41 // want to try and process these errors instead. Note that on bad instances,
42 // SCIP may still crash, so highly reliable systems should run SCIP in a
43 // separate process.
44 //
45 // NOTE(user): much of the API uses const std::string& instead of
46 // absl::string_view because the underlying SCIP API needs a null terminated
47 // char*.
48 #ifndef OR_TOOLS_GSCIP_GSCIP_H_
49 #define OR_TOOLS_GSCIP_GSCIP_H_
50 
51 #include <cstdint>
52 #include <functional>
53 #include <limits>
54 #include <memory>
55 #include <string>
56 #include <vector>
57 
58 #include "absl/container/flat_hash_map.h"
59 #include "absl/container/flat_hash_set.h"
60 #include "absl/status/status.h"
61 #include "absl/status/statusor.h"
62 #include "absl/strings/string_view.h"
63 #include "absl/types/span.h"
64 #include "ortools/gscip/gscip.pb.h"
65 #include "ortools/gscip/gscip_message_handler.h" // IWYU pragma: export
66 #include "scip/scip.h"
67 #include "scip/scip_prob.h"
68 #include "scip/type_cons.h"
69 #include "scip/type_scip.h"
70 #include "scip/type_var.h"
71 
72 namespace operations_research {
73 
74 using GScipSolution = absl::flat_hash_map<SCIP_VAR*, double>;
75 
76 // The result of GScip::Solve(). Contains the solve status, statistics, and the
77 // solutions found.
78 struct GScipResult {
79  GScipOutput gscip_output;
80  // The number of solutions returned is at most GScipParameters::num_solutions.
81  // They are ordered from best objective value to worst. When
82  // gscip_output.status() is optimal, solutions will have at least one element.
83  std::vector<GScipSolution> solutions;
84  // Of the same size as solutions.
85  std::vector<double> objective_values;
86  // Advanced use below
87 
88  // If the problem was unbounded, a primal ray in the unbounded direction of
89  // the LP relaxation should be produced.
90  absl::flat_hash_map<SCIP_VAR*, double> primal_ray;
91  // TODO(user): add dual support:
92  // 1. The dual solution for LPs.
93  // 2. The dual ray for infeasible LP/MIPs.
94 };
95 
96 // Models the constraint lb <= a*x <= ub. Members variables and coefficients
97 // must have the same size.
99  double lower_bound = -std::numeric_limits<double>::infinity();
100  std::vector<SCIP_VAR*> variables;
101  std::vector<double> coefficients;
102  double upper_bound = std::numeric_limits<double>::infinity();
103 };
104 
105 // A variable is implied integer if the integrality constraint is not required
106 // for the model to be valid, but the variable takes an integer value in any
107 // optimal solution to the problem.
109 
110 struct GScipIndicatorConstraint;
111 struct GScipLogicalConstraintData;
112 // Some advanced features, defined at the end of the header file.
113 struct GScipQuadraticRange;
114 struct GScipSOSData;
115 struct GScipVariableOptions;
116 
117 const GScipVariableOptions& DefaultGScipVariableOptions();
118 struct GScipConstraintOptions;
119 
120 const GScipConstraintOptions& DefaultGScipConstraintOptions();
121 using GScipBranchingPriority = absl::flat_hash_map<SCIP_VAR*, int>;
122 enum class GScipHintResult;
123 
124 // A thin wrapper around the SCIP solver that provides C++ bindings that are
125 // idiomatic for Google. Unless callbacks are used, the SCIP stage is always
126 // PROBLEM.
127 class GScip {
128  public:
129  // Create a new GScip (the constructor is private). The default objective
130  // direction is minimization.
131  static absl::StatusOr<std::unique_ptr<GScip>> Create(
132  const std::string& problem_name);
133  ~GScip();
134  static std::string ScipVersion();
135 
136  // After Solve() the parameters are reset and SCIP stage is restored to
137  // PROBLEM. "legacy_params" are in the format of legacy_scip_params.h and are
138  // applied after "params". Use of "legacy_params" is discouraged.
139  //
140  // The returned StatusOr will contain an error only if an:
141  // * An underlying function from SCIP fails.
142  // * There is an I/O error with managing SCIP output.
143  // The above cases are not mutually exclusive. If the problem is infeasible,
144  // this will be reflected in the value of GScipResult::gscip_output::status.
145  absl::StatusOr<GScipResult> Solve(
146  const GScipParameters& params = GScipParameters(),
147  const std::string& legacy_params = "",
148  GScipMessageHandler message_handler = nullptr);
149 
150  // ///////////////////////////////////////////////////////////////////////////
151  // Basic Model Construction
152  // ///////////////////////////////////////////////////////////////////////////
153 
154  // Use true for maximization, false for minimization.
155  absl::Status SetMaximize(bool is_maximize);
156  absl::Status SetObjectiveOffset(double offset);
157 
158  // The returned SCIP_VAR is owned by GScip. With default options, the
159  // returned variable will have the same lifetime as GScip (if instead,
160  // GScipVariableOptions::keep_alive is false, SCIP may free the variable at
161  // any time, see GScipVariableOptions::keep_alive for details).
162  //
163  // Note that SCIP will internally convert a variable of type `kInteger` with
164  // bounds of [0, 1] to a variable of type `kBinary`.
165  absl::StatusOr<SCIP_VAR*> AddVariable(
166  double lb, double ub, double obj_coef, GScipVarType var_type,
167  const std::string& var_name = "",
169 
170  // The returned SCIP_CONS is owned by GScip. With default options, the
171  // returned variable will have the same lifetime as GScip (if instead,
172  // GScipConstraintOptions::keep_alive is false, SCIP may free the constraint
173  // at any time, see GScipConstraintOptions::keep_alive for details).
174  //
175  // Can be called while creating the model or in a callback (e.g. in a
176  // GScipConstraintHandler).
177  absl::StatusOr<SCIP_CONS*> AddLinearConstraint(
178  const GScipLinearRange& range, const std::string& name = "",
180 
181  // ///////////////////////////////////////////////////////////////////////////
182  // Model Queries
183  // ///////////////////////////////////////////////////////////////////////////
184 
185  bool ObjectiveIsMaximize();
186  double ObjectiveOffset();
187 
188  double Lb(SCIP_VAR* var);
189  double Ub(SCIP_VAR* var);
190  double ObjCoef(SCIP_VAR* var);
191  // NOTE: The returned type may differ from the type passed to `AddVariable()`.
192  GScipVarType VarType(SCIP_VAR* var);
193  absl::string_view Name(SCIP_VAR* var);
194  const absl::flat_hash_set<SCIP_VAR*>& variables() { return variables_; }
195 
196  // These methods works on all constraint types.
197  absl::string_view Name(SCIP_CONS* constraint);
198  bool IsConstraintLinear(SCIP_CONS* constraint);
199  const absl::flat_hash_set<SCIP_CONS*>& constraints() { return constraints_; }
200 
201  // These methods will CHECK fail if constraint is not a linear constraint.
202  absl::Span<const double> LinearConstraintCoefficients(SCIP_CONS* constraint);
203  absl::Span<SCIP_VAR* const> LinearConstraintVariables(SCIP_CONS* constraint);
204  double LinearConstraintLb(SCIP_CONS* constraint);
205  double LinearConstraintUb(SCIP_CONS* constraint);
206 
207  // ///////////////////////////////////////////////////////////////////////////
208  // Model Updates (needed for incrementalism)
209  // ///////////////////////////////////////////////////////////////////////////
210  // TODO(b/246342145): A crash may occur if you attempt to set a lb <= -1.0 on
211  // a binary variable. SCIP can also silently change the vartype of a variable
212  // after construction, so you should check it via `VarType()`.
213  absl::Status SetLb(SCIP_VAR* var, double lb);
214  // TODO(b/246342145): A crash may occur if you attempt to set an ub >= 2.0 on
215  // a binary variable. SCIP can also silently change the vartype of a variable
216  // after construction, so you should check it via `VarType()`.
217  absl::Status SetUb(SCIP_VAR* var, double ub);
218  absl::Status SetObjCoef(SCIP_VAR* var, double obj_coef);
219  absl::Status SetVarType(SCIP_VAR* var, GScipVarType var_type);
220 
221  // Warning: you need to ensure that no constraint has a reference to this
222  // variable before deleting it, or undefined behavior will occur. For linear
223  // constraints, you can set the coefficient of this variable to zero to remove
224  // the variable from the constriant.
225  absl::Status DeleteVariable(SCIP_VAR* var);
226 
227  // Checks if SafeBulkDelete will succeed for vars, and returns a description
228  // the problematic variables/constraints on a failure (the returned status
229  // will not contain a propagated SCIP error). Will not modify the underyling
230  // SCIP, it is safe to continue using this if an error is returned.
231  absl::Status CanSafeBulkDelete(const absl::flat_hash_set<SCIP_VAR*>& vars);
232 
233  // Attempts to remove vars from all constraints and then remove vars from
234  // the model. As of August 7, 2020, will fail if the model contains any
235  // constraints that are not linear.
236  //
237  // Will call CanSafeBulkDelete above, but can also return an error Status
238  // propagated from SCIP. Do not assume SCIP is in a valid state if this fails.
239  absl::Status SafeBulkDelete(const absl::flat_hash_set<SCIP_VAR*>& vars);
240 
241  // These methods will CHECK fail if constraint is not a linear constraint.
242  absl::Status SetLinearConstraintLb(SCIP_CONS* constraint, double lb);
243  absl::Status SetLinearConstraintUb(SCIP_CONS* constraint, double ub);
244  absl::Status SetLinearConstraintCoef(SCIP_CONS* constraint, SCIP_VAR* var,
245  double value);
246  absl::Status AddLinearConstraintCoef(SCIP_CONS* constraint, SCIP_VAR* var,
247  double value);
248 
249  // Works on all constraint types. Unlike DeleteVariable, no special action is
250  // required before deleting a constraint.
251  absl::Status DeleteConstraint(SCIP_CONS* constraint);
252 
253  // ///////////////////////////////////////////////////////////////////////////
254  // Nonlinear constraint types.
255  // For now, only basic support (adding to the model) is provided. Reading and
256  // updating support may be added in the future.
257  // ///////////////////////////////////////////////////////////////////////////
258 
259  // Adds a constraint of the form:
260  // if z then a * x <= b
261  // where z is a binary variable, x is a vector of decision variables, a is
262  // vector of constants, and b is a constant. z can be negated.
263  //
264  // NOTE(user): options.modifiable is ignored.
265  absl::StatusOr<SCIP_CONS*> AddIndicatorConstraint(
266  const GScipIndicatorConstraint& indicator_constraint,
267  const std::string& name = "",
269 
270  // Adds a constraint of form lb <= x * Q * x + a * x <= ub.
271  //
272  // NOTE(user): options.modifiable and options.sticking_at_node are ignored.
273  absl::StatusOr<SCIP_CONS*> AddQuadraticConstraint(
274  const GScipQuadraticRange& range, const std::string& name = "",
276 
277  // Adds the constraint:
278  // logical_data.resultant = AND_i logical_data.operators[i],
279  // where logical_data.resultant and logical_data.operators[i] are all binary
280  // variables.
281  absl::StatusOr<SCIP_CONS*> AddAndConstraint(
282  const GScipLogicalConstraintData& logical_data,
283  const std::string& name = "",
285 
286  // Adds the constraint:
287  // logical_data.resultant = OR_i logical_data.operators[i],
288  // where logical_data.resultant and logical_data.operators[i] must be binary
289  // variables.
290  absl::StatusOr<SCIP_CONS*> AddOrConstraint(
291  const GScipLogicalConstraintData& logical_data,
292  const std::string& name = "",
294 
295  // Adds the constraint that at most one of the variables in sos_data can be
296  // nonzero. The variables can be integer or continuous. See GScipSOSData for
297  // details.
298  //
299  // NOTE(user): options.modifiable is ignored (these constraints are not
300  // modifiable).
301  absl::StatusOr<SCIP_CONS*> AddSOS1Constraint(
302  const GScipSOSData& sos_data, const std::string& name = "",
304 
305  // Adds the constraint that at most two of the variables in sos_data can be
306  // nonzero, and they must be adjacent under the ordering for sos_data. See
307  // GScipSOSData for details.
308  //
309  // NOTE(user): options.modifiable is ignored (these constraints are not
310  // modifiable).
311  absl::StatusOr<SCIP_CONS*> AddSOS2Constraint(
312  const GScipSOSData& sos_data, const std::string& name = "",
314 
315  // ///////////////////////////////////////////////////////////////////////////
316  // Advanced use
317  // ///////////////////////////////////////////////////////////////////////////
318 
319  // Returns the name of the constraint handler for this constraint.
320  absl::string_view ConstraintType(SCIP_CONS* constraint);
321 
322  // The proposed solution can be partial (only specify some of the variables)
323  // or complete. Complete solutions will be checked for feasibility and
324  // objective quality, and might be unused for these reasons. Partial solutions
325  // will always be accepted.
326  absl::StatusOr<GScipHintResult> SuggestHint(
327  const GScipSolution& partial_solution);
328 
329  // All variables have a default branching priority of zero. Variables are
330  // partitioned by their branching priority, and a fractional variable from the
331  // highest partition will always be branched on.
332  //
333  // TODO(user): Add support for BranchingFactor as well, this is typically
334  // more useful.
335  absl::Status SetBranchingPriority(SCIP_VAR* var, int priority);
336 
337  // Doubles with absolute value of at least this value are invalid and result
338  // in errors. Floating point actual infinities are replaced by this value in
339  // SCIP calls. SCIP considers values at least this large to be infinite. When
340  // querying gSCIP, if an absolute value exceeds ScipInf, it is replaced by
341  // std::numeric_limits<double>::infinity().
342  double ScipInf();
343  static constexpr double kDefaultScipInf = 1e20;
344 
345  // WARNING(rander): no synchronization is provided between InterruptSolve()
346  // and ~GScip(). These methods require mutual exclusion, the user is
347  // responsible for ensuring this invariant.
348  // TODO(user): should we add a lock here? Seems a little dangerous to block
349  // in a destructor.
350  bool InterruptSolve();
351 
352  // These should typically not be needed.
353  SCIP* scip() { return scip_; }
354 
355  absl::StatusOr<bool> DefaultBoolParamValue(const std::string& parameter_name);
356  absl::StatusOr<int> DefaultIntParamValue(const std::string& parameter_name);
357  absl::StatusOr<int64_t> DefaultLongParamValue(
358  const std::string& parameter_name);
359  absl::StatusOr<double> DefaultRealParamValue(
360  const std::string& parameter_name);
361  absl::StatusOr<char> DefaultCharParamValue(const std::string& parameter_name);
362  absl::StatusOr<std::string> DefaultStringParamValue(
363  const std::string& parameter_name);
364 
365  private:
366  explicit GScip(SCIP* scip);
367  // Releases SCIP memory.
368  absl::Status CleanUp();
369 
370  absl::Status SetParams(const GScipParameters& params,
371  const std::string& legacy_params);
372  absl::Status FreeTransform();
373 
374  // Replaces +/- inf by +/- ScipInf(), fails when |d| is in [ScipInf(), inf).
375  absl::StatusOr<double> ScipInfClamp(double d);
376 
377  // Returns +/- inf if |d| >= ScipInf(), otherwise returns d.
378  double ScipInfUnclamp(double d);
379 
380  // Returns an error if |d| >= ScipInf().
381  absl::Status CheckScipFinite(double d);
382 
383  absl::Status MaybeKeepConstraintAlive(SCIP_CONS* constraint,
384  const GScipConstraintOptions& options);
385 
386  SCIP* scip_;
387  absl::flat_hash_set<SCIP_VAR*> variables_;
388  absl::flat_hash_set<SCIP_CONS*> constraints_;
389 };
390 
391 // Advanced features below
392 
393 // Models the constraint
394 // lb <= x * Q * x + a * x <= ub
396  // Models lb above.
397  double lower_bound = -std::numeric_limits<double>::infinity();
398 
399  // Models a * x above. linear_variables and linear_coefficients must have the
400  // same size.
401  std::vector<SCIP_Var*> linear_variables;
402  std::vector<double> linear_coefficients;
403 
404  // These three vectors must have the same size. Models x * Q * x as
405  // sum_i quadratic_coefficients[i] * quadratic_variables1[i]
406  // * quadratic_variables2[i]
407  //
408  // Duplicate quadratic terms (e.g. i=3 encodes 4*x1*x3 and i=4 encodes
409  // 8*x3*x1) are added (as if you added a single entry 12*x1*x3).
410  //
411  // TODO(user): investigate, the documentation seems to suggest that when
412  // linear_variables[i] == quadratic_variables1[i] == quadratic_variables2[i]
413  // there is some advantage.
414  std::vector<SCIP_Var*> quadratic_variables1;
415  std::vector<SCIP_Var*> quadratic_variables2;
416  std::vector<double> quadratic_coefficients;
417 
418  // Models ub above.
419  double upper_bound = std::numeric_limits<double>::infinity();
420 };
421 
422 // Models special ordered set constraints (SOS1 and SOS2 constraints). Each
423 // contains a list of variables that are implicitly ordered by the provided
424 // weights, which must be distinct.
425 // SOS1: At most one of the variables can be nonzero.
426 // SOS2: At most two of the variables can be nonzero, and they must be
427 // consecutive.
428 //
429 // The weights are optional, and if not provided, the ordering in "variables" is
430 // used.
431 struct GScipSOSData {
432  // The list of variables where all but one or two must be zero. Can be integer
433  // or continuous variables, typically their domain will contain zero. Cannot
434  // be empty in a valid SOS constraint.
435  std::vector<SCIP_VAR*> variables;
436 
437  // Optional, can be empty. Otherwise, must have size equal to variables, and
438  // values must be distinct. Determines an "ordering" over the variables
439  // (smallest weight to largest). Additionally, the numeric values of
440  // the weights are used to make branching decisions in a solver specific way,
441  // for details, see:
442  // * https://scip.zib.de/doc/html/cons__sos1_8c.php
443  // * https://scip.zib.de/doc/html/cons__sos2_8c.php.
444  std::vector<double> weights;
445 };
446 
447 // Models the constraint z = 1 => a * x <= b
448 // If negate_indicator, then instead: z = 0 => a * x <= b
450  // The z variable above. The vartype must be kBinary.
451  SCIP_VAR* indicator_variable = nullptr;
452  bool negate_indicator = false;
453  // The x variable above.
454  std::vector<SCIP_Var*> variables;
455  // a above. Must have the same size as x.
456  std::vector<double> coefficients;
457  // b above.
458  double upper_bound = std::numeric_limits<double>::infinity();
459 };
460 
461 // Data for constraint of the form resultant = f(operators), e.g.:
462 // resultant = AND_i operators[i]
463 // For existing constraints (e.g. AND, OR) resultant and operators[i] should all
464 // be binary variables, this my change. See use in GScip for details.
466  SCIP_VAR* resultant = nullptr;
467  std::vector<SCIP_VAR*> operators;
468 };
469 
470 enum class GScipHintResult {
471  // Hint was not feasible.
472  kInfeasible,
473  // Hint was not good enough to keep.
474  kRejected,
475  // Hint was kept. Partial solutions are not checked for feasibility, they
476  // are always accepted.
477  kAccepted
478 };
479 
480 // Advanced use. Options to use when creating a variable.
482  // ///////////////////////////////////////////////////////////////////////////
483  // SCIP options. Descriptions are from the SCIP documentation, e.g.
484  // SCIPcreateVar:
485  // https://scip.zib.de/doc/html/group__PublicVariableMethods.php#ga7a37fe4dc702dadecc4186b9624e93fc
486  // ///////////////////////////////////////////////////////////////////////////
487 
488  // Should var's column be present in the initial root LP?
489  bool initial = true;
490 
491  // Is var's column removable from the LP (due to aging or cleanup)?
492  bool removable = false;
493 
494  // ///////////////////////////////////////////////////////////////////////////
495  // gSCIP options.
496  // ///////////////////////////////////////////////////////////////////////////
497 
498  // If keep_alive=true, the returned variable will not to be freed until after
499  // ~GScip() is called. Otherwise, the returned variable could be freed
500  // internally by SCIP at any point, and it is not safe to hold a reference to
501  // the returned variable.
502  //
503  // The primary reason to set keep_alive=false is if you are adding many
504  // variables in a callback (in branch and price), and you expect that most of
505  // them will be deleted.
506  bool keep_alive = true;
507 };
508 
509 // Advanced use. Options to use when creating a constraint.
511  // ///////////////////////////////////////////////////////////////////////////
512  // SCIP options. Descriptions are from the SCIP documentation, e.g.
513  // SCIPcreateConsLinear:
514  // https://scip.zib.de/doc/html/group__CONSHDLRS.php#gaea3b4db21fe214be5db047e08b46b50e
515  // ///////////////////////////////////////////////////////////////////////////
516 
517  // Should the LP relaxation of constraint be in the initial LP? False for lazy
518  // constraints (true in callbacks).
519  bool initial = true;
520  // Should the constraint be separated during LP processing?
521  bool separate = true;
522  // Should the constraint be enforced during node processing? True for model
523  // constraints, false for redundant constraints.
524  bool enforce = true;
525  // Should the constraint be checked for feasibility? True for model
526  // constraints, false for redundant constraints.
527  bool check = true;
528  // Should the constraint be propagated during node processing?
529  bool propagate = true;
530  // Is constraint only valid locally? Must be true for branching constraints.
531  bool local = false;
532  // Is constraint modifiable (subject to column generation)? In column
533  // generation applications, set to true if pricing adds coefficients to this
534  // constraint.
535  bool modifiable = false;
536  // Is constraint subject to aging? Set to true for own cuts which are
537  // separated as constraints
538  bool dynamic = false;
539  // Should the relaxation be removed from the LP due to aging or cleanup? Set
540  // to true for 'lazy constraints' and 'user cuts'.
541  bool removable = false;
542  // Should the constraint always be kept at the node where it was added, even
543  // if it may be moved to a more global node? Usually set to false. Set to true
544  // for constraints that represent node data.
545  bool sticking_at_node = false;
546 
547  // ///////////////////////////////////////////////////////////////////////////
548  // gSCIP options.
549  // ///////////////////////////////////////////////////////////////////////////
550 
551  // If keep_alive=true, the returned constraint will not to be freed until
552  // after ~GScip() is called. Otherwise, the returned constraint could be freed
553  // internally by SCIP at any point, and it is not safe to hold a reference to
554  // the returned constraint.
555  //
556  // The primary reason to set keep_alive=false is if you are adding many
557  // constraints in a callback, and you expect that most of them will be
558  // deleted.
559  bool keep_alive = true;
560 };
561 
562 } // namespace operations_research
563 
564 #endif // OR_TOOLS_GSCIP_GSCIP_H_
double LinearConstraintUb(SCIP_CONS *constraint)
Definition: gscip.cc:750
absl::Status SetObjectiveOffset(double offset)
Definition: gscip.cc:619
absl::StatusOr< SCIP_VAR * > AddVariable(double lb, double ub, double obj_coef, GScipVarType var_type, const std::string &var_name="", const GScipVariableOptions &options=DefaultGScipVariableOptions())
Definition: gscip.cc:329
absl::Status DeleteVariable(SCIP_VAR *var)
Definition: gscip.cc:663
absl::StatusOr< SCIP_CONS * > AddOrConstraint(const GScipLogicalConstraintData &logical_data, const std::string &name="", const GScipConstraintOptions &options=DefaultGScipConstraintOptions())
Definition: gscip.cc:513
absl::StatusOr< double > DefaultRealParamValue(const std::string &parameter_name)
Definition: gscip.cc:1014
absl::Status CanSafeBulkDelete(const absl::flat_hash_set< SCIP_VAR * > &vars)
Definition: gscip.cc:673
absl::StatusOr< SCIP_CONS * > AddAndConstraint(const GScipLogicalConstraintData &logical_data, const std::string &name="", const GScipConstraintOptions &options=DefaultGScipConstraintOptions())
Definition: gscip.cc:488
const absl::flat_hash_set< SCIP_CONS * > & constraints()
Definition: gscip.h:199
absl::StatusOr< SCIP_CONS * > AddLinearConstraint(const GScipLinearRange &range, const std::string &name="", const GScipConstraintOptions &options=DefaultGScipConstraintOptions())
Definition: gscip.cc:365
bool IsConstraintLinear(SCIP_CONS *constraint)
Definition: gscip.cc:730
absl::string_view ConstraintType(SCIP_CONS *constraint)
Definition: gscip.cc:726
absl::StatusOr< int64_t > DefaultLongParamValue(const std::string &parameter_name)
Definition: gscip.cc:1006
absl::StatusOr< int > DefaultIntParamValue(const std::string &parameter_name)
Definition: gscip.cc:998
absl::Status DeleteConstraint(SCIP_CONS *constraint)
Definition: gscip.cc:770
absl::Status SetLinearConstraintUb(SCIP_CONS *constraint, double ub)
Definition: gscip.cc:764
absl::Status SafeBulkDelete(const absl::flat_hash_set< SCIP_VAR * > &vars)
Definition: gscip.cc:687
static absl::StatusOr< std::unique_ptr< GScip > > Create(const std::string &problem_name)
Definition: gscip.cc:276
double Ub(SCIP_VAR *var)
Definition: gscip.cc:714
double ObjCoef(SCIP_VAR *var)
Definition: gscip.cc:718
absl::Status SetMaximize(bool is_maximize)
Definition: gscip.cc:613
absl::Span< SCIP_VAR *const > LinearConstraintVariables(SCIP_CONS *constraint)
Definition: gscip.cc:740
absl::StatusOr< std::string > DefaultStringParamValue(const std::string &parameter_name)
Definition: gscip.cc:1030
absl::StatusOr< bool > DefaultBoolParamValue(const std::string &parameter_name)
Definition: gscip.cc:990
absl::StatusOr< SCIP_CONS * > AddIndicatorConstraint(const GScipIndicatorConstraint &indicator_constraint, const std::string &name="", const GScipConstraintOptions &options=DefaultGScipConstraintOptions())
Definition: gscip.cc:447
double Lb(SCIP_VAR *var)
Definition: gscip.cc:710
const absl::flat_hash_set< SCIP_VAR * > & variables()
Definition: gscip.h:194
absl::Status SetLb(SCIP_VAR *var, double lb)
Definition: gscip.cc:638
double LinearConstraintLb(SCIP_CONS *constraint)
Definition: gscip.cc:746
absl::Status SetLinearConstraintCoef(SCIP_CONS *constraint, SCIP_VAR *var, double value)
Definition: gscip.cc:777
absl::Status SetLinearConstraintLb(SCIP_CONS *constraint, double lb)
Definition: gscip.cc:758
absl::StatusOr< GScipHintResult > SuggestHint(const GScipSolution &partial_solution)
Definition: gscip.cc:795
absl::StatusOr< GScipResult > Solve(const GScipParameters &params=GScipParameters(), const std::string &legacy_params="", GScipMessageHandler message_handler=nullptr)
Definition: gscip.cc:832
GScipVarType VarType(SCIP_VAR *var)
Definition: gscip.cc:720
absl::Status SetVarType(SCIP_VAR *var, GScipVarType var_type)
Definition: gscip.cc:656
absl::Status SetBranchingPriority(SCIP_VAR *var, int priority)
Definition: gscip.cc:633
absl::StatusOr< char > DefaultCharParamValue(const std::string &parameter_name)
Definition: gscip.cc:1022
absl::Span< const double > LinearConstraintCoefficients(SCIP_CONS *constraint)
Definition: gscip.cc:734
absl::Status SetUb(SCIP_VAR *var, double ub)
Definition: gscip.cc:644
absl::Status SetObjCoef(SCIP_VAR *var, double obj_coef)
Definition: gscip.cc:650
absl::StatusOr< SCIP_CONS * > AddSOS2Constraint(const GScipSOSData &sos_data, const std::string &name="", const GScipConstraintOptions &options=DefaultGScipConstraintOptions())
Definition: gscip.cc:587
static std::string ScipVersion()
Definition: gscip.cc:294
absl::StatusOr< SCIP_CONS * > AddQuadraticConstraint(const GScipQuadraticRange &range, const std::string &name="", const GScipConstraintOptions &options=DefaultGScipConstraintOptions())
Definition: gscip.cc:399
static constexpr double kDefaultScipInf
Definition: gscip.h:343
absl::string_view Name(SCIP_VAR *var)
Definition: gscip.cc:724
absl::Status AddLinearConstraintCoef(SCIP_CONS *constraint, SCIP_VAR *var, double value)
Definition: gscip.cc:787
absl::StatusOr< SCIP_CONS * > AddSOS1Constraint(const GScipSOSData &sos_data, const std::string &name="", const GScipConstraintOptions &options=DefaultGScipConstraintOptions())
Definition: gscip.cc:560
const std::string name
int64_t value
IntVar * var
Definition: expr_array.cc:1874
Collection of objects used to extend the Constraint Solver library.
const GScipConstraintOptions & DefaultGScipConstraintOptions()
Definition: gscip.cc:208
std::function< void(GScipMessageType type, absl::string_view message)> GScipMessageHandler
const GScipVariableOptions & DefaultGScipVariableOptions()
Definition: gscip.cc:203
absl::flat_hash_map< SCIP_VAR *, int > GScipBranchingPriority
Definition: gscip.h:121
absl::flat_hash_map< SCIP_VAR *, double > GScipSolution
Definition: gscip.h:74
const std::optional< Range > & range
Definition: statistics.cc:36
std::vector< SCIP_Var * > variables
Definition: gscip.h:454
std::vector< SCIP_VAR * > variables
Definition: gscip.h:100
std::vector< double > coefficients
Definition: gscip.h:101
std::vector< SCIP_VAR * > operators
Definition: gscip.h:467
std::vector< SCIP_Var * > quadratic_variables1
Definition: gscip.h:414
std::vector< SCIP_Var * > quadratic_variables2
Definition: gscip.h:415
std::vector< SCIP_Var * > linear_variables
Definition: gscip.h:401
std::vector< double > linear_coefficients
Definition: gscip.h:402
std::vector< double > quadratic_coefficients
Definition: gscip.h:416
absl::flat_hash_map< SCIP_VAR *, double > primal_ray
Definition: gscip.h:90
std::vector< double > objective_values
Definition: gscip.h:85
std::vector< GScipSolution > solutions
Definition: gscip.h:83
std::vector< SCIP_VAR * > variables
Definition: gscip.h:435
std::vector< double > weights
Definition: gscip.h:444