Skip to content

Commit

Permalink
simplify the ratio constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
exaexa committed Dec 16, 2023
1 parent dcf93d4 commit 67506c0
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions src/builders/thermodynamic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,24 +136,15 @@ m = add_ratio_constraints(
)
```
"""
function add_log_ratio_constraints(
m::C.ConstraintTree,
ratios::Dict{String,Tuple{String,String,Float64}};
name::Symbol,
log_ratio_constraints(
ratios::Dict{String,Tuple{String,String,Float64}},
on::C.ConstraintTree,
) = ConstraintTree(
Symbol(cid) => C.Constraint(
value = on[Symbol(var1)].value - on[Symbol(var2)].value,
bound = log(ratio),
) for (cid, (var1, var2, ratio)) in ratios
)
for (cid, (var1, var2, ratio)) in ratios
m *=
name^Symbol(
cid,
)^C.Constraint(
value = on[Symbol(var1)].value - on[Symbol(var2)].value,
bound = log(ratio),
)
end

m
end

export add_log_ratio_constraints

Expand Down Expand Up @@ -245,12 +236,11 @@ function max_min_driving_force_analysis(
m.log_metabolite_concentrations[Symbol(mid)].bound = log(val)
end

m = add_log_ratio_constraints(
m,
concentration_ratios;
name = :metabolite_ratio_constraints,
on = m.log_metabolite_concentrations,
)
m *=
:metabolite_ratio_constraints^log_ratio_constraints(
concentration_ratios,
m.log_metabolite_concentrations,
)


optimized_constraints(
Expand Down

0 comments on commit 67506c0

Please sign in to comment.