Commit cddaea86 authored by Miroslav Kratochvil's avatar Miroslav Kratochvil
Browse files

unify the style of the modifications

parent 3b319c0b
......@@ -5,26 +5,24 @@
Limit the objective value to `tolerance`-times the current objective value, as
with [`objective_bounds`](@ref).
"""
function constrain_objective_value(tolerance)
return (_, opt_model) -> begin
constrain_objective_value(tolerance) =
(_, opt_model) -> begin
lambda_min, lambda_max = objective_bounds(tolerance)(objective_value(opt_model))
old_objective = objective_function(opt_model)
@constraint(opt_model, lambda_min <= sum(old_objective) <= lambda_max)
end
end
"""
change_constraint(id::String, lb, ub)
Change the lower and upper bounds (`lb` and `ub` respectively) of reaction `id`.
"""
function change_constraint(id::String, lb, ub)
change_constraint(id::String, lb, ub) =
(model, opt_model) -> begin
ind = first(indexin([id], reactions(model)))
isnothing(ind) && throw(DomainError(id, "No matching reaction was found."))
set_optmodel_bound!(ind, opt_model, lb = lb, ub = ub)
end
end
"""
change_objective(new_objective::Union{String,Vector{String}}; weights=[], sense=MOI.MAX_SENSE)
......@@ -36,11 +34,11 @@ array of reactions identifiers.
Optionally, the objective can be weighted by a vector of `weights`, and a
optimization `sense` can be set.
"""
function change_objective(
change_objective(
new_objective::Union{String,Vector{String}};
weights = [],
sense = MOI.MAX_SENSE,
)
) =
(model, opt_model) -> begin
# Construct objective_indices array
......@@ -67,4 +65,3 @@ function change_objective(
v = opt_model[:x]
@objective(opt_model, sense, sum(opt_weights[i] * v[i] for i in objective_indices))
end
end
......@@ -8,9 +8,8 @@ Possible arguments are `MOI.MAX_SENSE` and `MOI.MIN_SENSE`.
If you want to change the objective and sense at the same time, use
[`change_objective`](@ref) instead to do both at once.
"""
function change_sense(objective_sense)
change_sense(objective_sense) =
(_, opt_model) -> set_objective_sense(opt_model, objective_sense)
end
"""
change_optimizer(optimizer)
......@@ -21,9 +20,8 @@ This may be used to try different approaches for reaching the optimum, and in
problems that may require different optimizers for different parts, such as the
[`parsimonious_flux_balance_analysis`](@ref).
"""
function change_optimizer(optimizer)
change_optimizer(optimizer) =
(_, opt_model) -> set_optimizer(opt_model, optimizer)
end
"""
change_optimizer_attribute(attribute_key, value)
......@@ -32,7 +30,5 @@ Change a JuMP optimizer attribute. The attributes are optimizer-specific, refer
to the JuMP documentation and the documentation of the specific optimizer for
usable keys and values.
"""
function change_optimizer_attribute(attribute_key, value)
(_, opt_model) ->
set_optimizer_attribute(opt_model, attribute_key, value)
end
change_optimizer_attribute(attribute_key, value) =
(_, opt_model) -> set_optimizer_attribute(opt_model, attribute_key, value)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment