diff --git a/docs/src/metabolic-modeling.jl b/docs/src/metabolic-modeling.jl index 78ead1f..0feaaa9 100644 --- a/docs/src/metabolic-modeling.jl +++ b/docs/src/metabolic-modeling.jl @@ -280,8 +280,8 @@ C.constraint_values(c.objective, optimal_variable_assignment) # organisms: c = :community^( - :species1^(c * :handicap^C.Constraint(c.fluxes.R_PFK.value, 0.0)) + - :species2^(c * :handicap^C.Constraint(c.fluxes.R_ACALD.value, 0.0)) + :species1^(c * :handicap^C.Constraint(c.fluxes.R_PFK.value, 0)) + + :species2^(c * :handicap^C.Constraint(c.fluxes.R_ACALD.value, 0)) ) # We can create additional variables that represent total community intake of @@ -349,10 +349,10 @@ Dict(k => v.fluxes.R_BIOMASS_Ecoli_core_w_GAM for (k, v) in result.community) c.exchanges.oxygen.bound = (-20.0, 20.0) # ...or rebuild a whole constraint: -c.exchanges.biomass = C.Constraint(c.exchanges.biomass.value, (-20.0, 20.0)) +c.exchanges.biomass = C.Constraint(c.exchanges.biomass.value, (-20, 20)) # ...or even add new constraints, here using the index syntax for demonstration: -c[:exchanges][:production_is_zero] = C.Constraint(c.exchanges.biomass.value, 0.0) +c[:exchanges][:production_is_zero] = C.Constraint(c.exchanges.biomass.value, 0) # ...or remove some constraints (this erases the constraint that was added just # above): diff --git a/docs/src/quadratic-optimization.jl b/docs/src/quadratic-optimization.jl index 087967c..9728228 100644 --- a/docs/src/quadratic-optimization.jl +++ b/docs/src/quadratic-optimization.jl @@ -32,7 +32,7 @@ error_val = # This allows us to naturally express quadratic constraint (e.g., that an error # must not be too big); and directly observe the error values in the system. -system = :vars^system * :error^C.Constraint(value = error_val, bound = (0.0, 100.0)) +system = :vars^system * :error^C.Constraint(error_val, (0, 100)) # (For simplicity, you can also use the `Constraint` constructor to make # quadratic constraints out of `QuadraticValue`s -- it will overload properly.) diff --git a/src/constraint.jl b/src/constraint.jl index 8397e1c..2459fab 100644 --- a/src/constraint.jl +++ b/src/constraint.jl @@ -26,6 +26,10 @@ Base.@kwdef mutable struct Constraint{V} end end +Constraint(v::T, b::Int) where {T<:Value} = Constraint(v, Float64(b)) +Constraint(v::T, b::Tuple{X,Y}) where {T<:Value,X<:Real,Y<:Real} = + Constraint(v, Float64.(b)) + Base.:-(a::Constraint) = -1 * a Base.:*(a::Real, b::Constraint) = b * a Base.:*(a::Constraint, b::Real) = Constraint(