简体   繁体   English

在Pyomo中为约束提供上限和下限的问题

[英]Problems in providing upper and lower bounds to a constraint in Pyomo

I am new to Pyomo. 我是Pyomo的新手。 In the code section below, I am trying to minimize a function such that two other constraints are satisfied. 在下面的代码部分中,我试图最小化一个函数,以便满足其他两个约束。 I have problem with particulary one constraint where I am trying to provide a range by specifying the upper and lower bounds. 我有一个特别的约束问题,我试图通过指定上限和下限来提供一个范围。 The format of the dictionary is, dict[key]=[d,r,p]; 字典的格式为dict [key] = [d,r,p]; 'p' is not used here. 这里不使用'p'。 The decision variable "x" is binary. 决策变量“ x”是二进制的。 The objective is to find out the item(only one) to choose from, such that "d" is minimum for a range of "r" values. 目的是找出要选择的项目(只有一个),以使“ r”值范围内的“ d”最小。 This range of "r" values is given by the "constraint rxlambda_constraint_rule_upper". “ r”值的范围由“ constraint rxlambda_constraint_rule_upper”给出。 So, the objective is to find out the item among the three dictionary items (from dict), so that the value of "d" is minimum for a range of "r" values.T he expected output as I understand should be the first item (as I have put here), as in [2, 0.8 ,0.3] , r =0.8 which less that 0.9 and greater than 0.5 and in this range , d = 2 is the only minimum. 因此,目的是从字典中找出三个字典项中的项,以使“ d”的值在“ r”值的范围内最小。我所期望的预期输出应该是第一个项(如我在此处所述),如[2,0.8,0.3],r = 0.8,其中r小于0.9且大于0.5,并且在此范围内,d = 2是唯一的最小值。 However, I don't understand the cause of this error and have attached the error messege along with the code. 但是,我不了解此错误的原因,并且已将错误信息与代码一起附加。 I am using 'cplex' through neos server. 我正在通过neos服务器使用'cplex'。

# Code #代码
2 RangeSet Declarations

    m : Dim=0, Dimen=1, Size=1, Domain=Integers, Ordered=True, Bounds=(1, 1)
        Virtual
    n : Dim=0, Dimen=1, Size=3, Domain=Integers, Ordered=True, Bounds=(1, 3)
        Virtual

4 Param Declarations

    I : Size=1, Index=None, Domain=Any, Default=None, Mutable=False
        Key  : Value
        None :     1

    J : Size=1, Index=None, Domain=Any, Default=None, Mutable=False
        Key  : Value
        None :     3

    d : Size=3, Index=n, Domain=Any, Default=None, Mutable=False
        Key : Value
          1 :     2
          2 :     3
          3 :     3

    r : Size=3, Index=n, Domain=NonNegativeReals, Default=None, Mutable=False
        Key : Value
          1 :   0.8
          2 :   0.1
          3 :   0.2

1 Var Declarations

    x : Size=3, Index=n

        Key : Lower : Value : Upper : Fixed : Stale : Domain
          1 :     0 :  None :     1 : False :  True : Binary
          2 :     0 :  None :     1 : False :  True : Binary
          3 :     0 :  None :     1 : False :  True : Binary

1 Objective Declarations

    OBJ : Size=1, Index=None, Active=True

        Key  : Active : Sense    : Expression
        None :   True : minimize : 2*x[1] + 3*x[2] + 3*x[3]

2 Constraint Declarations

    rxlambdaConstraintUpper : Size=3, Index=n, Active=True

        Key : Lower : Body       : Upper : Active
          1 :   0.5 : 0.8 * x[1] :   0.9 :   True
          2 :   0.5 : 0.1 * x[2] :   0.9 :   True
          3 :   0.5 : 0.2 * x[3] :   0.9 :   True

    sumxConstraint : Size=3, Index=n, Active=True

        Key : Lower : Body               : Upper : Active
          1 :   1.0 : x[1] + x[2] + x[3] :   1.0 :   True
          2 :   1.0 : x[1] + x[2] + x[3] :   1.0 :   True
          3 :   1.0 : x[1] + x[2] + x[3] :   1.0 :   True

10 Declarations: I J m n x d r OBJ rxlambdaConstraintUpper sumxConstraint

WARNING: DEPRECATION WARNING: the Model.create() method is deprecated.  Call
    Model.create_instance() to create a concrete instance from an abstract
    model.  You do not need to call Model.create() for a concrete model.
WARNING: DEPRECATED: Cannot call Model.create_instance() on a constructed
    model; returning a clone of the current model instance.
Job "xxxxx" submitted to NEOS, password='xxxxx'
Check the following URL for progress report :
"link deleted"
Job "xxxxx" dispatched
password: "XXXXX"
---------- Begin Solver Output -----------
Condor submit: 'neos.submit'
Condor submit: 'watchdog.submit'
Job submitted to NEOS HTCondor pool.
WARNING: Loading a SolverResults object with a warning status into
    model=unknown;
        message from solver=CPLEX 12.7.0.0\x3a integer infeasible.; 0 MIP
        simplex iterations; 0 branch-and-bound nodes; No basis.

2 RangeSet Declarations

    m : Dim=0, Dimen=1, Size=1, Domain=Integers, Ordered=True, Bounds=(1, 1)
        Virtual
    n : Dim=0, Dimen=1, Size=3, Domain=Integers, Ordered=True, Bounds=(1, 3)
        Virtual

4 Param Declarations

    I : Size=1, Index=None, Domain=Any, Default=None, Mutable=False
        Key  : Value
        None :     1
    J : Size=1, Index=None, Domain=Any, Default=None, Mutable=False
        Key  : Value
        None :     3
    d : Size=3, Index=n, Domain=Any, Default=None, Mutable=False
        Key : Value
          1 :     2
          2 :     3
          3 :     3
    r : Size=3, Index=n, Domain=NonNegativeReals, Default=None, Mutable=False
        Key : Value
          1 :   0.8
          2 :   0.1
          3 :   0.2

1 Var Declarations

    x : Size=3, Index=n

        Key : Lower : Value : Upper : Fixed : Stale : Domain
          1 :     0 :  None :     1 : False :  True : Binary
          2 :     0 :  None :     1 : False :  True : Binary
          3 :     0 :  None :     1 : False :  True : Binary

1 Objective Declarations

    OBJ : Size=1, Index=None, Active=True

        Key  : Active : Sense    : Expression
        None :   True : minimize : 2*x[1] + 3*x[2] + 3*x[3]

2 Constraint Declarations

    rxlambdaConstraintUpper : Size=3, Index=n, Active=True

        Key : Lower : Body       : Upper : Active
          1 :   0.5 : 0.8 * x[1] :   0.9 :   True
          2 :   0.5 : 0.1 * x[2] :   0.9 :   True
          3 :   0.5 : 0.2 * x[3] :   0.9 :   True

    sumxConstraint : Size=3, Index=n, Active=True

        Key : Lower : Body               : Upper : Active
          1 :   1.0 : x[1] + x[2] + x[3] :   1.0 :   True
          2 :   1.0 : x[1] + x[2] + x[3] :   1.0 :   True
          3 :   1.0 : x[1] + x[2] + x[3] :   1.0 :   True

10 Declarations: I J m n x d r OBJ rxlambdaConstraintUpper sumxConstraint

Model unknown

  Variables:

    x : Size=3, Index=n

        Key : Lower : Value : Upper : Fixed : Stale : Domain
          1 :     0 :  None :     1 : False :  True : Binary
          2 :     0 :  None :     1 : False :  True : Binary
          3 :     0 :  None :     1 : False :  True : Binary

  Objectives:

    OBJ : Size=1, Index=None, Active=True
ERROR: evaluating expression: No value for uninitialized NumericValue object
    x[1]
        (expression: 2*x[1] + 3*x[2] + 3*x[3])
ERROR: evaluating object as numeric value: OBJ
        (object: <class 'pyomo.core.base.objective.SimpleObjective'>)
    No value for uninitialized NumericValue object x[1]
        Key : Active : Value
        None :   None :  None

  Constraints:

    rxlambdaConstraintUpper : Size=3

ERROR: evaluating expression: No value for uninitialized NumericValue object
    x[1]
        (expression: 0.8 * x[1])
ERROR: evaluating expression: No value for uninitialized NumericValue object
    x[2]
        (expression: 0.1 * x[2])
ERROR: evaluating expression: No value for uninitialized NumericValue object
    x[3]
        (expression: 0.2 * x[3])
        Key : Lower : Body : Upper
          1 :  None : None :  None
          2 :  None : None :  None
          3 :  None : None :  None

    sumxConstraint : Size=3

ERROR: evaluating expression: No value for uninitialized NumericValue object
    x[1]

        (expression: x[1] + x[2] + x[3])

ERROR: evaluating expression: No value for uninitialized NumericValue object
    x[1]

        (expression: x[1] + x[2] + x[3])

ERROR: evaluating expression: No value for uninitialized NumericValue object
    x[1]

        (expression: x[1] + x[2] + x[3])

        Key : Lower : Body : Upper
          1 :  None : None :  None
          2 :  None : None :  None
          3 :  None : None :  None
(1, None)
(2, None)
(3, None)

​

###### The Error log is: ##### ######错误日志为:#####

 2 RangeSet Declarations m : Dim=0, Dimen=1, Size=1, Domain=Integers, Ordered=True, Bounds=(1, 1) Virtual n : Dim=0, Dimen=1, Size=3, Domain=Integers, Ordered=True, Bounds=(1, 3) Virtual 4 Param Declarations I : Size=1, Index=None, Domain=Any, Default=None, Mutable=False Key : Value None : 1 J : Size=1, Index=None, Domain=Any, Default=None, Mutable=False Key : Value None : 3 d : Size=3, Index=n, Domain=Any, Default=None, Mutable=False Key : Value 1 : 2 2 : 3 3 : 3 r : Size=3, Index=n, Domain=NonNegativeReals, Default=None, Mutable=False Key : Value 1 : 0.8 2 : 0.1 3 : 0.2 1 Var Declarations x : Size=3, Index=n Key : Lower : Value : Upper : Fixed : Stale : Domain 1 : 0 : None : 1 : False : True : Binary 2 : 0 : None : 1 : False : True : Binary 3 : 0 : None : 1 : False : True : Binary 1 Objective Declarations OBJ : Size=1, Index=None, Active=True Key : Active : Sense : Expression None : True : minimize : 2*x[1] + 3*x[2] + 3*x[3] 2 Constraint Declarations rxlambdaConstraintUpper : Size=3, Index=n, Active=True Key : Lower : Body : Upper : Active 1 : 0.5 : 0.8 * x[1] : 0.9 : True 2 : 0.5 : 0.1 * x[2] : 0.9 : True 3 : 0.5 : 0.2 * x[3] : 0.9 : True sumxConstraint : Size=3, Index=n, Active=True Key : Lower : Body : Upper : Active 1 : 1.0 : x[1] + x[2] + x[3] : 1.0 : True 2 : 1.0 : x[1] + x[2] + x[3] : 1.0 : True 3 : 1.0 : x[1] + x[2] + x[3] : 1.0 : True 10 Declarations: IJ mnxdr OBJ rxlambdaConstraintUpper sumxConstraint WARNING: DEPRECATION WARNING: the Model.create() method is deprecated. Call Model.create_instance() to create a concrete instance from an abstract model. You do not need to call Model.create() for a concrete model. WARNING: DEPRECATED: Cannot call Model.create_instance() on a constructed model; returning a clone of the current model instance. Job "xxxxx" submitted to NEOS, password='xxxxx' Check the following URL for progress report : "link deleted" Job "xxxxx" dispatched password: "XXXXX" ---------- Begin Solver Output ----------- Condor submit: 'neos.submit' Condor submit: 'watchdog.submit' Job submitted to NEOS HTCondor pool. WARNING: Loading a SolverResults object with a warning status into model=unknown; message from solver=CPLEX 12.7.0.0\\x3a integer infeasible.; 0 MIP simplex iterations; 0 branch-and-bound nodes; No basis. 2 RangeSet Declarations m : Dim=0, Dimen=1, Size=1, Domain=Integers, Ordered=True, Bounds=(1, 1) Virtual n : Dim=0, Dimen=1, Size=3, Domain=Integers, Ordered=True, Bounds=(1, 3) Virtual 4 Param Declarations I : Size=1, Index=None, Domain=Any, Default=None, Mutable=False Key : Value None : 1 J : Size=1, Index=None, Domain=Any, Default=None, Mutable=False Key : Value None : 3 d : Size=3, Index=n, Domain=Any, Default=None, Mutable=False Key : Value 1 : 2 2 : 3 3 : 3 r : Size=3, Index=n, Domain=NonNegativeReals, Default=None, Mutable=False Key : Value 1 : 0.8 2 : 0.1 3 : 0.2 1 Var Declarations x : Size=3, Index=n Key : Lower : Value : Upper : Fixed : Stale : Domain 1 : 0 : None : 1 : False : True : Binary 2 : 0 : None : 1 : False : True : Binary 3 : 0 : None : 1 : False : True : Binary 1 Objective Declarations OBJ : Size=1, Index=None, Active=True Key : Active : Sense : Expression None : True : minimize : 2*x[1] + 3*x[2] + 3*x[3] 2 Constraint Declarations rxlambdaConstraintUpper : Size=3, Index=n, Active=True Key : Lower : Body : Upper : Active 1 : 0.5 : 0.8 * x[1] : 0.9 : True 2 : 0.5 : 0.1 * x[2] : 0.9 : True 3 : 0.5 : 0.2 * x[3] : 0.9 : True sumxConstraint : Size=3, Index=n, Active=True Key : Lower : Body : Upper : Active 1 : 1.0 : x[1] + x[2] + x[3] : 1.0 : True 2 : 1.0 : x[1] + x[2] + x[3] : 1.0 : True 3 : 1.0 : x[1] + x[2] + x[3] : 1.0 : True 10 Declarations: IJ mnxdr OBJ rxlambdaConstraintUpper sumxConstraint Model unknown Variables: x : Size=3, Index=n Key : Lower : Value : Upper : Fixed : Stale : Domain 1 : 0 : None : 1 : False : True : Binary 2 : 0 : None : 1 : False : True : Binary 3 : 0 : None : 1 : False : True : Binary Objectives: OBJ : Size=1, Index=None, Active=True ERROR: evaluating expression: No value for uninitialized NumericValue object x[1] (expression: 2*x[1] + 3*x[2] + 3*x[3]) ERROR: evaluating object as numeric value: OBJ (object: <class 'pyomo.core.base.objective.SimpleObjective'>) No value for uninitialized NumericValue object x[1] Key : Active : Value None : None : None Constraints: rxlambdaConstraintUpper : Size=3 ERROR: evaluating expression: No value for uninitialized NumericValue object x[1] (expression: 0.8 * x[1]) ERROR: evaluating expression: No value for uninitialized NumericValue object x[2] (expression: 0.1 * x[2]) ERROR: evaluating expression: No value for uninitialized NumericValue object x[3] (expression: 0.2 * x[3]) Key : Lower : Body : Upper 1 : None : None : None 2 : None : None : None 3 : None : None : None sumxConstraint : Size=3 ERROR: evaluating expression: No value for uninitialized NumericValue object x[1] (expression: x[1] + x[2] + x[3]) ERROR: evaluating expression: No value for uninitialized NumericValue object x[1] (expression: x[1] + x[2] + x[3]) ERROR: evaluating expression: No value for uninitialized NumericValue object x[1] (expression: x[1] + x[2] + x[3]) Key : Lower : Body : Upper 1 : None : None : None 2 : None : None : None 3 : None : None : None (1, None) (2, None) (3, None)​ 

Your rxlambdaConstraintUpper for 2, 3 is infeasible. 2、3的rxlambdaConstraintUpper是不可行的。

      2 :   0.5 : 0.1 * x[2] :   0.9 :   True
      3 :   0.5 : 0.2 * x[3] :   0.9 :   True 

if x[2] and x[3] takes 0 or 1, they will be less than 0.5 (their lower bound). 如果x [2]和x [3]取0或1,则它们将小于0.5(它们的下界)。 Therefore if you change line 因此,如果您更改线

 return  (0.5, model.r[i]*model.x[i], 0.9 )   

as

 return  (0, model.r[i]*model.x[i], 0.9 ) 

you can reach the working model and result. 您可以获得工作模型和结果。

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

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