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

more updates

parent b8818d22
......@@ -22,10 +22,9 @@ Arguments are passed to [`flux_balance_analysis`](@ref).
"""
function flux_balance_analysis_vec(args...)::Union{Vector{Float64},Nothing}
optmodel = flux_balance_analysis(args...)
vars = optmodel[:x]
termination_status(optmodel) in [MOI.OPTIMAL, MOI.LOCALLY_SOLVED] || return nothing
value.(vars)
value.(optmodel[:x])
end
"""
......@@ -81,15 +80,21 @@ function flux_balance_analysis(
optimize!(cbm)
status = (
return cbm
end
function flux_balance_analysis_vec()
end
status = (
termination_status(cbm) == MOI.OPTIMAL ||
termination_status(cbm) == MOI.LOCALLY_SOLVED
)
)
if status
return map_fluxes(v, model)
else
if status
return map_fluxes(cbm[:v], model)
else
@warn "Optimization issues occurred."
return Dict{String,Float64}()
end
end
......@@ -134,55 +134,20 @@ fva_max, fva_min = fva(model, biomass, optimizer; solver_attributes=atts)
function fva(
model::CobraModel,
optimizer;
objective_func::Union{Reaction,Array{Reaction,1}} = Reaction[],
optimum_bound = 0.9999,
weights = Float64[],
solver_attributes = Dict{Any,Any}(),
constraints = Dict{String,Tuple{Float64,Float64}}(),
sense = MOI.MAX_SENSE,
modifications = [(model, opt_model) -> nothing]
)
cbm = make_optimization_model(model, optimizer, sense = sense)
# get core optimization problem
cbm = make_optimization_model(model, optimizer)
v = cbm[:x]
if !isempty(solver_attributes) # set other attributes
for (k, v) in solver_attributes
set_optimizer_attribute(cbm, k, v)
# apply callbacks - user can also just put in a function
if typeof(modifications) <: Vector
for mod in modifications
mod(model, cbm)
end
end
# set additional constraints
for (rxnid, con) in constraints
ind = model.reactions[findfirst(model.reactions, rxnid)]
set_bound(ind, cbm; lb = con[1], ub = con[2])
end
# if an objective function is supplied, modify the default objective
if typeof(objective_func) == Reaction || !isempty(objective_func)
# ensure that an array of objective indices are fed in
if typeof(objective_func) == Reaction
objective_indices = [model[objective_func]]
else
objective_indices = [model[rxn] for rxn in objective_func]
end
if isempty(weights)
weights = ones(length(objective_indices))
end
opt_weights = zeros(length(model.reactions))
# update the objective function tracker
# don't update model objective function - silly thing to do
wcounter = 1
for i in eachindex(model.reactions)
if i in objective_indices
# model.reactions[i].objective_coefficient = weights[wcounter]
opt_weights[i] = weights[wcounter]
wcounter += 1
# else
# model.reactions[i].objective_coefficient = 0.0
end
end
@objective(cbm, sense, sum(opt_weights[i] * v[i] for i in objective_indices))
modifications(model, cbm)
end
optimize!(cbm)
......
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