Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
fixed_integer_variable_bounds.cc
Go to the documentation of this file.
1// Copyright 2010-2025 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// A simple example where an integer variable with fractional bounds whose only
15// feasible value is 0 or 1 is silently converted to a binary variable. This
16// leads to a debug crash if you try to widen the bounds.
17#include <memory>
18#include <utility>
19
20#include "absl/log/check.h"
23
24int main(int argc, char* argv[]) {
25 InitGoogle("", &argc, &argv, true);
26
27 auto gscip_or = operations_research::GScip::Create("");
28 std::unique_ptr<operations_research::GScip> gscip = *std::move(gscip_or);
29
30 const auto x_or = gscip->AddVariable(
32 CHECK_OK(x_or);
33 SCIP_VAR* const x = *x_or;
34
35 QCHECK(gscip->VarType(x) == operations_research::GScipVarType::kBinary);
36 QCHECK_EQ(gscip->Lb(x), 0.5);
37 QCHECK_EQ(gscip->Ub(x), 1.5);
38
39 // Setting the bounds to [0, 2] will CHECK-fail in debug model.
40 gscip->SetUb(x, 2.0).IgnoreError();
41
42 // Similarly, updating the lower bound to -1 will CHECK-fail in debug model.
43 gscip->SetLb(x, -1.0).IgnoreError();
44}
static absl::StatusOr< std::unique_ptr< GScip > > Create(const std::string &problem_name)
Definition gscip.cc:362
int main(int argc, char *argv[])
void InitGoogle(absl::string_view usage, int *argc, char ***argv, bool deprecated)
Definition init_google.h:49