最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Constraint.Feasible does not return callable constraints - Stack Overflow

programmeradmin4浏览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).

发布评论

评论列表(0)

  1. 暂无评论