chkwon / Complementarity.jl

provides a modeling interface for mixed complementarity problems (MCP) and math programs with equilibrium problems (MPEC) via JuMP
Other
75 stars 20 forks source link

Printing of MCPModel #38

Closed hhoeschle closed 3 years ago

hhoeschle commented 5 years ago

Hi all,

I discovered that the printing of a MCPModel did not provide the complementarity constraints. Here is a first test to fix that:

function printMCP(m)
    mcp_data  = Complementarity.get_MCP_data(m)
    res = "$(m)Complementarity constraints\n"

    # replace all subexpression
    dict_s = Dict{Int,String}(
        i => nl_expr_string(m, REPLMode , expr)
        for (i,expr) in enumerate(m.nlp_data.nlexpr)
    )

    sub_reg = r"subexpression\[(?<id>[0-9]+)\]"
    for (i,expr) in dict_s
        m = match(sub_reg, expr)
        try
            dict_s[i] = replace(expr, m.match => dict_s[parse(Int, m[:id])])
        catch
        end
    end
    for c in mcp_data
        expr_id = parse(Int,split("$(c.F)", "#")[end][1:end-1])
        res = res * " $(c.lb) ≦ $(c.var) \n   ⟂ $(dict_s[expr_id]) ≧ 0.0\n"
    end
    return res
end

For the example on the start page, this is the outcome of println(printMCP(m)):

Feasibility
Subject to
 x >= 0.0
Complementarity constraints
 0.0 ≦ x
   ⟂ x + 2.0 ≧ 0.0
chkwon commented 3 years ago

Closing for the new version of PATHSolver.jl https://github.com/chkwon/PATHSolver.jl/pull/44