Integer programming of type 0 −1 is a special case of integer programming whose variables only take the value 0 or 1. at this time called
0-1 variable, or binary variable. The condition that only takes the value 0 or 1 is subject to the following constraints:
The replacement of integers is consistent with the constraint form of general integer programming. In practical problems, if 0 −1 variables are introduced, the linear programming problems that need to be discussed separately in various situations can be unified in one problem. We first introduce the practical problem of introducing 0 −1 variables.
1. Mathematical modeling process
Selection of Investment Sites - Mutually Exclusive Programs
Example 4 A company intends to establish sales offices in the east, west and south districts of the city. There are 7 positions (points) to choose from in the proposal. Regulation:
in the Eastside. Choose at most two of the three points;
in the West End. At least one of the two points is selected;
In the South Zone, at least one of the two points is selected.
If the point is , the equipment investment is estimated to be RMB, and the annual profit is estimated to be RMB , but the total investment cannot exceed RMB. ask
Which points should be chosen to maximize annual profit?
When solving the problem, first introduce the 0 −1 variable so that
So the problem can be written as:
2. Mutually exclusive constraints
There are two mutually exclusive constraints
Introducing a 0 −1 variable y , the above constraints can be rewritten as:
where M is a sufficiently large number. Restrictions
can be rewritten as
If there are m mutually exclusive constraints:
In order to ensure that only one of the constraints works, we introduce 0 −1 variables and a sufficiently large constant , and the following set of constraints
meet the above requirements. This is because, due to (2), only one of m can take a value of 0. If , is substituted into (1), only the constraints will work, and other expressions are redundant.
3. Fixed Cost Problem
Fixed cost (fixed cost) problems cannot be described by general linear programming, but can be solved by changing to mixed integer programming, see the example below.
Example 5 In order to produce a certain product, a factory has several different production methods to choose from. For example, the selected production method has high investment (purchasing equipment with a high degree of automation), and due to the large output, it is allocated to each product. Variable costs are reduced; conversely, if the investment in the selected production method is low, the variable costs allocated to each product may increase in the future. So it must be considered comprehensively. There are three ways to choose from, so:
- Indicates the output when the jth method is adopted;
- represents the variable cost of each product when using the jth way;
- Indicates the fixed cost when using the jth way.
In order to illustrate the characteristics of cost, other constraints are not considered for the time being. The total cost of using the various production methods is:
When composing the objective function, in order to discuss it in one problem uniformly, 0 −1 variables are now introduced , let
So the objective function
(3) This requirement can be expressed as the following three linear constraints:
where is a sufficiently small positive number and is a sufficiently large positive number. Must be 1 when > 0; only meaningful when = 0 is 0.
Take a chestnut:
4. Programming implementation
Implemented in Python
import pulp
InvestLP = pulp.LpProblem("0 −1型整数规划问题", sense=pulp.LpMaximize) # 定义问题,求最大值
x1= pulp.LpVariable('x1', cat='Binary') # 定义 x1
x2= pulp.LpVariable('x2', cat='Binary') # 定义 x2
x3= pulp.LpVariable('x3', cat='Binary') # 定义 x3
InvestLP += (3*x1 - 2*x2 + 5*x3 ) # 设置目标函数 f(x)
InvestLP += (x1 + 2*x2 - x3 <= 2) # 不等式约束
InvestLP += (x1 + 4*x2 + x3 <= 4)
InvestLP += (x1 +x2 <= 3)
InvestLP += (4*x2 +x3 <= 6)
InvestLP.solve()
print(InvestLP.name) # 输出求解状态
print("求解状态:", pulp.LpStatus[InvestLP.status]) # 输出求解状态
for v in InvestLP.variables():
print(v.name, "=", v.varValue) # 输出每个变量的最优值
print("目标函数值 =", pulp.value(InvestLP.objective)) # 输出最优解的目标函数值
Output result:
0 −1型整数规划问题
求解状态: Optimal
x1 = 1.0
x2 = 0.0
x3 = 1.0
目标函数值 = 8.0