如何在Gurobipy中编写这个约束?

2024-10-02 18:17:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Gurobipy编写一个线性程序,并且在编写一个约束时遇到了问题。我对如何求<;0不等式的和感到困惑。你知道吗

约束如下:https://imgur.com/a/FP0aAKl

我已经初始化了变量xC和xP(我称之为xPone)。参数B也已经被定义,并且包含在一个名为B的字典中。你知道吗

这是我当前的代码:

m = Model('LP')

m.addConstrs((xC_smp[s,m,p] == - quicksum (B[(s,n,m,p)] * xPone_slnmonep[s,l,n,mone,p]) 
                                       for m in materials for s in sites for l in lines
                                       for n in versions for p in periods for mone in materialones 
                                       if B[(s,n,m,p)] < 0), name='c7')

当前返回一个空集{}。我希望里面有一些价值观。如果有人能指出这个问题,我将不胜感激。谢谢。你知道吗


Tags: inhttpslt程序comfor参数线性
1条回答
网友
1楼 · 发布于 2024-10-02 18:17:10

这可能是工作:

m.addConstrs( quicksum((xC_smp[s,m,p] for m in materials for s in sites for p in periods))  == 
            - quicksum ((B[(s,n,m,p)] * xPone_slnmonep[s,l,n,mone,p] for m in materials 
                               for s in sites for l in lines for n in versions 
                               for p in periods for mone in materialones 
                                   if B[(s,n,m,p)] < 0), name='c7')

相关问题 更多 >