【问题标题】:PuLP not holding onto Integer Category纸浆不保留整数类别
【发布时间】:2015-04-08 15:30:54
【问题描述】:

所以在我的代码中,我正在为不同类型的变量编写一个线性程序。有 6 个。第一个是产品的“x”变量,其余 5 个是盒子的“w”变量(五个不同大小的盒子)。我需要所有这些都是整数,但是,在我的输出中,我将 x 变量设为整数,但框大小都是非整数。我已经尝试了 100 种不同的方法,但我无法弄清楚。

对于 varset 中的 ind:

    maxID = skunulldict[ind]
    sky = maxquant[maxID]
    globals()[ind] = pulp.LpVariable(ind, 0, sky, cat='Integer')
for indd in contset20:
    vn = contvendor[indd]
    capC = vv20[vn]
    globals()[indd] = pulp.LpVariable(indd, 0, capC, cat='Integer')
for indds in contset40:
    vns = contvendor[indds]
    capC = vv40[vns]
    globals()[indds] = pulp.LpVariable(indds, 0, capC, cat='Integer')
for indd in contset2b:
    vn = contvendor[indd]
    capC = vv2b[vn]
    globals()[indd] = pulp.LpVariable(indd, 0, capC, cat='Integer')
for indd in contset4b:
    vn = contvendor[indd]
    capC = vv4b[vn]
    globals()[indd] = pulp.LpVariable(indd, 0, capC, cat='Integer')
for indd in contsetcs:
    vn = contvendor[indd]
    capC = vvcs[vn]
    globals()[indd] = pulp.LpVariable(indd, 0, capC, cat='Integer')

【问题讨论】:

    标签: python-2.7 integer glpk pulp


    【解决方案1】:

    提供的变量定义似乎没问题。 您可以尝试将变量的类别打印到控制台,以在源的不同部分验证它们的整数类别。

    for x in modell.variables():
        print "Name:       ", x.name
        print "Category:   ", x.cat
    

    您的问题可能位于代码的另一部分。要获得更高级的答案,需要工作示例或代码的其他部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多