Julia JuMP optimization help

With complements in Julia/JuMP/PATH/KNITRO. How do you get to use non-linear functions. See in the code below.


using PATH, JuMP, KNITRO

function geological_constraints_MCP()

    Α = 50.0
    Β = 0.1
    δ = 0.05
    γ = 0.1
    ψ₁ = 0.0
    ψ₂ = 2.0
    λ₁ = 5.0
    λ₂ = 4.0
    R₀ = 0.0
    S₀ = 10.0
    T = 40

    gxt = Model(PATH.Optimizer)

    @variable(gxt, q[1:4]>=0)

    # working linear function
    #@constraint(gxt, -(Α .- Β*q - ψ₁.*q) ⟂ q)

    # I would like one of the two below to work    
    @NLconstraint(gxt, -(Α .- Β*q - ψ₁.*q.^(ψ₂-1)) ⟂ q)
    #@NLconstraint(gxt, -(Α .- Β*q - (ψ₁.*q).*q) ⟂ q)

    print(gxt)
    optimize!(gxt)
    value.(q)
end


geological_constraints_MCP()


JuMP’s NLP support is limited to <=, >=, and == constraints. It’s a sore point that needs fixing, but that is for the future.

For now, you can only use linear complementary constraints with PATH. Not sure about KNITRO, but I think the same applies. Although you could add a slack variable and use that instead.

2 Likes

Thanks once again @odow. This is very helpful.

To partly answer my own question. See this discussion.

Using “complementarity.jl” works with nonlinear expressions. Here is the working piece of code:

using PATH, JuMP, Complementarity

function geological_constraints_MCP()

    Α = 50.0
    Β = 0.1
    δ = 0.05
    γ = 0.1
    ψ₁ = 0.0
    ψ₂ = 2.0
    λ₁ = 5.0
    λ₂ = 4.0
    R₀ = 0.0
    S₀ = 10.0
    T = 4
    t = 1:T

    gxt =MCPModel()
    @variable(gxt, q[i in t]>=0)
    @mapping(gxt, FOC[i in t], -(Α - Β*q[i] - ψ₁*q[i]^(ψ₂-1)))
    @complementarity(gxt,FOC,q)

    print(gxt)
    status = solveMCP(gxt)
    #value.(q)
    @show result_value.(q)
end


geological_constraints_MCP()