0

I am currently working with an LP-problem and Pyomo. There I am generating different constraints based on some input parameters. The structure of the constraint generation is the following:

The constraints and variables are constructed within the model-initiating function itself and hence linked to the model (=self). The parameters and the corresponding variable indices are given by a list of tuples inputParameterAndVarList. The variables are given by self.x.

self.constraints = pyo.Constraint(inputParameterAndVarList, rule = constraintGenerationRule)

def constraintGenerationRule(self, inputParameter, varIndex):
    if inputParameter > 0:
        returnResult = inputParameter * self.x[varIndex]
    else:
        returnResult = pyo.Constraint.Feasible

return returnResult

If I now run the code, the constraints are only constructed if the input parameter > 0. Hence, the number of constraints is smaller than the number of tuples in the inputParameterAndVarList. Thus, I also cannot call the constraints, which have been constructed by pyo.Constraint.Feasible and receive an error instead (key not found).

Actually, Constraint.Feasible somehow behaves as Constraint.Skip. Has anyone an idea why this is happening and how to encounter it? Returning (0,0,0) instead of Constraint.Feasible does the trick for now (but I'd prefer to use Constraint.Feasible for better clarity, readability and code consistency).

1
  • What do you mean by "call the constraint"? You should just be constructing them for the model. The function you have above is creating an expression not a constraint, which would normally be a relational expression (==, <=, >=) Commented Mar 26 at 13:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.