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).