【问题标题】:Printing indices of 3-dimensional variable in PuLP for scheduling在 PuLP 中打印 3 维变量的索引以进行调度
【发布时间】:2016-09-09 07:15:33
【问题描述】:

我正在使用 SolverStudio(Excel 插件)和 PuLP(基于 Python 的优化语言)创建一个将学生分配到工作地点的工具。

这是我要打印其索引的变量:

# Decision variable, =1 if student s is assigned to working place w on day d; 0 otherwise Assignment = LpVariable.dicts("Assignment",(Students,Working_places,Days),0,1,LpBinary)

对于每个工作地点和日期,我想输出分配在那里的学生的姓名,以便创建时间表。

我目前的做法是:

for w in Working_places:
    for d in Days:
        for s in Students:
            if Assignment[s][w][d] == 1:
                Schedule[w,d] = Name[s]

Schedule[w,d] 是在 SolverStudio 中定义的空二维参数,Name[s] 包含学生的姓名。

我将代码序列放置在模型的不同位置。无论是在prob.solve() 语句之前还是之后,都没有区别。

目前,Schedule[w,d] 被学生列表中最后一个学生的姓名填满。

我观察到 if 子句被完全忽略。我可以删除它并生成相同的输出。

是否有不同的方式告诉 Python“对于每个工作地点和日期,打印分配的学生”?

非常感谢您!

【问题讨论】:

    标签: python optimization scheduling pulp


    【解决方案1】:

    同时自己也发现了错误:

    for w in Working_places: for d in Days: for s in Students: if Assignment[s][w][d].varValue == 1: Schedule[w,d] = Name[s]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 2021-06-30
      • 1970-01-01
      • 1970-01-01
      • 2013-05-10
      • 1970-01-01
      相关资源
      最近更新 更多