python - Gurobi 多目标函数分层退化

标签 python python-3.x gurobi

我正在尝试实现一个具有多个目标函数(特别是 2 个)的 Gurobi 模型,该模型按字典顺序(在层次结构中)求解,但我遇到了一个问题,在优化第二个目标函数时,它会将解决方案降级为第一个一,这不应该发生在分层优化中。它将第一个解决方案降低 1,将第二个解决方案降低 5,这可能是我如何分层设置模型的错误吗?这是我设置模型的代码:

    m = Model('lexMin Model')
    m.ModelSense = GRB.MINIMIZE
    variable = m.addVars(k.numVars, vtype=GRB.BINARY, name='variable') 
    m.setObjectiveN(LinExpr(quicksum([variable[j]*k.obj[0][j] for j in range(k.numVars)])),0)
    m.setObjectiveN(LinExpr(quicksum([variable[j]*k.obj[1][j] for j in range(k.numVars)])),1)

    for i in range(0,k.numConst): 
        m.addConstr(quicksum([k.const[i,j]*variable[j] for j in range(k.numVars)] <= k.constRHS[i]))

        m.addConstr(quicksum([variable[j]*k.obj[0][j] for j in range(k.numVars)]) >= r2[0][0])
        m.addConstr(quicksum([variable[j]*k.obj[0][j] for j in range(k.numVars)]) <= r2[1][0])
        m.addConstr(quicksum([variable[j]*k.obj[1][j] for j in range(k.numVars)]) >= r2[1][1])
        m.addConstr(quicksum([variable[j]*k.obj[1][j] for j in range(k.numVars)]) <= r2[0][1])

    m.Params.ObjNumber = 0
    m.ObjNPriority = 1
    m.update()
    m.optimize()

我已经仔细检查过,第二个函数的优先级是 0,目标函数的值与我将错误的函数优先级排序时的值相去甚远。当优化第一个函数时,它甚至找到了正确的值,但是当它移动到第二个值时,它选择的值会降低第一个值。

Gurobi 输出如下所示:

Optimize a model with 6 rows, 375 columns and 2250 nonzeros
Model fingerprint: 0xac5de9aa
Variable types: 0 continuous, 375 integer (375 binary)
Coefficient statistics:
  Matrix range     [1e+01, 1e+02]
  Objective range  [1e+01, 1e+02]
  Bounds range     [1e+00, 1e+00]
  RHS range        [1e+04, 1e+04]

---------------------------------------------------------------------------
Multi-objectives: starting optimization with 2 objectives ... 
---------------------------------------------------------------------------

Multi-objectives: applying initial presolve ...
---------------------------------------------------------------------------

Presolve time: 0.00s
Presolved: 6 rows and 375 columns
---------------------------------------------------------------------------

Multi-objectives: optimize objective 1 () ...
---------------------------------------------------------------------------

Presolve time: 0.00s
Presolved: 6 rows, 375 columns, 2250 nonzeros
Variable types: 0 continuous, 375 integer (375 binary)

Root relaxation: objective -1.461947e+04, 10 iterations, 0.00 seconds

    Nodes    |    Current Node    |     Objective Bounds      |     Work
 Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

     0     0 -14619.473    0    3          - -14619.473      -     -    0s
H    0     0                    -14569.00000 -14619.473  0.35%     -    0s
H    0     0                    -14603.00000 -14619.473  0.11%     -    0s
H    0     0                    -14608.00000 -14619.473  0.08%     -    0s
H    0     0                    -14611.00000 -14618.032  0.05%     -    0s
     0     0 -14617.995    0    5 -14611.000 -14617.995  0.05%     -    0s
     0     0 -14617.995    0    3 -14611.000 -14617.995  0.05%     -    0s
H    0     0                    -14613.00000 -14617.995  0.03%     -    0s
     0     0 -14617.995    0    5 -14613.000 -14617.995  0.03%     -    0s
     0     0 -14617.995    0    5 -14613.000 -14617.995  0.03%     -    0s
     0     0 -14617.995    0    7 -14613.000 -14617.995  0.03%     -    0s
     0     0 -14617.995    0    3 -14613.000 -14617.995  0.03%     -    0s
     0     0 -14617.995    0    4 -14613.000 -14617.995  0.03%     -    0s
     0     0 -14617.995    0    6 -14613.000 -14617.995  0.03%     -    0s
     0     0 -14617.995    0    6 -14613.000 -14617.995  0.03%     -    0s
     0     0 -14617.995    0    6 -14613.000 -14617.995  0.03%     -    0s
     0     0 -14617.720    0    7 -14613.000 -14617.720  0.03%     -    0s
     0     0 -14617.716    0    8 -14613.000 -14617.716  0.03%     -    0s
     0     0 -14617.697    0    8 -14613.000 -14617.697  0.03%     -    0s
     0     0 -14617.661    0    9 -14613.000 -14617.661  0.03%     -    0s
     0     2 -14617.661    0    9 -14613.000 -14617.661  0.03%     -    0s
*  823     0              16    -14614.00000 -14616.351  0.02%   2.8    0s

Cutting planes:
  Gomory: 6
  Cover: 12
  MIR: 4
  StrongCG: 2
  Inf proof: 6
  Zero half: 1

Explored 1242 nodes (3924 simplex iterations) in 0.29 seconds
Thread count was 8 (of 8 available processors)

Solution count 6: -14614 -14613 -14611 ... -14569
No other solutions better than -14614

Optimal solution found (tolerance 1.00e-04)
Best objective -1.461400000000e+04, best bound -1.461400000000e+04, gap 0.0000%
---------------------------------------------------------------------------

Multi-objectives: optimize objective 2 () ...
---------------------------------------------------------------------------


Loaded user MIP start with objective -12798

Presolve removed 1 rows and 0 columns
Presolve time: 0.01s
Presolved: 6 rows, 375 columns, 2250 nonzeros
Variable types: 0 continuous, 375 integer (375 binary)

Root relaxation: objective -1.282967e+04, 28 iterations, 0.00 seconds

    Nodes    |    Current Node    |     Objective Bounds      |     Work
 Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

     0     0 -12829.673    0    3 -12798.000 -12829.673  0.25%     -    0s
     0     0 -12829.378    0    4 -12798.000 -12829.378  0.25%     -    0s
     0     0 -12829.378    0    3 -12798.000 -12829.378  0.25%     -    0s
     0     0 -12828.688    0    4 -12798.000 -12828.688  0.24%     -    0s
H    0     0                    -12803.00000 -12828.688  0.20%     -    0s
     0     0 -12825.806    0    5 -12803.000 -12825.806  0.18%     -    0s
     0     0 -12825.193    0    5 -12803.000 -12825.193  0.17%     -    0s
     0     0 -12823.156    0    6 -12803.000 -12823.156  0.16%     -    0s
     0     0 -12822.694    0    7 -12803.000 -12822.694  0.15%     -    0s
     0     0 -12822.679    0    7 -12803.000 -12822.679  0.15%     -    0s
     0     2 -12822.679    0    7 -12803.000 -12822.679  0.15%     -    0s

Cutting planes:
  Cover: 16
  MIR: 6
  StrongCG: 3
  Inf proof: 4
  RLT: 1

Explored 725 nodes (1629 simplex iterations) in 0.47 seconds
Thread count was 8 (of 8 available processors)

Solution count 2: -12803 -12798 
No other solutions better than -12803

Optimal solution found (tolerance 1.00e-04)
Best objective -1.280300000000e+04, best bound -1.280300000000e+04, gap 0.0000%

因此它找到值 (-14613,-12803) 而不是 (-14614,-12798)

最佳答案

默认MIPGap是 1e-4。第一个目标是降级小于此。 (1/14614 =~ 0.7 e-4)。如果您降低 MIPGap,您的问题应该会消失。在你的代码中添加

m.setObjective('MipGap', 1e-6)

优化前。

推断此行为的一种方法是,由于您的 MIPGap 为 1e-4,因此即使您没有第二个目标,您也会接受值为 -14113 的解。

关于python - Gurobi 多目标函数分层退化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60941734/

相关文章:

python - 使用内部命令窗口 Python 工具和 Visual Studio 2013 进行调试

Python无法读取环境变量

python-3.x - 在 python 中使用 selenium 禁用 webdriver 的控制台输出

python3 时间戳字符串中的纪元

python-3.x - 使用 re.search() 在字符串中搜索模式,模式包含 '+' 字符

c++ - 如何创建一个四维指针数组?

python - 在 Python Gurobi 中删除变量

python - 打开简历,img [x,y]总是返回0

Python - 绘制天线辐射模式

python - gurobi 6.0.2/setPWLObj 的分段线性目标崩溃