Commit 57be2637 authored by Miroslav Kratochvil's avatar Miroslav Kratochvil
Browse files

implement objective envelopes (aka production envelopes)

parent 51f6f8f3
envelope_lattice(m::MetabolicModel, rids::Vector{String}; kwargs...) =
envelope_lattice(m, Vector{Int}(indexin(rids, reactions(m))); kwargs...)
envelope_lattice(
m::MetabolicModel,
ridxs::Vector{Int};
samples = 10,
ranges = collect(zip(bounds(m)...))[ridxs],
reaction_samples = fill(samples, length(ridxs))) =
(
lb .+ (ub - lb) .* ((1:s) .- 1) ./ max(s - 1, 1) for
(s, (lb, ub)) in zip(reaction_samples, ranges)
)
objective_envelope(m::MetabolicModel, rids::Vector{String}, args...; kwargs...) =
objective_envelope(m, Vector{Int}(indexin(rids, reactions(m))), args...; kwargs...)
objective_envelope(
m::MetabolicModel,
ridxs::Vector{Int},
optimizer;
lattice = envelope_lattice(m, ridxs),
kwargs...,
) = (
lattice = collect.(lattice),
values = screen_optmodel_modifications(
m,
optimizer,
modifications = collect(
[(_, optmodel) -> begin
for (i, ridx) in enumerate(ridxs)
set_normalized_rhs(optmodel[:lbs][ridx], bounds[i])
set_normalized_rhs(optmodel[:ubs][ridx], bounds[i])
end
end] for bounds in Iterators.product(lattice...)
),
analysis = screen_optimize_objective,
),
)
......@@ -143,3 +143,47 @@ A shortcut for [`screen`](@ref) that only works with model variants.
"""
screen_variants(model, variants, analysis; workers = [myid()]) =
screen(model; variants = variants, analysis = analysis, workers = workers)
screen_optimize_objective(_, optmodel)::Union{Float64,Nothing} =
optimize_objective(optmodel)
function screen_optmodel_modifications(
model,
optimizer;
modifications::Array{V,N},
analysis = screen_optimize_objective,
workers = [myid()],
) where {V<:AbstractVector,N}
save_model = :(
begin
local model = $model
$COBREXA.precache!(model)
(model, $COBREXA.make_optimization_model(model, $optimizer))
end
)
map(
fetch,
save_at.(workers, :cobrexa_screen_optmodel_modifications_data, Ref(save_model)),
)
save_model = nothing
map(fetch, save_at.(workers, :cobrexa_screen_optmodel_modifications_fn, Ref(analysis)))
res = dpmap(
mods -> :(
begin
local (model, optmodel) = cobrexa_screen_optmodel_modifications_data
for mod in $mods
mod(model, optmodel)
end
cobrexa_screen_optmodel_modifications_fn(model, optmodel)
end
),
CachingPool(workers),
modifications,
)
map(fetch, remove_from.(workers, :cobrexa_screen_optmodel_modifications_data))
map(fetch, remove_from.(workers, :cobrexa_screen_optmodel_modifications_fn))
return res
end
......@@ -59,6 +59,15 @@ function is_solved(optmodel)
false
end
function optimize_objective(optmodel)::Union{Float64,Nothing}
optimize!(optmodel)
if is_solved(optmodel)
objective_value(optmodel)
else
nothing
end
end
"""
get_optmodel_bounds(opt_model)
......
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