Unverified Commit 681cf813 authored by St. Elmo's avatar St. Elmo Committed by GitHub
Browse files

Merge pull request #180 from LCSB-BioCore/mo-opt-check-squash-and-sense-export

Export MAX/MIN, squash optimality check, relocate modifications
parents dcc5a9d7 81dd787e
......@@ -53,7 +53,7 @@ Pages = map(file -> joinpath("analysis", file), readdir("../src/analysis"))
```@autodocs
Modules = [COBREXA]
Pages = map(file -> joinpath("reconstruction", "modifications", file), readdir("../src/reconstruction/modifications"))
Pages = map(file -> joinpath("analysis", "modifications", file), readdir("../src/analysis/modifications"))
```
### Flux sampling
......
......@@ -41,7 +41,7 @@ _inc_all.(
"io",
joinpath("io", "show"),
"reconstruction",
joinpath("reconstruction", "modifications"),
joinpath("analysis", "modifications"),
"analysis",
joinpath("analysis", "sampling"),
joinpath("base", "utils"),
......
......@@ -8,9 +8,7 @@ Arguments are passed to [`flux_balance_analysis`](@ref).
"""
function flux_balance_analysis_vec(args...; kwargs...)::Union{Vector{Float64},Nothing}
optmodel = flux_balance_analysis(args...; kwargs...)
COBREXA.JuMP.termination_status(optmodel) in [MOI.OPTIMAL, MOI.LOCALLY_SOLVED] ||
return nothing
is_solved(optmodel) || return nothing
value.(optmodel[:x])
end
......
......@@ -141,13 +141,13 @@ Internal helper for creating the optimized model on a remote worker, for
avoiding namespace problems.
"""
function _FVA_optimize_reaction(model, rid, ret)
sense = rid > 0 ? MOI.MAX_SENSE : MOI.MIN_SENSE
sense = rid > 0 ? MAX_SENSE : MIN_SENSE
var = all_variables(model)[abs(rid)]
@objective(model, sense, var)
optimize!(model)
if termination_status(model) in [MOI.OPTIMAL, MOI.LOCALLY_SOLVED]
if is_solved(model)
return ret(model)
else
return nothing
......
......@@ -41,8 +41,7 @@ function parsimonious_flux_balance_analysis(
)
# Run FBA
opt_model = flux_balance_analysis(model, optimizer; modifications = modifications)
COBREXA.JuMP.termination_status(opt_model) in [MOI.OPTIMAL, MOI.LOCALLY_SOLVED] ||
return nothing # FBA failed
is_solved(opt_model) || return nothing # FBA failed
# get the objective
Z = objective_value(opt_model)
......@@ -63,15 +62,13 @@ function parsimonious_flux_balance_analysis(
@constraint(opt_model, pfba_constraint, lb <= original_objective <= ub)
optimize!(opt_model)
COBREXA.JuMP.termination_status(opt_model) in [MOI.OPTIMAL, MOI.LOCALLY_SOLVED] &&
break
is_solved(opt_model) && break
COBREXA.JuMP.delete(opt_model, pfba_constraint)
COBREXA.JuMP.unregister(opt_model, :pfba_constraint)
end
COBREXA.JuMP.termination_status(opt_model) in [MOI.OPTIMAL, MOI.LOCALLY_SOLVED] ||
return nothing # pFBA failed
is_solved(opt_model) || return nothing # pFBA failed
return opt_model
end
......
......@@ -52,3 +52,6 @@ const _constants = (
),
colors = (empty = :dark_gray, payload = :default, key = :cyan),
)
const MAX_SENSE = COBREXA.MOI.MAX_SENSE
const MIN_SENSE = COBREXA.MOI.MIN_SENSE
......@@ -42,3 +42,16 @@ function optimize_model(model::MetabolicModel, optimizer; sense = MOI.MIN_SENSE)
COBREXA.JuMP.optimize!(optimization_model)
return optimization_model
end
"""
is_solved(optmodel)
Return `true` if `optmodel` solved successfully (solution is optimal or locally optimal).
Return `false` if any other termination status is reached. Termination status is defined
in the documentation of `JuMP`.
"""
function is_solved(optmodel)
COBREXA.JuMP.termination_status(optmodel) in [MOI.OPTIMAL, MOI.LOCALLY_SOLVED] ? true :
false
end
......@@ -56,7 +56,7 @@ end
modifications = [
change_objective("BIOMASS_Ecoli_core_w_GAM"),
change_constraint("EX_glc__D_e", -12, -12),
change_sense(MOI.MAX_SENSE),
change_sense(MAX_SENSE),
change_optimizer_attribute("IPM_IterationsLimit", 110),
],
)
......
Supports Markdown
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