OR-Tools  8.2
gscip_ext.h
Go to the documentation of this file.
1// Copyright 2010-2018 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// Additional nonlinear constraints not supported directly by SCIP.
15//
16// The primary purpose of this file is to support the nonlinear constraints of
17// MPSolver proto API.
18//
19// WARNING(rander): as these constraints are not natively supported in SCIP,
20// they will generally not be a single SCIP_CONS* created, but will typically
21// result in multiple SCIP_CONS* and SCIP_VAR* being created. Direct access to
22// these intermediate variables and constraints is currently not provided.
23//
24// TODO(user): either implement with SCIP constraint handlers or use a solver
25// independent implementation.
26#ifndef OR_TOOLS_GSCIP_GSCIP_EXT_H_
27#define OR_TOOLS_GSCIP_GSCIP_EXT_H_
28
29#include "absl/status/status.h"
30#include "ortools/gscip/gscip.h"
31#include "scip/scip.h"
32#include "scip/scip_prob.h"
33#include "scip/type_cons.h"
34#include "scip/type_scip.h"
35#include "scip/type_var.h"
36
37namespace operations_research {
38
39// Adds the constraint y = abs(x). May create auxiliary variables. Supports
40// unbounded x.
41absl::Status GScipCreateAbs(GScip* gscip, SCIP_Var* x, SCIP_Var* abs_x,
42 const std::string& name = "");
43
44// TODO(user): delete this type and the methods below, use a generic version
45// templated on the variable type that supports operator overloads.
47 absl::flat_hash_map<SCIP_VAR*, double> terms;
48 double offset = 0.0;
49
50 GScipLinearExpr() = default;
51 explicit GScipLinearExpr(SCIP_VAR* variable);
52 explicit GScipLinearExpr(double offset);
53};
54
55// Returns left - right.
57 const GScipLinearExpr& right);
58
59// Returns -expr.
61
62// Returns the range -inf <= left.terms - right.terms <= right.offset -
63// left.offset
65 const GScipLinearExpr& right);
66
67// Adds the constraint resultant = maximum(terms). Supports unbounded variables
68// in terms.
69absl::Status GScipCreateMaximum(GScip* gscip, const GScipLinearExpr& resultant,
70 const std::vector<GScipLinearExpr>& terms,
71 const std::string& name = "");
72
73// Adds the constraint resultant = minimum(terms). Supports unbounded variables
74// in terms.
75absl::Status GScipCreateMinimum(GScip* gscip, const GScipLinearExpr& resultant,
76 const std::vector<GScipLinearExpr>& terms,
77 const std::string& name = "");
78
79// Models the constraint z = 1 => lb <= ax <= ub
80// If negate_indicator, then instead: z = 0 => lb <= ax <= ub
82 SCIP_VAR* indicator_variable = nullptr;
83 bool negate_indicator = false;
85};
86
87// Supports unbounded variables in indicator_range.range.variables.
88absl::Status GScipCreateIndicatorRange(
89 GScip* gscip, const GScipIndicatorRangeConstraint& indicator_range,
90 const std::string& name = "",
92
93// WARNING: DO NOT CHANGE THE OBJECTIVE DIRECTION AFTER CALLING THIS METHOD.
94//
95// This is implemented by modeling the quadratic term with an an inequality
96// constraint and a single extra variable, which is then added to the objective.
97// The inequality will be in the wrong direction if you change the objective
98// direction after calling this method.
100 GScip* gscip, std::vector<SCIP_Var*> quadratic_variables1,
101 std::vector<SCIP_Var*> quadratic_variables2,
102 std::vector<double> quadratic_coefficients, const std::string& name = "");
103
104} // namespace operations_research
105
106#endif // OR_TOOLS_GSCIP_GSCIP_EXT_H_
const std::string name
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
GScipLinearRange GScipLe(const GScipLinearExpr left, const GScipLinearExpr &right)
Definition: gscip_ext.cc:56
GScipLinearExpr GScipDifference(GScipLinearExpr left, const GScipLinearExpr &right)
Definition: gscip_ext.cc:37
absl::Status GScipCreateMaximum(GScip *gscip, const GScipLinearExpr &resultant, const std::vector< GScipLinearExpr > &terms, const std::string &name)
Definition: gscip_ext.cc:76
absl::Status GScipCreateAbs(GScip *gscip, SCIP_Var *x, SCIP_Var *abs_x, const std::string &name)
Definition: gscip_ext.cc:69
absl::Status GScipAddQuadraticObjectiveTerm(GScip *gscip, std::vector< SCIP_Var * > quadratic_variables1, std::vector< SCIP_Var * > quadratic_variables2, std::vector< double > quadratic_coefficients, const std::string &name)
Definition: gscip_ext.cc:143
absl::Status GScipCreateMinimum(GScip *gscip, const GScipLinearExpr &resultant, const std::vector< GScipLinearExpr > &terms, const std::string &name)
Definition: gscip_ext.cc:132
absl::Status GScipCreateIndicatorRange(GScip *gscip, const GScipIndicatorRangeConstraint &indicator_range, const std::string &name, const GScipConstraintOptions &options)
Definition: gscip_ext.cc:173
GScipLinearExpr GScipNegate(GScipLinearExpr expr)
Definition: gscip_ext.cc:46
absl::flat_hash_map< SCIP_VAR *, double > terms
Definition: gscip_ext.h:47