有没有可能在PuLP
中利用LpVariables的配对来制定约束?你知道吗
更具体地说,假设我有LpVariablesx1
,x2
。。。x100
(所有二进制范畴),每一个都代表一个对象。所有这些对象都有一个type
属性,即1
、2
、3
或4
,还有一个group
属性,也是1
、2
、3
或4
。你知道吗
如何创建以下约束(我不确定在PuLP
中如何创建):
解决方案中的两个变量必须在同一个group
(可以是任何group
)中,一个必须是1
类型,另一个必须是2
类型。你知道吗
解本身是每个单个变量,其中8个变量的值为True
(表示它们是解的一部分),其余变量的值为False
(表示它们不是解的一部分),由无数其他约束选择。你知道吗
因此,我想在布尔逻辑中为解决方案添加的约束是:
(type 1 object in group 1 AND type 2 object in group 1) OR
(type 1 object in group 2 AND type 2 object in group 2) OR
(type 1 object in group 3 AND type 2 object in group 3) OR
(type 1 object in group 4 AND type 2 object in group 4)
此外,有没有一种方法可以将这个约束抽象到纸浆中的n
组?你知道吗
下面是一个完整的工作示例,可以满足您的需要。它应该产生下面的输出。如您所见,选择了8个x,并且遵守了至少从类型1(在我的示例中为类型0)和类型2(在我的示例中为类型1)中选择一个的规则,以及至少一个组中有两个选择的变量的要求。你知道吗
解决这个问题的诀窍如this question的答案所述
自给自足的示例,随心所欲(Python3):
相关问题 更多 >
编程相关推荐