Skip to content

Commit

Permalink
start cleaning the variables
Browse files Browse the repository at this point in the history
  • Loading branch information
exaexa committed Jan 3, 2024
1 parent fd1c5e8 commit 3ad2a35
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
AbstractFBCModels = "0.2.2"
Aqua = "0.7"
Clarabel = "0.6"
ConstraintTrees = "0.8"
ConstraintTrees = "0.9"
DistributedData = "0.2"
DocStringExtensions = "0.8, 0.9"
Downloads = "1"
Expand Down
3 changes: 1 addition & 2 deletions docs/src/examples/03-parsimonious-flux-balance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ model = load_model("e_coli_core.json") # load the model

# Use the convenience function to run standard pFBA on

vt =
parsimonious_flux_balance_analysis(model, Clarabel.Optimizer; settings = [silence])
vt = parsimonious_flux_balance_analysis(model, Clarabel.Optimizer; settings = [silence])

# Or use the piping functionality

Expand Down
1 change: 1 addition & 0 deletions src/COBREXA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ include("builders/loopless.jl")
include("builders/objectives.jl")
include("builders/thermodynamic.jl")
include("builders/unsigned.jl")
include("builders/variables.jl")

# simplified front-ends for the above
include("frontend/balance.jl")
Expand Down
20 changes: 17 additions & 3 deletions src/builders/unsigned.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ Shortcut for allocation non-negative ("unsigned") variables. The argument
"""
unsigned_variables(; keys) = C.variables(; keys, bounds = C.Between(0.0, Inf))

export unsigned_variables

export unsigned_variables # TODO kill

"""
$(TYPEDSIGNATURES)
Expand Down Expand Up @@ -62,11 +61,26 @@ sign_split_constraints(;
bound = C.EqualTo(0.0),
) for (k, s) in signed
)
#TODO the example above might as well go to docs
#TODO the example above needs to go to docs
# TODO this is a prime treezip candidate

export sign_split_constraints

positive_bound_contribution(b::C.EqualTo) = b.equal_to >= 0 ? b : C.EqualTo(0.0)
positive_bound_contribution(b::C.Between) =
b.lower >= 0 && b.upper >= 0 ? b :
b.lower <= 0 && b.upper <= 0 ? C.EqualTo(0) :
C.Between(max(0, b.lower), max(0, b.upper))
# TODO binary doesn't really fit here but it would be great if it could.

unsigned_positive_contribution_variables(cs::C.ConstraintTree) =
variables_for(c -> positive_bound_contribution(c.bound), cs)

unsigned_negative_contribution_variables(cs::C.ConstraintTree) =
variables_for(c -> positive_bound_contribution(c.bound), cs)

# TODO: docs, doesn't apply to fluxes only
# TODO replace by the above
function fluxes_in_direction(fluxes::C.ConstraintTree, direction = :forward)
keys = Symbol[]
for (id, flux) in fluxes
Expand Down
8 changes: 8 additions & 0 deletions src/builders/variables.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

variables_for(makebound, cs::C.ConstraintTree) =
let var_idx = 0
C.tree_map(cs, C.Constraint) do c
var_idx += 1
C.variable(idx = var_idx, bound = makebound(c))
end
end
7 changes: 1 addition & 6 deletions src/frontend/mmdf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,7 @@ function max_min_driving_force_analysis(
)


optimized_constraints(
m;
objective = m.max_min_driving_force.value,
optimizer,
settings,
)
optimized_constraints(m; objective = m.max_min_driving_force.value, optimizer, settings)
end

export max_min_driving_force_analysis

0 comments on commit 3ad2a35

Please sign in to comment.