I would like to use the same script to evaluate my model results obtained by an MCP reformulation and a constraint optimization. Unfortunately, I would need to swap between JuMP.value and Complementarity.result_value.
I did the following to overcome this:
import JuMP
import Complementarity
value(x::JuMP.VariableRef) = haskey(owner_model(x).ext,:MCP) ? Complementarity.result_value(x) : JuMP.value(x)
value(x::Number) = x
value(x::JuMP.NonlinearExpression) = JuMP.value(x::JuMP.NonlinearExpression, value) # use function `value` to evaluate JuMP.VariableRef in expressions
value(x) = JuMP.value(x) # Fall back on default for rest
using JuMP
using Complementarity
m = MCPModel()
@variable(m, x >= 0)
a = @NLexpression(m, x+2)
@mapping(m, F, a)
@complementarity(m, F, x)
status = solveMCP(m)
@show value(a)
@show value(x)
using Clp
m2 = Model()
@variable(m2, y>=0)
b = @expression(m2, y+1)
@constraint(m2, b <= 2)
@objective(m2, Max, y)
optimize!(m2, with_optimizer(Clp.Optimizer))
@show value(y)
@show value(b)
Hallo,
I would like to use the same script to evaluate my model results obtained by an MCP reformulation and a constraint optimization. Unfortunately, I would need to swap between
JuMP.value
andComplementarity.result_value
.I did the following to overcome this:
Maybe it can be integrated somehow.
Greetings, Hanspeter