IainNZ / JuMPeR.jl

Julia for Mathematical Programming - extension for Robust Optimization
http://iainnz.github.io/JuMPeR.jl
Other
51 stars 23 forks source link

solveRobust( ... ) vs solve(...) with multiple dispatch? #13

Closed vgupta1 closed 10 years ago

vgupta1 commented 10 years ago

Minor issue: it'd be nice to call solve() and print() instead of solveRobust() and printRobust() using multiple dispatch if possible. Is there a reason we can't do it this way?

IainNZ commented 10 years ago

Can't be done (yet) Robust models are JuMP models with an "extension".

function RobustModel(;solver=nothing,cutsolver=nothing)
    m = Model(solver=solver)
    m.ext[:Robust] = RobustData(cutsolver)
    return m
end

Alternatives that would let you do multiple dispatch including using an AbstractModel from which Model and a hypothetical RobustModel inherit from is one option, another was making Model parametric. Both had issues... This is something @mlubin and I talked about a lot, and this "extension" mechanism was the best we could do without compromising any JuMP speed. Somewhat related to https://github.com/JuliaLang/julia/issues/4935

vgupta1 commented 10 years ago

I noticed that... Do you know if the language extension is coming soon? (i.e. requiring abstract types to have certain members?)

Alternatively, although it seems a bit dodgy, (for my own edifiaton) couldn't you have done this?

type RobustModel <: Model
    m  #This is actually a model
     rd #this is the robust data and extension stuff
end

In other words, Robust models implement BOTH "is a" and "has a" in the inheritance scheme?


Vishal Gupta PhD Candidate, 2014 Operations Research Center Massachusetts Institute of Technology www.mit.edu/~vgupta1/

On Thu, Apr 10, 2014 at 9:50 PM, Iain Dunning notifications@github.comwrote:

Can't be done (yet) Robust models are JuMP models with an "extension".

function RobustModel(;solver=nothing,cutsolver=nothing) m = Model(solver=solver) m.ext[:Robust] = RobustData(cutsolver) return m end

Alternatives that would let you do multiple dispatch including using an AbstractModel from which Model and a hypothetical RobustModel inherit from is one option, another was making Model parametric. Both had issues... This is something @mlubin https://github.com/mlubin and I talked about a lot, and this "extension" mechanism was the best we could do without compromising any JuMP speed. Somewhat related to JuliaLang/julia#4935https://github.com/JuliaLang/julia/issues/4935

Reply to this email directly or view it on GitHubhttps://github.com/IainNZ/JuMPeR.jl/issues/13#issuecomment-40163671 .

mlubin commented 10 years ago

The issue is that variables contain a reference to their parent model, which needs to be a Model. We tried making variables parametric on the model type, but that led to Julia's version of C++ template hell. Having different model types also makes extensions mutually exclusive.

mlubin commented 10 years ago

Also you can't inherit from concrete types in Julia. Model would need to be an abstract type.