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

implement reviews

parent e2d3a7f9
Pipeline #50154 failed with stages
in 8 minutes and 32 seconds
......@@ -453,10 +453,8 @@ function change_objective!(
rxn_idxs::Vector{Int};
weights = ones(length(rxn_idxs)),
)
nz_idxs, _ = findnz(objective(model))
model.c[nz_idxs] .= 0.0 # reset
dropzeros!(model.c) # cleanup
model.c[rxn_idxs] .= weights # set
model.c = spzeros(length(model.c))
model.c[rxn_idxs] .= weights
nothing
end
......
......@@ -428,31 +428,21 @@ end
"""
change_objective!(
model::CoreModelCoupled,
rxn_idxs::Vector{Int};
weights = ones(length(rxns)),
args...,
kwargs...,
)
Change the objective for `model` to reaction(s) with indices `rxn_ids`, optionally
specifying their `weights`. By default, assume equal weights. If no objective exists in
model, sets objective.
Forwards arguments to [`change_objective!`](@ref).
"""
function change_objective!(
model::CoreModelCoupled,
rxn_idxs::Vector{Int};
weights = ones(length(rxns)),
)
change_objective!(model.lm, rxn_idxs; weights)
function change_objective!(model::CoreModelCoupled, args...; kwargs...)
change_objective!(model.lm, args...; kwargs...)
end
change_objective!(model::CoreModelCoupled, rxn_xid::Int) =
change_objective!(model.lm, [rxn_xid])
function change_objective!(
model::CoreModelCoupled,
rxn_ids::Vector{String};
weights = ones(length(rxns)),
)
change_objective!(model.lm, rxn_ids; weights)
function change_objective!(model::CoreModelCoupled, args...; kwargs...)
change_objective!(model.lm, args...; kwargs...)
end
change_objective!(model::CoreModelCoupled, rxn_id::String) =
......
......@@ -248,14 +248,12 @@ function change_objective!(
)
all(!haskey(model.reactions, rid) for rid in rxn_ids) &&
throw(DomainError(rxn_ids, "Some reaction ids were not found in model."))
k = 1 # counter
for rid in reactions(model)
if rid in rxn_ids
model.reactions[rid].objective_coefficient = weights[k]
k += 1
else # set others to zero
model.reactions[rid].objective_coefficient = 0.0
end
for rid in reactions(model) # reset to zero
model.reactions[rid].objective_coefficient = 0.0
end
for (k, rid) in enumerate(rxn_ids)
model.reactions[rid].objective_coefficient = weights[k]
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