Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
test_models.h
Go to the documentation of this file.
1// Copyright 2010-2024 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// Holds MathOpt models that are shared across tests from this directory.
15#ifndef OR_TOOLS_MATH_OPT_SOLVER_TESTS_TEST_MODELS_H_
16#define OR_TOOLS_MATH_OPT_SOLVER_TESTS_TEST_MODELS_H_
17
18#include <memory>
19
21
23
24// Decision variables:
25// * x[i], i=1..3
26// * y[i], i=1..3
27//
28// Problem statement:
29// max sum_i 3 * x[i] + 2 * y[i]
30// s.t. x[i] + y[i] <= 1.5 for i=1..3
31// 0 <= x[i], y[i] <= 1 for i=1..3
32// Optionally, x[i], y[i] integer, for i=1..3
33//
34// Analysis:
35// * For IP, x[i] = 1, y[i] = 0 for all i is optimal, objective 9.
36// * For LP, x[i] = 1, y[i] = 0.5 for all i is optimal, objective is 12.
37std::unique_ptr<Model> SmallModel(bool integer);
38
39// Problem data: m = 3, n > 0, c = [5, 4, 3]
40//
41// Decision variables: x[i][j], i = 1..m, j = 1..n
42//
43// Problem statement:
44// max sum_i sum_j c[i] * x[i,j]
45// s.t. x[i, j] + x[i, k] <= 1 for i = 1..m, j = 1..n, k = j+1..n (A)
46// x[0, j] + x[i, k] <= 1 for i = 2..m, j = 1..n, k = 1..n (B)
47// 0 <= x[i, j] <= 1
48// Optionally, x[i, j] integer.
49//
50// Analysis:
51// * Constraint (A) says that for each row i, pick at most one j to be on.
52// * Constraint (B) says that if you pick any from row i = 0, you cannot use
53// rows i = 1, 2.
54// * Optimal objective is 7, e.g. x[1][0] = x[2][0] = 1, all other x zero.
55// * Heuristics are likely to pick elements with x[0][j] = 1 to get the larger
56// objective coefficient, global reasoning (beyond one linear constraint) is
57// needed to see this doesn't work well.
58// * LP optimal objective is 10 * (5 + 4 + 3) / 2, taking all x[i, j] = 1/2,
59// so the problem has a large initial gap.
60// * For LP, variable is at a bound, so likely some pivots will be required.
61// * The MIP has many symmetric solutions.
62std::unique_ptr<Model> DenseIndependentSet(bool integer, int n = 10);
63
64// A hint with objective value of 5 for the model returned by
65// DenseIndependentSet().
66ModelSolveParameters::SolutionHint DenseIndependentSetHint5(const Model& model);
67
68// Problem data: n > 0
69//
70// Decision variables: x[i], i = 0..n-1
71//
72// Problem statement:
73// max sum_i x[i]
74// s.t. x[i] + x[j] <= 1 for i = 0..n-1, j = i+1..n-1
75// 0 <= x[i] <= 1 for i = 0..n-1
76//
77// Analysis:
78// * The unique optimal solution to this problem is x[i] = 1/2 for all i, with
79// an objective value of n/2.
80// * Setting an iteration of limit significantly smaller than n should prevent
81// an LP solver from finding an optimal solution. Specific state at such
82// termination is solver-dependent.
83std::unique_ptr<Model> IndependentSetCompleteGraph(bool integer, int n = 10);
84
85} // namespace operations_research::math_opt
86
87#endif // OR_TOOLS_MATH_OPT_SOLVER_TESTS_TEST_MODELS_H_
GRBmodel * model
An object oriented wrapper for quadratic constraints in ModelStorage.
Definition gurobi_isv.cc:28
std::unique_ptr< Model > SmallModel(const bool integer)
std::unique_ptr< Model > IndependentSetCompleteGraph(const bool integer, const int n)
std::unique_ptr< Model > DenseIndependentSet(const bool integer, const int n)
ModelSolveParameters::SolutionHint DenseIndependentSetHint5(const Model &model)