0

조건식을 가진 목적 함수를 사용하는 것이 가능합니까?Pyomo와 조건부 목적 함수

워드 프로세서에서 예를 변경, 내가 좋아하는 표현하고자이이 같은 직접 모델링 할 수

def objective_function(model): 
    return model.x[0] if model.x[1] < const else model.x[2] 

model.Obj = Objective(rule=objective_function, sense=maximize) 

또는 내가 (만약 그렇다면 어떻게 것 표정이 변화의 일종을 고려해야 할 처럼)? 대신 변수 식의, 내가 Pyomo 내가 값을 얻을 싶은 생각하기 때문에 생각

Evaluating Pyomo variables in a Boolean context, e.g. 
    if expression <= 5: 
is generally invalid. If you want to obtain the Boolean value of the 
expression based on the current variable values, explicitly evaluate the 
expression using the value() function: 
    if value(expression) <= 5: 
or 
    if value(expression <= 5): 

:

는 바로 위 같은 오류 메시지를 제공합니다 실행.

답변

0

논리적 분리를 사용하여 공식화하는 한 가지 방법. 당신은 사용에 대한 Pyomo.GDP 문서로 볼 수 있지만처럼 보일 것입니다 : 당신이 사용하는 상보성 제약을 수립 할 수

m.helper_var = Var() 
m.obj = Objective(expr=m.helper_var) 
m.lessthan = Disjunct() 
m.lessthan.linker = Constraint(expr=m.helper_var == m.x[0]) 
m.lessthan.constr = Constraint(expr=m.x[1] < const) 
m.greaterthan = Disjunct() 
m.greaterthan.linker = Constraint(expr=m.helper_var == m.x[2]) 
m.greaterthan.constr = Constraint(expr=m.x[1] >= const) 
m.lessthanorgreaterthan = Disjunction(expr=[m.lessthan, m.greaterthan]) 
# some kind of transformation (convex hull or big-M) 

.