Unverified Commit bae8f421 authored by St. Elmo's avatar St. Elmo Committed by St. Elmo
Browse files

remove extra returns

parent 04493072
...@@ -21,8 +21,7 @@ of the model, if the solution is found. ...@@ -21,8 +21,7 @@ of the model, if the solution is found.
Arguments are passed to [`flux_balance_analysis`](@ref). Arguments are passed to [`flux_balance_analysis`](@ref).
""" """
function flux_balance_analysis_vec(args...)::Union{Vector{Float64},Nothing} function flux_balance_analysis_vec(args...)::Union{Vector{Float64},Nothing}
optmodel = flux_balance_analysis(args...) (optmodel, vars) = flux_balance_analysis(args...)
vars = optmodel[:x]
termination_status(optmodel) in [MOI.OPTIMAL, MOI.LOCALLY_SOLVED] || return nothing termination_status(optmodel) in [MOI.OPTIMAL, MOI.LOCALLY_SOLVED] || return nothing
value.(vars) value.(vars)
...@@ -74,7 +73,7 @@ function fba( ...@@ -74,7 +73,7 @@ function fba(
# get core optimization problem # get core optimization problem
cbm = make_optimization_model(model, optimizer, sense = sense) cbm = make_optimization_model(model, optimizer, sense = sense)
v = cbm[:x] # fluxes v = cbm[:x] # fluxes
# modify core optimization problem according to user specifications # modify core optimization problem according to user specifications
if !isempty(solver_attributes) # set other attributes if !isempty(solver_attributes) # set other attributes
for (k, val) in solver_attributes for (k, val) in solver_attributes
......
...@@ -38,7 +38,7 @@ function flux_variability_analysis( ...@@ -38,7 +38,7 @@ function flux_variability_analysis(
end end
optimization_model = flux_balance_analysis(model, optimizer) optimization_model = flux_balance_analysis(model, optimizer)
Z0 = COBREXA.JuMP.objective_value(optimization_model) Z0 = JuMP.objective_value(optimization_model)
optimization_model = nothing # we won't need this one anymore, so free the memory optimization_model = nothing # we won't need this one anymore, so free the memory
# store a JuMP optimization model at all workers # store a JuMP optimization model at all workers
...@@ -92,7 +92,7 @@ Internal helper function for adding constraints to a model. Exists mainly ...@@ -92,7 +92,7 @@ Internal helper function for adding constraints to a model. Exists mainly
because for avoiding namespace problems on remote workers. because for avoiding namespace problems on remote workers.
""" """
function _FVA_add_constraint(model, c, x, Z0, gamma) function _FVA_add_constraint(model, c, x, Z0, gamma)
COBREXA.JuMP.@constraint(model, c' * x gamma * Z0) JuMP.@constraint(model, c' * x gamma * Z0)
end end
""" """
...@@ -103,11 +103,11 @@ namespace problems. ...@@ -103,11 +103,11 @@ namespace problems.
""" """
function _FVA_optimize_reaction(model, rid) function _FVA_optimize_reaction(model, rid)
sense = rid > 0 ? MOI.MAX_SENSE : MOI.MIN_SENSE sense = rid > 0 ? MOI.MAX_SENSE : MOI.MIN_SENSE
var = COBREXA.JuMP.all_variables(model)[abs(rid)] var = JuMP.all_variables(model)[abs(rid)]
COBREXA.JuMP.@objective(model, sense, var) JuMP.@objective(model, sense, var)
COBREXA.JuMP.optimize!(model) JuMP.optimize!(model)
return COBREXA.JuMP.objective_value(model) return JuMP.objective_value(model)
end end
""" """
......
...@@ -10,7 +10,7 @@ function make_optimization_model( ...@@ -10,7 +10,7 @@ function make_optimization_model(
m, n = size(stoichiometry(model)) m, n = size(stoichiometry(model))
xl, xu = bounds(model) xl, xu = bounds(model)
optimization_model = COBREXA.JuMP.Model(optimizer) optimization_model = JuMP.Model(optimizer)
@variable(optimization_model, x[i = 1:n]) @variable(optimization_model, x[i = 1:n])
@objective(optimization_model, sense, objective(model)' * x) @objective(optimization_model, sense, objective(model)' * x)
@constraint(optimization_model, mb, stoichiometry(model) * x .== balance(model)) # mass balance @constraint(optimization_model, mb, stoichiometry(model) * x .== balance(model)) # mass balance
...@@ -29,6 +29,7 @@ function optimize_model( ...@@ -29,6 +29,7 @@ function optimize_model(
sense = MOI.MIN_SENSE, sense = MOI.MIN_SENSE,
) where {LM<:MetabolicModel} ) where {LM<:MetabolicModel}
optimization_model = make_optimization_model(model, optimizer; sense = sense) optimization_model = make_optimization_model(model, optimizer; sense = sense)
COBREXA.JuMP.optimize!(optimization_model) x = optimization_model[:x]
JuMP.optimize!(optimization_model)
return optimization_model return optimization_model
end end
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