Building a solver (Getting variable types)



I’m currently reading the documentation of MathProgBase from top to bottom and back again and having a look on some implementations of solvers.

As far as I understood it:
JuMP divides a problem into different categories like LP,Conic and NLP and gives different parameters to MathProgBase based on that. For linear that’s a matrix A a vector b and so on.

For NLP this is kind of an expression of f(x) and g(x) and some other stuff.

Actually I’m not really understanding where the types of each variable are stored.

I get the number of variables and its upper and lower bounds but that’s all. I tried to understand the Pajarito solver but there it seems to be somewhere between loadproblem! and optimize!. I thought there is kind of nothing in between besides from initialize but it doesn’t seem to happen there.

Thanks for any help and maybe you also have some tutorial or documentation or another solver where I might be able to get some information.


You can use the getcategory(x) function to query the type of each variable in your model. They’re all stored as symbols in the model.colCat field.


Sorry can you clarify that a bit? I don’t have access to the x values, right? Or how can I access them inside loadproblem! or something similar. It feels like I’m in a kind of abstract place where the Model is in the outer world and I have just some information about it. That’s why I’m a bit confused.

Thanks for your help.


In Pajarito it seems like they use

MathProgBase.setvartype!(m::PajaritoNonlinearModel, v::Vector{Symbol}) = (m.vartype = v)

Unfortunately that function doesn’t seem to be called in my module :confused:


getcategory(x::JuMP.Variable) returns the type of a JuMP Variable. If you’re trying to build a solver that JuMP could call through MathProgBase, you will need to implement a method for MathProgBase.setvartype! (see yourself.


Is there a documentation about the flow inside MathProgBase ? Like first loadproblem! is called and then this and then optimize! and so on?

I more or less copied the setvartype! function from Pajarito just changed the type of m but it doesn’t get called. Any idea?


Ah I found it. I used relaxation=true and then the function doesn’t get called which makes sense.


JuMP will call setvartype! on the MPB model after loadproblem! if there are any non-continuous variables.

You should be aware that MPB will soon be replaced and unsuported in Julia 0.7 and JuMP 0.19 in favor of MathOptInterface (announcement). We’re getting closer to having basic MOI functionality working on the JuMP side and solver interfaces, but it’s not quite usable yet.