Pyomo Variable with Bounds=(0.0, None) getting a Minus Value

1.7k views Asked by At

I am using a pyomo-Concreate Model and in this model there is a pyomo variable called Lambda, which is bounded with (0.0, None) and within=Non.NegativeReals.

The problem is after solving the model it somehow gets a minus value, which should not happen.

What do you think the problem can be?

PS: I am using GLPK Solver v4.61 to solve the model.

Here is the declaration of the variable Lambda, and also the results:

    m.Lambda = pyomo.Var(
        within=pyomo.NonNegativeReals,
        bounds=(0.0, None),
        doc='Sub Problem Objective')

Check the last iteration, even though the results are right, lambda should not have a value of minus something???

1

There are 1 answers

0
Gabe Hackebeil On BEST ANSWER

In addition to Bethany's comment, and in a more general sense, all solvers need use built in tolerances due to the use of finite-precision arithmetic to solve your model. Although the output you link to is negative in the last iteration, it is negative by a small enough amount that it was likely deemed feasible based on the tolerance used by your solver. You can likely tighten this tolerance using options for your solver, but, in the end, you will need to use tolerances in your own code when you do additional checks for whatever algorithm you are scripting (e.g., assert var.value <= var.ub + feas_abstol, where feas_abstol is set to some small number like 1e-8 somewhere in your code).