Hussain K
Hussain K

Reputation: 21

Getting None value for a pyomo Variable after solving the model

I have solved a model called llbp. The status for the result object is coming as optimal . But, for one of the variables the values is coming as None and hence I am unable to access the objective value.

In: if (llbp_result.solver.status == SolverStatus.ok) and (llbp_result.solver.termination_condition == TerminationCondition.optimal):
        print ("this is feasible and optimal")
Out: this is feasible and optimal
In: llbp.obj.expr()
Out: ERROR: evaluating object as numeric value: x[89]
        (object: <class 'pyomo.core.base.var._GeneralVarData'>)
    No value for uninitialized NumericValue object x[89]
In: llbp.x[89].value == None
Out: True

Upvotes: 0

Views: 1372

Answers (2)

gmavrom
gmavrom

Reputation: 440

What @rodri says is probably true, that a variable's value is given as None because it does not appear in any constraint or in the objective function.

To address that, you can use initialize=0 when you define the variables. For example:

model.V = Var(initialize=0)

Of course you can also add any other arguments related to Pyomo sets, within statements etc.

Upvotes: 2

rodri
rodri

Reputation: 1

The same thing happened to me. In my case, the solver put some variables to None because they didn't appear in the objective function or any other constraint. Or, rather, they appeared multiplied by a parameter with value 0. Check if this is also happening in your model

Upvotes: 0

Related Questions