简体   繁体   English

纸浆中的二维决策变量

[英]2D decision variables in PuLP

I am new to PuLP, and I am trying to run an optimization problem where one of my decision variables is 2D.我是 PuLP 的新手,我正在尝试运行一个优化问题,其中我的一个决策变量是 2D。 I'm a little confused as to how one can declare 2D decision variables as part of plp.LpVariable?我对如何将 2D 决策变量声明为 plp.LpVariable 的一部分感到有些困惑? As of now, this is how I am declaring the variable截至目前,这就是我声明变量的方式

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

Thanks!谢谢!

Welcome to SO!欢迎来到 SO! What you are looking for is the dicts method of the LpVariable class.您正在寻找的是LpVariable class 的dicts方法。 This allows you to pass in multi-dimensional indexes to create an M x N, or M x N x O (etc.) set of variables.这允许您传入多维索引以创建 M x N 或 M x N x O(等)变量集。

It's use is illustrated in the pulp docs example of solving a sudoku puzzle: https://coin-or.github.io/pulp/CaseStudies/a_sudoku_problem.html?highlight=dicts它的用途在解决数独难题的纸浆文档示例中进行了说明: https://coin-or.github.io/pulp/CaseStudies/a_sudoku_problem.ZFC35FDC70D52FC69DE36

And the method itself is documented here: https://coin-or.github.io/pulp/technical/pulp.html?highlight=dicts#pulp.LpVariable.dicts该方法本身记录在此: https://coin-or.github.io/pulp/technical/pulp.html?highablelight.plsLdicts

As far as I know the method cannot directly accept upperbounds and lowerbounds which are different for each variable, so you'd need to do something like:据我所知,该方法不能直接接受每个变量不同的上限和下限,因此您需要执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM