简体   繁体   English

整数线性编程程序的行为不符合预期

[英]Integer linear programming program does not behave as expected

I have the following integer linear programming problem which assigns values as expected, but when I add certain constraints, the objective function seems to become vacuous. 我有以下整数线性规划问题,该问题按预期分配值,但是当我添加某些约束时,目标函数似乎变得虚空。 I am not sure what to make of it. 我不确定该怎么做。 I am using python to solve the problem. 我正在使用python解决问题。

Non Vacuous formulation 非空配方

score12 = 1
score21 = -1
C       = 1000000

maximize  : (w12 - s12) * score12 + (w21 - s21) * score21

subject to:
            d12 = x2 - x1
            d21 = x1 - x2

            d12 - w12*C <= 0
            d21 - w21*C <= 0

            d12 + (1 - w12)*C > 0
            d21 + (1 - w21)*C > 0

            d12 + s12*C      >= 0
            d21 + s21*C      >= 0

            0 <= xi <= 1      , continuous
            0 <= wij, sij <= 1, integer

The objective function is as expected: 目标功能符合预期:

MAXIMIZE
-1*s_12 + 1*s_21 + 1*w_12 + -1*w_21 + 0

And the solution is as expected: 并且解决方案符合预期:

('d_12', '= ', 0.0)
('d_21', '= ', 0.0)
('s_12', '= ', 0.0)
('s_21', '= ', 1.0)
('w_12', '= ', 1.0)
('w_21', '= ', 0.0)
('x_1', '= ', 0.0)
('x_2', '= ', 0.0)

But when I add the following constraints, or just either one: 但是,当我添加以下约束或仅一个约束时:

d12 - (1 - s12)*C < 0 
d21 - (1 - s21)*C < 0 

Python changes the objective function to: Python将目标函数更改为:

MAXIMIZE
0*__dummy + False
SUBJECT TO
... omited

I'm not what to make of it, the solution becomes vacuous: 我不是用它做的,解决方案变得空虚:

('__dummy', '= ', None)
('d_12', '= ', 0.0)
('d_21', '= ', 0.0)
('s_12', '= ', 1.0)
('s_21', '= ', 1.0)
('w_12', '= ', 1.0)
('w_21', '= ', 1.0)
('x_1', '= ', 0.0)
('x_2', '= ', 0.0)

I did not analyze your constraints but here is some comment on what kind of problem there might be. 我没有分析您的约束,但是这里有一些关于可能存在的问题的评论。

You are using this to define a constraint: 您正在使用它来定义约束:

d12 - (1 - s12)*C < 0
  • In Linear Programming, there are only inequalities of the form <= and >= ( == may be constructed by these; ignoring numerical difficulties); 在线性编程中,仅存在<=>=形式的不等式( ==可以由这些构造;忽略数值困难); everything else is just not natural (not much sense in regards to the math) 其他一切都不自然(数学上没有太多意义)
  • pulp-or only defines the mentioned operators above; 纸浆-或仅定义上面提到的运算符; but not < and > link; 但不是<> 链接; scroll to bottom; 滚动到底部; also see next image from the docs 另请参阅文档中的下一张图片

在此处输入图片说明

Pulp is not that robust about wrong usage of the library and usually and silently overwrites the objective when some badly formed constraint is added (This might be the case here). Pulp对于错误使用库的能力不强,通常在添加一些格式错误的约束时会悄无声息地覆盖目标 (此处可能就是这种情况)。 Maybe you will find some experiences like that in pulp's issue-tracker 也许您会在纸浆的问题跟踪器中找到类似的体验

Consider using the Constraint-class and not using overloaded-operators. 考虑使用约束类而不使用重载运算符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM