Toggle navigation
SCIP Optimization Suite
SCIP
SoPlex
ZIMPL
UG
GCG
Documentation
SCIP 9.2.0
SCIP 8.1.0
SCIP 7.0.3
SCIP 6.0.2
SCIP 5.0.1
SCIP 4.0.1
SCIP 3.2.1
SCIP
Solving Constraint Integer Programs
examples
Binpacking
doc
xternal_binpacking.c
Go to the documentation of this file.
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2
/* */
3
/* This file is part of the program and library */
4
/* SCIP --- Solving Constraint Integer Programs */
5
/* */
6
/* Copyright (C) 2002-2018 Konrad-Zuse-Zentrum */
7
/* fuer Informationstechnik Berlin */
8
/* */
9
/* SCIP is distributed under the terms of the ZIB Academic License. */
10
/* */
11
/* You should have received a copy of the ZIB Academic License */
12
/* along with SCIP; see the file COPYING. If not email to scip@zib.de. */
13
/* */
14
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15
16
/**@file xternal_binpacking.c
17
* @brief The bin packing example of SCIP
18
* @author Timo Berthold
19
* @author Stefan Heinz
20
*/
21
22
/*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
23
24
/**@page BINPACKING_MAIN Overview
25
* @author Timo Berthold
26
* @author Stefan Heinz
27
*
28
* This example contains a branch-and-price approach for the binpacking problem which is realized with the framework
29
* \SCIP. Therefore, the following plugins are implemented:
30
*
31
* - a \ref reader_bpa.c "problem reader" which parses the problem out of file and creates the corresponding problem within \SCIP
32
* - a \ref probdata_binpacking.c "(global) problem data structure" which contains all necessary information
33
* - a \ref pricer_binpacking.c "pricer" which generates new variables/columns during the search
34
* - the \ref branch_ryanfoster.c "Ryan/Foster branching rule"
35
* - a \ref cons_samediff.c "constraint handler" which handles the branching decisions of the Ryan/Foster branching
36
* - a \ref vardata_binpacking.c "variable data structure" which stores information for each variable and is needed to perform the Ryan/Foster
37
* branching
38
*
39
* In the following we introduce the problem, explain the use of the reader plugin and pricer plugin. Finally, we
40
* introduce the Ryan/Foster branching rule and briefly discuss how that specific branching rule is realized within
41
* the framework \SCIP.
42
*
43
* -# \ref BINPACKING_PROBLEM "Problem description"
44
* -# \ref BINPACKING_READER "Parsing the input format and creating the problem"
45
* -# \ref BINPACKING_PROBLEMDATA "Main problem data"
46
* -# \ref BINPACKING_PRICER "Pricing new variables"
47
* -# \ref BINPACKING_BRANCHING "Ryan/Foster branching"
48
* -# \ref BINPACKING_MAKEFILE "The Makefile"
49
*
50
*/
51
52
/**@page BINPACKING_PROBLEM Problem description
53
*
54
* The binpacking problem consists of the task to distribute a given set of items \f$ [n] := \{1, \dots, n\}\f$ with
55
* nonnegative size \f$s_i\f$ to a minimal number of bins, all of the same capacity \f$\kappa\f$. As example consider 9
56
* items with sizes: 2, 1, 2, 1, 1, 2, 3, 2, and 1 and a bin capacity of \f$\kappa\f$ of 4. The following pictures show
57
* a feasible solution which needs 5 bins. The minimum number of bins needed for that example is 3.
58
*
59
* <CENTER>
60
* \image html binpacking.png
61
* </CENTER>
62
*
63
* This problem can be formulated as a set covering problem as discussed by Gilmore and Gomory in the following two classical papers:
64
* - Gilmore P. C., R. E. Gomory: A linear programming approach to the cutting-stock problem. Operations Research 9 (1961): 849-859.
65
* - Gilmore P. C., R. E. Gomory: A linear programming approach to the cutting-stock problem - Part II. Operations Research 11 (1963): 863-888
66
*
67
* We introduce a binary variable \f$x_{S}\f$ for each feasible packing \f$S\f$. A <b>packing</b> \f$S\f$ is an
68
* assignment vector \f$ \lambda_{S}\in\{0,1\}^n \f$ which states the items belonging to that packing. It is
69
* <b>feasible</b>, if and only if the total size of the items contained in this assignment is not greater than the
70
* given capacity \f$\kappa\f$. Let \f$\mathcal{S}\f$ be the set of all feasible packing, this measns:
71
*
72
* \f[
73
* \mathcal{S} := \{S\subseteq [n] \mid \sum_{i:i\in S} s_{i} \leq \kappa \}
74
* \f]
75
*
76
* An integer program can be formulated as follows:
77
*
78
* \f[
79
* \begin{array}[t]{rll}
80
* \min & \displaystyle \sum_{S \in \mathcal{S}} x_{S} \\
81
* & \\
82
* subject \ to & \displaystyle \sum_{S \in \mathcal{S}} (\lambda_{S})_{i}x_{S} \ge 1 & \quad \forall i \in \{1,\dots,n\} \\
83
* & \\
84
* & x_{S} \in \{0,1\} & \quad \forall S \in \mathcal{S} \\
85
* \end{array}
86
* \f]
87
*
88
* This means we are searching for a set of packings such that each item is contained in at least one of the selected
89
* packings. Since the objective is to minimize the number of used packings, each optimal solution to the above problem
90
* can be transformed into a solution where each item is packed exactly once with the same cost.
91
*
92
*
93
* Since \f$\mathcal{S}\f$ can be of exponential size, we are using a column generation approach to solve this
94
* problem. We initialize the (master) problem with a set of \f$ n \f$ variables representing packings of a single item
95
* per bin. Now, we have to iteratively search for variables representing "better" packings, i.e., a packing pattern
96
* which reduces the overall cost. For a given solution \f$y^\star\f$ of the (restricted) dual linear program, we have
97
* to find a variable/packing \f$ \lambda_{S} \f$ for which the reduced costs is negative. This means:
98
*
99
* \f[
100
* c_{S} - \sum_{i=0}^n (\lambda_S)_i y_i^\star < 0.
101
* \f]
102
*
103
* Since all variables \f$ \lambda_{S} \f$ have an objective coefficient \f$ c_{S} = 1 \f$ the above condition is
104
* equivalent to
105
*
106
* \f[
107
* \sum_{i=0}^n (\lambda_S)_i y_i^\star > 1.
108
* \f]
109
*
110
*
111
* To find such a variable/packing we solve the following integer program:
112
*
113
* \f[
114
* \begin{array}[t]{rll}
115
* \max & \displaystyle \sum_{i=1}^n (\lambda_S)_i y^\star_i\\
116
* & \\
117
* subject \ to & \displaystyle \sum_{i=0}^n (\lambda_S)_i s_i \leq \kappa \\
118
* & \\
119
* & (\lambda_S)_i \in \{0,1\} & \quad \forall i \in \{ 1, \dots , n \} \\
120
* \end{array}
121
* \f]
122
*
123
* where \f$ (\lambda_S)_i \f$ for \f$i\in\{1,\dots,n\}\f$ are binary variables and \f$y^\star_i\f$ given by the dual
124
* solution of the restricted master problem.
125
*
126
* The above problem is a knapsack problem which can be solved via dynamic programming or by solving the above integer
127
* program. In this example we implemented a pricer which solves the integer program.
128
*
129
*/
130
131
132
133
/**@page BINPACKING_MAKEFILE The Makefile
134
*
135
* The Makefile is based on the main \SCIP Makefile. This means that all compiling options which are
136
* available for \SCIP are also available for the binpacking project. Below, you find a list
137
* of the most important compiling flags, the values they can take, and a short description. The
138
* values in bold face are the default values.
139
*
140
* - <code>LPS={clp | cpx | none | <b>spx</b>}</code>
141
* <br>
142
* Defines the linear program solver to use:
143
* - <code>clp</code> use COIN-OR CLP
144
* - <code>cpx</code> use IBM CPLEX
145
* - <code>none</code> no LP solver
146
* - <code><b>spx</b></code> use SoPlex
147
*
148
* - <code>OPT={dbg | <b>opt</b>}</code>
149
* <br>
150
* Defines if the projects gets compiled in debug (<code>dbg</code>) mode or
151
* optimized (<code><b>opt</b></code>) mode. In the debug mode all assertions are checked.
152
*
153
* - <code>ZIMPL={false | <b>true</b>}</code>
154
* <br>
155
* Defines if the modeling language ZIMPL should be linked to binary or not.
156
*
157
* In the following we explain the all <b>Makefile targets</b>.
158
*
159
* - <b>lint</b>
160
* <br>
161
* Statically checks the code for uninitialized variables and many other possible problems,
162
* which even do not lead to compiler errors. For this,
163
* the external tool flexelint is needed. The call produces the file <code>lint.out</code>
164
* which contains all the detected warnings. From the experience when developing \SCIP, we strongly
165
* recommend to use such a code checker. It is always a surprising the stuff such tools detect.
166
* <br>
167
*
168
* - <b>clean</b>
169
* <br>
170
* Remove all objective files, libraries, and binaries.
171
* <br>
172
*
173
* - <b>test</b>
174
* <br>
175
* Starts an automated test run based on the SCIP test runs (see \ref TEST "How to run automated tests with SCIP").
176
* <br>
177
*
178
* - <b>tags</b>
179
* <br>
180
* Generates tags which can be used in the editor <b>emacs</b> and <b>xemacs</b>.
181
* <br>
182
*
183
* - <b>depend</b>
184
* <br>
185
* Generates the dependencies for the compiling process.
186
*/