-
-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiobjective support in JuMP #2099
Comments
Another option is to define function MOI.set(model, ::ObjectiveFunction, func::AbstractVectorFunction)
for i in 1:MOI.output_dimension(func)
MOI.set(model, MultiObjectiveFunction(i), func[i])
end
end so that both syntax works for the user |
The more I've thought about this, the more sure I am that 1 is the correct way. You really are declaring a vector valued objective, instead of multiple different objectives. It causes a natural interpretation of the return type of ObjectiveValue and needs no change to MOI. |
Great to see a renewed and improved effort to bring vector-optimzation to JuMP :) |
Thanks @odow for having initiated this discussion, and I am happy to see it. We are developping vOptSolver which is currently composed of two packages, vOptSpecific and vOptGeneric. vOptGeneric is devoted to multi-objective linear optimization problems with discrete variables, see https://github.com/vOptSolver (but we have also some beta versions of algorithms for problems with mixed integer variables and continuous variables). The version online is compliant with julia 1.x and JuMP 0.18. You can give a look on the notebook (here : https://github.com/vOptSolver/vOptSolver-notebook) that I have prepared as support for a seminar held in November 2018. The version of vOptGeneric compliant with JuMP 0.19 is ready on a branch (https://github.com/vOptSolver/vOptGeneric.jl/branches). It is a matter of free time for me for updating all the documents (for some reasons I have been much less available since the last summer). Here an example with vOptGeneric+JuMP0.19 for the bi-objective knapsack problem: using vOptGeneric, JuMP, Cbc, LinearAlgebra
m = vModel(with_optimizer(Cbc.Optimizer, logLevel=0))
p1 = [77,94,71,63,96,82,85,75,72,91,99,63,84,87,79,94,90,60,69,62]
p2 = [65,90,90,77,95,84,70,94,66,92,74,97,60,60,65,97,93,60,69,74]
w = [80,87,68,72,66,77,99,85,70,93,98,72,100,89,67,86,91,79,71,99]
c = 900
size = length(p1)
@variable(m, x[1:size], Bin)
@addobjective(m, Max, dot(x, p1))
@addobjective(m, Max, dot(x, p2))
@constraint(m, dot(x, w) <= c)
vSolve(m, method=:dichotomy)
Y_N = getY_N(m)
for n = 1:length(Y_N)
X = value.(x, n)
print(findall(elt -> elt ≈ 1, X))
println("| z = ",Y_N[n])
end As you can see:
Thus:
|
vOpt would can either create
You can freely define any interface, JuMP will not restrict you. You just need to define new MOI attributes, so that the user can do |
Is it okay to just redefine the objective? (E.g., below.) Or are you keeping the pre-computed frontier and projecting it onto the lower-dimensional space when you remove an objective? @objective(model, Min, C * x)
# Then later
@objective(model, Min, C[1, :] * x) If model = Model()
@variable(model, x[1:2])
@objective(model, Min, C * x)
Y_N = MOI.get(model, vOpt.EfficientFacets()) Gurobi.jl uses this to query the IIS, for example. There is one very big change for vOptSolver: you should re-write it as a MOI solver, rather than a JuMP-extension. That means you don't have to worry about macros like |
From the user/modeler perspective it seems that option 2 is better. Mode one is sort of not natural mainly if the two objectives are completely different. |
So my reasoning is this:
So, at the MOI level, we don't need to change anything to support M.O. One exception is if solvers want to return more complicated solution artifacts (e.g., facets). If so, they should define solver-specific MOI attributes. So, given we don't need to change MOI, what is the closest mapping to JuMP? Vector-valued objectives. If you want to give the objectives separately, you can go: @expression(model, first_objective, ...)
@expression(model, second_objective, ...)
@objective(model, Min, [first_objective; second_objective]) The other approach, JuMP giving objectives separately, would require changes to MOI to parameterize the objective function based on the index. This raises some questions.
|
expressions are reasonable for a quick fix, although doing separately seems a good future goal. |
The inconvenience I see to the |
To which I counter: there is already precedent for vector-valued functions in constraints; most solvers would throw "VectorAffineFunction in objective not supported"; and even if they did solve it, People could get equally confused with @objective(model, Min, x)
@objective(model, Min, y) And how would we handle multiple objective senses? Here is @xgandibleux's example with what I am proposing: using vOptGeneric, JuMP, Cbc, LinearAlgebra
p1 = [77,94,71,63,96,82,85,75,72,91,99,63,84,87,79,94,90,60,69,62]
p2 = [65,90,90,77,95,84,70,94,66,92,74,97,60,60,65,97,93,60,69,74]
w = [80,87,68,72,66,77,99,85,70,93,98,72,100,89,67,86,91,79,71,99]
c = 900
size = length(p1)
model = Model(with_optimizer(
vOptGeneric.Optimizer(
Cbc.Optimizer(logLevel=0), method=:dichotomy
)
))
@variable(model, x[1:size], Bin)
@objective(model, Max, [dot(x, p1), dot(x, p2)])
@constraint(m, dot(x, w) <= c)
optimize!(model)
for n = 1:result_count(model)
X = value.(x; result = n)
print(findall(elt -> elt ≈ 1, X))
println("| z = ", objective_value(model; result = n))
end |
In writing @objective(model, Max, [dot(x, p1), dot(x, p2)]) the user cannot • Concerning (1): of course, it is trivial to rewrite the function from min to max, but having the choice here is natural (same level of why not express the constraints only in <=). • Concerning (2): MO-models are also solved within an interactive approach, where the user can adopt a "what-if" behavior with the objectives. This is a feedback that I have received from users of vOptGeneric. I am working with my students on a case study (a car sequencing problem) with 2 or 3 objective functions. The (technical) constraints are static but the objectives may change between production plants. This is an other illustration where preferences of a decision-maker may suggest to delete an objective or replace an objective by an other (with the idea of comparing different optimization policy) in a (large) MIP model. Is it technically possible to imagine of naming the objectives as the constraints: @objective(model, obj1, Max, [dot(x, p1)])
@objective(model, obj2, Min, [dot(x, p2)]) or @objective(model, cost[1], Min, [dot(x, p1)])
@objective(model, stability[2], Max, [dot(x, p2)]) or @objective(model, [1], Min, [dot(x, p1)])
@objective(model, [2], Max, [dot(x, p2)]) or @objective(model, obj[i = 1:3], [ dot(x, p[i]) ]) and then to refer to one objective by name (e.g. stability) or by its index (e.g. 2)? |
This is a reasonable point to make. The question of "objective sense" isn't obvious. The hang-up we seem to be having is the standard form. Is it:
where
where I'm going to argue strongly that it's the first, since it is the simplest concept. More importantly, it's the design of MathOptInterface as it stands today. We wouldn't need to add any special features for multi objective problems. This is pretty important for actually implementing this, because I don't think we want to re-think the entire concept of objectives this close to the release of JuMP 1.0. So at the expense of (i) providing a list of expressions not being the nicest syntax and (ii) not being able to specify different objective senses, perhaps we can table this idea until JuMP 2.0?
They can just reset the objective: model = Model()
@variable(model, x[1:2])
@objective(model, Min, [x[1], x[2]])
optimize!(model)
@objective(model, Min, x[1] + x[2])
optimize!(model)
This would be possible using model = Model()
@variable(model, x[1:2])
@expression(model, obj[i=1:2], x[i])
@objective(model, Min, obj)
optimize!(model)
value(obj[1], result=1) Relating to the changing objectives point: model = Model()
@variable(model, x[1:3])
@expression(model, stability, x[1])
@expression(model, cost, x[2])
@expression(model, production, x[3])
@objective(model, Max, [stability, production, -cost])
optimize!(model)
@show value(stability; result=2)
@show value(cost; result=2)
@objective(model, Max, [stability, production])
optimize!(model)
# Note: we didn't have cost as an objective, but we can still query the value!
@show value(cost; result=2) |
Okay, so I started to implement this, and I found that one thing would have to change in MOI. Essentially, we just need to relax the """
ObjectiveFunction{F<:AbstractScalarFunction}()
A model attribute for the objective function which has a type `F<:AbstractScalarFunction`.
`F` should be guaranteed to be equivalent but not necessarily identical to the function type provided by the user.
Throws an `InexactError` if the objective function cannot be converted to `F`,
e.g. the objective function is quadratic and `F` is `ScalarAffineFunction{Float64}` or
it has non-integer coefficient and `F` is `ScalarAffineFunction{Int}`.
"""
struct ObjectiveFunction{F<:AbstractScalarFunction} <: AbstractModelAttribute end |
So I talked to @mlubin, and we won't be pushing this into JuMP unless there is general agreement on the approach. We definitely don't want to force @xgandibleux et al. to implement However, since I require this for my personal work, I will move forward with an implementation. Once it's ready for review, we can have another discussion about the pro's and con's of each approach, this time with some actual working code. But, to re-iterate, we won't merge it unless there is general agreement. |
Okay, I now have a proof of concept multi-objective solver: https://github.com/odow/MOO.jl The best place to look is the test, where we solve a trivial 2 variable BOLP: Arguments for
If we want to move forward with this, now that JuMP has support for accessing multiple solutions (#2100), the only missing piece is JuMP passing vector-valued functions to solvers as the objective function. |
I recently had a conversation with Kaisa Miettinen who leads the multiobjective optimization group at University of Jyväskylä. (She made me aware of @xgandibleux 's work using Julia)
I see that 1&4 can be accomplished with the current frame work. If consider those features non-essential but think they are low hanging fruits on the way of JuMP becoming a best in class multi objective framework. Although my knowledge on multi objective optimization is second hand only and i am open to be corrected. |
I would like to add my two cents to the discussion, mainly concerning way objectives are declared. Background: I have recently worked on a trust region solver for nonlinear multiobjective problems. Despite this fact, the need for separate evaluation of the different objectives might arise in other approaches as well. Hope this helps in evaluating how to proceed :) |
@/all: Thanks for the input. If anyone watching this thread (or your students) is interested in progressing this further, I've proposed this as a Google Summer of Code (GSOC) for this (Northern) summer: You can find more about GSOC here: If we get selected, student applications run March 30 - April 14. |
Hi @odow , how is the progress about MOO? or recommend to use https://github.com/anriseth/MultiJuMP.jl? |
No progress. MultiJuMP hasn't been updated to JuMP 1.0. Digging in to understand how it works and updating it to JuMP 1.0 would be a good project, if you have the time. |
vOptGeneric solves generic linear problems with 2 objectives with e.g. an epsilon constraint method (+ MIP solver available from JuMP). It is compliant with the last versions of julia and JuMP. A quick starter is presented in recent slides here. Several examples are provided here. |
This is a re-hash of #968 The last PR lost steam because of the discussion in jump-dev/JuMP.jl#2099 My sense is that this is still the right API approach at the MOI-level, but that it's the wrong approach at the JuMP level. I'm working on a PR to JuMP, so let's hold off comments until things are working fully and we can discuss the full API, rather than the pros and cons of treating multi-criteria as vector optimization. I have a proof-of-concept solver at https://github.com/odow/MOO.jl and I'll also update Gurobi.jl to support the new API.
To be read in conjunction with jump-dev/MathOptInterface.jl#2070 A proof-of-concept solver and JuMP examples are available at jump-dev/MultiObjectiveAlgorithms.jl#2 The issue #2099 discussed two approaches for implementing MO in JuMP. 1. Treat multicriteria as a vector of scalar objectives and a vector of scalar senses. This would let someone write [Min, Max], [f(x), g(x)]. The main reason for this approach is that it matches what users want to do. 2. Treat multicriteria as an optimization problem with a vector-valued objective function. Users could write only Min, f(x) where f(x) is a vector. The main reason for this approach is that it matches what MathOptInterface wants. This PR implements option 2. The strongest reason in support of option 2 is that it requires very little code to implement, suggesting that it is a natural extension of MOI. The biggest downside is that it doesn't overcome the Min-Max issue; but I think we can work around this with user-facing cosmetic tooling in JuMP; solvers would be forced to accept a single sense.
I'm back at this in #3176. Here's a related project that we should look to for ideas: https://pymoo.org. It's a bit limited though. It supports only |
Single objective sense
Mixed objective sense
|
If I may comment on Gurobi's capability: You can specify both weights and priorities for the objectives. The objectives will then be grouped by the priority, and each group will be "blended" with a weighted sum. In addition, the user can specify tolerances (both rel. and abs.?) to allow for some relaxation when going one level deeper into the hierarchy. This feature in particular is quite useful in practice, we found, as you'd otherwise quickly end up in extreme corners. |
Yeah. I haven't tested, but this should work: set_optimizer_attribute.(
model,
Gurobi.MultiObjectivePriority.(1:3),
[2, 1, 1],
)
set_optimizer_attribute.(
model,
Gurobi.MultiObjectiveWeight.(1:3),
[1.0, 0.25, 0.75],
) I think these are attributes of the optimizer though. They're unrelated to how we model the objectives at the JuMP level. |
Fair enough, I'm not sure about the scope of this issue. If this is just about defining attributes that some of the solvers may support, there's not much more to say about it. But the algorithm for hierarchical objectives is easy enough to implement on top of any (LP/MIP) solver, so it could make sense to implement some kind of wrapper for it. |
Yeah. That's my plan for: https://github.com/odow/MOO.jl Currently it just has a single algorithm, but the idea is to collate a few simple ones. |
Before the integration of MOP features into CPLEX and Gurobi, we have integrated in vOptGeneric two methods aiming to solve weighted sum and the lexicographic LP/MIP with any solver interfaced to JuMP. The methods to invoke are :dicho or :dichotomy These last months, we have extended HiGHS to 2LP (expected by several colleagues for research needs) and developped the epsilon-contraint method for 3 objectives based on the Kirlik-and-Sayin algorithm (vOptGeneric is mainly used today for solving bi-objective problems with the epslion-contraint method with declared with JuMP). Both should be integrated to vOptGeneric shorthly (it is a matter of freetime for us). BTW, FICO has also announced recently the integration of MOP features into XPRESS. |
Nice 😄 Is there a link to the code? Does it support independent objective senses? |
The code is already on github. We are now testing it. It will be available in the coming weeks (as soon as the tests will be completed, and cleaned from french comments). HiGHS2LP implements the 3rd phase of the simplex algorithm. From the optimal solution obtained with the simplex algorithm, it iterates for generating all the non-dominated points. HiGHS2LP is used exactly as HiGHS (see hereafter); the only difference comes the second objective that the user has to specify. Both objectives are given in maximization or in minimization. The solver computes a minimum complete set of efficient solutions The 2LP problem to solve:
The description for HiGHS2LP:
The output:
In the output we get:
To do:
|
Okay. I think this settles it for me. Having a vector-valued objective function with a single objective sense is the way to go, since that's what all solvers supporting multiple objectives will support. If, in future, we find that users keep asking for So the PR for people to review if interested is jump-dev/MathOptInterface.jl#2070
This should be easy, we can copy HiGHS.jl, but it will need jump-dev/MathOptInterface.jl#2070 first. |
This is a re-hash of #968 The last PR lost steam because of the discussion in jump-dev/JuMP.jl#2099 My sense is that this is still the right API approach at the MOI-level, but that it's the wrong approach at the JuMP level. I'm working on a PR to JuMP, so let's hold off comments until things are working fully and we can discuss the full API, rather than the pros and cons of treating multi-criteria as vector optimization. I have a proof-of-concept solver at https://github.com/odow/MOO.jl and I'll also update Gurobi.jl to support the new API.
To be read in conjunction with jump-dev/MathOptInterface.jl#2070 A proof-of-concept solver and JuMP examples are available at jump-dev/MultiObjectiveAlgorithms.jl#2 The issue #2099 discussed two approaches for implementing MO in JuMP. 1. Treat multicriteria as a vector of scalar objectives and a vector of scalar senses. This would let someone write [Min, Max], [f(x), g(x)]. The main reason for this approach is that it matches what users want to do. 2. Treat multicriteria as an optimization problem with a vector-valued objective function. Users could write only Min, f(x) where f(x) is a vector. The main reason for this approach is that it matches what MathOptInterface wants. This PR implements option 2. The strongest reason in support of option 2 is that it requires very little code to implement, suggesting that it is a natural extension of MOI. The biggest downside is that it doesn't overcome the Min-Max issue; but I think we can work around this with user-facing cosmetic tooling in JuMP; solvers would be forced to accept a single sense.
This is a re-hash of #968 The last PR lost steam because of the discussion in jump-dev/JuMP.jl#2099 My sense is that this is still the right API approach at the MOI-level, but that it's the wrong approach at the JuMP level. I'm working on a PR to JuMP, so let's hold off comments until things are working fully and we can discuss the full API, rather than the pros and cons of treating multi-criteria as vector optimization. I have a proof-of-concept solver at https://github.com/odow/MOO.jl and I'll also update Gurobi.jl to support the new API.
@xgandibleux here's the documentation for the PR: https://jump.dev/JuMP.jl/previews/PR3176/manual/objective/#Set-a-vector-valued-objective Take a read. Any comments on the syntax? Are you happy to model problems with a vector-valued objective? |
@odow, I installed and tested this code on my computer, it is great! Shall we moving to
(2) the retrieval of outputs at least for 2 and 3 objective cases:
Perhaps starting with a 2D e-constraint method (which call a MILP solver among the 3 listed) for solving an IP will help to design the coming steps. The code corresponding to this method is available in vOptGeneric, which can be a starting point. An other tentative could be to revisit gurobi.jl in order to deliver a 2-IP and to return |
I've already implemented support in Here's what it looks like with these branches:
julia> using JuMP
julia> import Gurobi, HiGHS, MOO
julia> begin
p1 = [77, 94, 71, 63, 96, 82, 85, 75, 72, 91, 99, 63, 84, 87, 79, 94, 90]
p2 = [65, 90, 90, 77, 95, 84, 70, 94, 66, 92, 74, 97, 60, 60, 65, 97, 93]
w = [80, 87, 68, 72, 66, 77, 99, 85, 70, 93, 98, 72, 100, 89, 67, 86, 91]
model = Model()
set_silent(model)
@variable(model, x[1:length(w)], Bin)
@objective(model, Max, [p1' * x, p2' * x])
@constraint(model, w' * x <= 900)
model
end
A JuMP Model
Maximization problem with:
Variables: 17
Objective function type: Vector{AffExpr}
`AffExpr`-in-`MathOptInterface.LessThan{Float64}`: 1 constraint
`VariableRef`-in-`MathOptInterface.ZeroOne`: 17 constraints
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.
Names registered in the model: x
julia> set_optimizer(model, Gurobi.Optimizer)
julia> optimize!(model)
julia> for i in 1:result_count(model)
Y = objective_value(model; result = i)
println("Result $i : Objective value = $Y")
X = findall(xi -> xi > 0.9, value.(x; result = i))
println(" Items = $X")
end
Result 1 : Objective value = [934.0, 971.0]
Items = [2, 3, 5, 6, 8, 10, 11, 12, 15, 16, 17]
Result 2 : Objective value = [905.0, 897.0]
Items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
julia> set_optimizer(model, () -> MOO.Optimizer(HiGHS.Optimizer))
julia> set_optimizer_attribute(model, MOO.Algorithm(), MOO.NISE())
julia> optimize!(model)
julia> for i in 1:result_count(model)
Y = objective_value(model; result = i)
println("Result $i : Objective value = $Y")
X = findall(xi -> xi > 0.9, value.(x; result = i))
println(" Items = $X")
end
Result 1 : Objective value = [955.0, 906.0]
Items = [2, 3, 5, 6, 9, 10, 11, 14, 15, 16, 17]
Result 2 : Objective value = [948.0, 939.0]
Items = [1, 2, 3, 5, 6, 8, 10, 11, 15, 16, 17]
Result 3 : Objective value = [934.0, 971.0]
Items = [2, 3, 5, 6, 8, 10, 11, 12, 15, 16, 17]
Result 4 : Objective value = [918.0, 983.0]
Items = [2, 3, 4, 5, 6, 8, 10, 11, 12, 16, 17]
julia> set_optimizer_attribute(model, MOO.Algorithm(), MOO.Hierarchical())
julia> optimize!(model)
julia> for i in 1:result_count(model)
Y = objective_value(model; result = i)
println("Result $i : Objective value = $Y")
X = findall(xi -> xi > 0.9, value.(x; result = i))
println(" Items = $X")
end
Result 1 : Objective value = [955.0, 906.0]
Items = [2, 3, 5, 6, 9, 10, 11, 14, 15, 16, 17] Note that Gurobi returns multiple results, but the second is not on the frontier, it is just an integer feasible point. |
To be read in conjunction with jump-dev/MathOptInterface.jl#2070 A proof-of-concept solver and JuMP examples are available at jump-dev/MultiObjectiveAlgorithms.jl#2 The issue #2099 discussed two approaches for implementing MO in JuMP. 1. Treat multicriteria as a vector of scalar objectives and a vector of scalar senses. This would let someone write [Min, Max], [f(x), g(x)]. The main reason for this approach is that it matches what users want to do. 2. Treat multicriteria as an optimization problem with a vector-valued objective function. Users could write only Min, f(x) where f(x) is a vector. The main reason for this approach is that it matches what MathOptInterface wants. This PR implements option 2. The strongest reason in support of option 2 is that it requires very little code to implement, suggesting that it is a natural extension of MOI. The biggest downside is that it doesn't overcome the Min-Max issue; but I think we can work around this with user-facing cosmetic tooling in JuMP; solvers would be forced to accept a single sense.
Merged! Thanks for all of the input over the last few years. |
This issue is for a discussion on introducing multiobjective support to JuMP (and
MOI).
Passing multiple objectives to the solver
There are two possibilities:
@objective
to support vector-valued functions, so the user wouldwrite:
index
keyword, so the user would write:Option (1) is probably the easiest, since it fits quite well into the MOI
framework, and JuMP already has support for parsing vector-valued functions.
M.O. solvers would just declare:
The biggest downside with (1) is that it would only support linear and quadratic
objectives. We wouldn't be able to directly support nonlinear objectives. (You
could, of course, introduce a dummy variable with a nonlinear equality
constraint.)
Querying results from the solver
I think the easiest way for M.O. solvers to return the Pareto frontier is for
them to sligthly abuse the notion of
ResultCount
.We should implement
And then add keyword arguments to
value
,objective_value
, so we have:The only issue with
objective_value
(andobjective_bound
anddual_objective_bound
) is that they expect aFloat64
return type. This wouldbe relaxed to depend on the type of the objective function.
Example
If
MultiJuMP
implemented aMOI.Optimizer
solver, we could write:cc @anriseth, @matbesancon
The text was updated successfully, but these errors were encountered: