简体   繁体   English

获取纸浆目标函数的最小值最大值

[英]Get minimum of maximize value on pulp objective function

I'm trying to use pulp to get minimum value U(X) of following objective function,我正在尝试使用纸浆来获得以下目标函数的最小值U(X) 目标函数

where x_{f,i,v} is binary value.其中x_{f,i,v}是二进制值。

And I'm having problem while writing max() when set an objective function to pulp.LpProblem .在将目标函数设置为pulp.LpProblem时,我在编写max()时遇到了问题。

What I do is use python inner function max() but it gives me an error.我所做的是使用 python 内部函数max()但它给了我一个错误。 Seems like it cannot be used to pulp.好像不能用来打浆。

    for each_sfc in self.SFCs:
        vnf_id_list = list()
        for each_VNF in each_sfc.VNF_list:
            vnf_id_list.append(str(each_VNF.ID))

        new_sfc_vars = LpVariable.dicts(
            name='X',
            indexs=vnf_id_list,
            lowBound=0,
            upBound=1,
            cat='Continuous'
        )

        for each_key in new_sfc_vars.keys():
            new_sfc_vars[each_key] = 1 - new_sfc_vars[each_key]

        self.sfc_vars.append(new_sfc_vars)

    self.LP_model = LpProblem(
        name="Static backup",
        sense=LpMinimize
    )

    for each_SFC, each_vars in zip(self.SFCs, self.sfc_vars):
        self.LP_model.objective += each_SFC.backup_cost * max(each_vars.values())
    print(self.LP_model.objective)

How can I use max() with pulp or how can I reformulate the code?如何将max()与纸浆一起使用或如何重新编写代码?

This is a very basic question.这是一个非常基本的问题。

  1. max() is not linear. max()不是线性的。 Linear expressions look like a1*x1+a2*x2+... .线性表达式看起来像a1*x1+a2*x2+... PuLP is for linear models only, so it only allows linear expressions in the objective and the constraints. PuLP 仅用于线性模型,因此它只允许目标和约束中的线性表达式。 Note that some modeling tools have a max function, but they typically linearize this under the hood.请注意,某些建模工具具有 max 函数,但它们通常会在幕后对其进行线性化。

  2. A very standard formulation for a construct like min sum(i, max(j, x(i,j)) ismin sum(i, max(j, x(i,j))这样的构造的一个非常标准的公式是

    min sum(i, y(i)) y(i) >= x(i,j) for all i,j
  3. Just consult any LP textbook.只需查阅任何 LP 教科书即可。 It will explain this formulation.它将解释这个公式。 Often this is called minimax .通常这称为minimax

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

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