【问题标题】:2D decision variables in PuLP纸浆中的二维决策变量
【发布时间】:2020-09-16 01:05:33
【问题描述】:

我是 PuLP 的新手,我正在尝试运行一个优化问题,其中我的一个决策变量是 2D。我对如何将 2D 决策变量声明为 plp.LpVariable 的一部分感到有些困惑?到目前为止,这就是我声明变量的方式

a = { k : plp.LpVariable(name='a', lowBound=np.array([0, 0]), \
                         upBound=np.array([2, 3]), \
                         cat=plp.LpContinuous) for k in range(10)}

谢谢!

【问题讨论】:

    标签: pulp integer-programming


    【解决方案1】:

    欢迎来到 SO!您正在寻找的是 LpVariable 类的 dicts 方法。这允许您传入多维索引以创建 M x N 或 M x N x O(等)变量集。

    它的用法在解决数独难题的纸浆文档示例中进行了说明:https://coin-or.github.io/pulp/CaseStudies/a_sudoku_problem.html?highlight=dicts

    这里记录了方法本身: https://coin-or.github.io/pulp/technical/pulp.html?highlight=dicts#pulp.LpVariable.dicts

    据我所知,该方法不能直接接受每个变量不同的上限和下限,因此您需要执行以下操作:

    up_bounds = [2,3]
    a = pulp.LpVariable.dicts('a', range(2), lowBound=0)
    for i in range(2):
        prob += a[i] <= up_bounds[i]
    

    【讨论】:

    • 非常感谢您的帮助!我很快就会试试这个! :)
    猜你喜欢
    • 2022-01-10
    • 2020-08-28
    • 2020-08-06
    • 1970-01-01
    • 2021-02-08
    • 2020-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多