最小化问题的reformulation

以一个最简单的线性规划问题为例。
min ⁡    0.02 x 1 + 0.07 x 2 + 0.04 x 3 + 0.03 x 4 + 0.05 x 5 s.t. 0.3 x 1 + 2 x 2 + x 3 + 0.6 x 4 + 1.8 x 5 > = 70 0.1 x 1 + 0.05 x 2 + 0.02 x 3 + 0.2 x 4 + 0.05 x 5 > = 3 0.05 x 1 + 0.1 x 2 + 0.02 x 3 + 0.2 x 4 + 0.08 x 5 > = 9.1 (1) \begin{aligned} \min \,\,&0.02x1 + 0.07x2 + 0.04x3 + 0.03x4 + 0.05x5\\ \text{s.t.}&0.3x1 + 2x2 + x3 + 0.6x4 + 1.8x5 >= 70\\ &0.1x1 + 0.05x2 + 0.02x3 + 0.2x4 + 0.05x5 >= 3\\ &0.05x1 + 0.1x2 + 0.02x3 + 0.2x4 + 0.08x5 >= 9.1 \tag{1} \end{aligned} mins.t.0.02x1+0.07x2+0.04x3+0.03x4+0.05x50.3x1+2x2+x3+0.6x4+1.8x5>=700.1x1+0.05x2+0.02x3+0.2x4+0.05x5>=30.05x1+0.1x2+0.02x3+0.2x4+0.08x5>=9.1(1)
使用Gurobi进行求解,python代码如下:

from gurobipy import *

# Create a new model
m = Model()

# Create variables
x1 = m.addVar(name="x1")
x2 = m.addVar(name="x2")
x3 = m.addVar(name="x3")
x4 = m.addVar(name="x4")
x5 = m.addVar(name="x5")
phi = m.addVar(name="phi")

# Set objective function
m.setObjective(0.02 * x1 + 0.07 * x2 + 0.04 * x3 + 0.03 * x4 + 0.05 * x5)

# Add constraints
m.addConstr(0.3 * x1 + 2 * x2 + x3 + 0.6 * x4 + 1.8 * x5 >= 70, "c2")
m.addConstr(0.1 * x1 + 0.05 * x2 + 0.02 * x3 + 0.2 * x4 + 0.05 * x5 >= 3, "c3")
m.addConstr(0.05 * x1 + 0.1 * x2 + 0.02 * x3 + 0.2 * x4 + 0.08 * x5 >= 9.1, "c4")

# Optimize model
m.optimize()

# Print values for decision variables
for v in m.getVars():
    print(v.varName, v.x)

# Print maximized profit value
print('Maximized profit:',  m.objVal)

问题(1)等价于:
min ⁡    ϕ s.t. ϕ ≥ 0.02 x 1 + 0.07 x 2 + 0.04 x 3 + 0.03 x 4 + 0.05 x 5 0.3 x 1 + 2 x 2 + x 3 + 0.6 x 4 + 1.8 x 5 > = 70 0.1 x 1 + 0.05 x 2 + 0.02 x 3 + 0.2 x 4 + 0.05 x 5 > = 3 0.05 x 1 + 0.1 x 2 + 0.02 x 3 + 0.2 x 4 + 0.08 x 5 > = 9.1 (2) \begin{aligned} \min \,\,&\phi\\ \text{s.t.}&\phi\ge 0.02x1 + 0.07x2 + 0.04x3 + 0.03x4 + 0.05x5\\ &0.3x1 + 2x2 + x3 + 0.6x4 + 1.8x5 >= 70\\ &0.1x1 + 0.05x2 + 0.02x3 + 0.2x4 + 0.05x5 >= 3\\ &0.05x1 + 0.1x2 + 0.02x3 + 0.2x4 + 0.08x5 >= 9.1 \tag{2} \end{aligned} mins.t.ϕϕ0.02x1+0.07x2+0.04x3+0.03x4+0.05x50.3x1+2x2+x3+0.6x4+1.8x5>=700.1x1+0.05x2+0.02x3+0.2x4+0.05x5>=30.05x1+0.1x2+0.02x3+0.2x4+0.08x5>=9.1(2)
使用Gurobi进行求解,python代码如下:

from gurobipy import *

# Create a new model
m = Model()

# Create variables
x1 = m.addVar(name="x1")
x2 = m.addVar(name="x2")
x3 = m.addVar(name="x3")
x4 = m.addVar(name="x4")
x5 = m.addVar(name="x5")
phi = m.addVar(name="phi")

# Set objective function
m.setObjective(phi)

# Add constraints
m.addConstr(phi >= 0.02 * x1 + 0.07 * x2 + 0.04 * x3 + 0.03 * x4 + 0.05 * x5, "c1")
m.addConstr(0.3 * x1 + 2 * x2 + x3 + 0.6 * x4 + 1.8 * x5 >= 70, "c2")
m.addConstr(0.1 * x1 + 0.05 * x2 + 0.02 * x3 + 0.2 * x4 + 0.05 * x5 >= 3, "c3")
m.addConstr(0.05 * x1 + 0.1 * x2 + 0.02 * x3 + 0.2 * x4 + 0.08 * x5 >= 9.1, "c4")

# Optimize model
m.optimize()

# Print values for decision variables
for v in m.getVars():
    print(v.varName, v.x)

# Print maximized profit value
print('Maximized profit:',  m.objVal)

你可能感兴趣的:(优化,学习)