[JuMP] Connecting JuMP to custom Solver Simplex

Hello, I’m new in Julia Language and I’m currently coding the Simplex algorithm and I would like to use JuMP to write the optimization models to my solver. My ideia is write the models using JuMP and call my solver or JuMP pass the problem in Simplex’s standard form. I don’t know to do that and I don’t even know if it is possible to that using JuMP. Anyone could help me?

Yes, that’s possible. See Manual · MathOptInterface

I read the MOI’s documentation, but I couldn’t understand how to “translate” the model defined using JuMP to the standard form using MOI’s API. I’ve tried some functions and methods but I didn’t get any success.

image

I already have a model defined using JuMP and I would like to generate the standard form matrix for that.

@Wikunia has a blog post about connecting his solver to JuMP; maybe it will be useful for you: Constraint Solver: How to use JuMP for your own solver?.

2 Likes

Yeah as @ericphanson mentioned I did something like that for my ConstraintSolver. Feel free to reach out if you have questions. For example if you’re in the slack we can chat :wink:

You don’t have to do the translation to the standard LP format, it is do for you automatically by bridges. You just have to specify which constraint type you support with support_constraint. In your case, if it’s the standard LP format, you only support nonnegative variables and linear equality constraint. I would suggest to look at CSDP and SDPA their format is the same with the added support for SDP variables (just ignore it)

1 Like

The easiest thing to do is to copy Clp.jl.

In particular, it has code that extracts data for LPs in the standard form:

min  c'x
s.t. rl <= Ax <= ru
     cl <=  x <= cu

See here, for example:

1 Like

It depends what is meant by standard form here. If the LP standard form is

min c'x
s.t. Ax = b
     x >= 0

Then what you need to do is

function MOI.supports_add_constrained_variables( # don't support free variables (they should all be nonnegatives)
    ::Optimizer, ::Type{MOI.Reals})
    return false
end
function MOI.supports_add_constrained_variables( # support nonnegative variables
    ::Optimizer, ::Type{MOI.Nonnegatives})
    return true
end
function MOI.add_constrained_variables(
    optimizer::Optimizer,
    set::MOI.Nonnegatives)
    # TODO load variables and return variables indices and constraint index
end
function MOI.supports( # support affine objective : c'x + constant
    ::Optimizer,
    ::MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}})
    return true
end
function MOI.set(
    optimizer::Optimizer,
    ::MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}},
    func::MOI.ScalarAffineFunction{Float64})
    # TODO load objective function
end
function MOI.supports_constraint( # support equalities A[i,:]'x = b[i]
    ::Optimizer, ::Type{MOI.ScalarAffineFunction{Float64}},
    ::Type{MOI.EqualTo{Float64}})
    return true
end
function MOI.add_constraint(
    ::Optimizer,
    func::MOI.ScalarAffineFunction{Float64},
    set::MOI.EqualTo{Float64})
    # TODO load constraint and return constraint index
end