Commit f5a527f3 authored by Miroslav Kratochvil's avatar Miroslav Kratochvil
Browse files

fix the interface name to AbstractCobraModel

(it's not necessarily going to be linear anyway,
and AbstractModel collided with JuMP.)
parent 520bb8e2
......@@ -6,5 +6,5 @@ s.t. S x = b
xₗ ≤ x ≤ xᵤ
```
"""
fluxBalanceAnalysis(model::LM, optimizer) where {LM<:AbstractLinearModel} =
fluxBalanceAnalysis(model::LM, optimizer) where {LM<:AbstractCobraModel} =
solveLP(model, optimizer; sense = MOI.MAX_SENSE)
......@@ -15,7 +15,7 @@ function fluxVariabilityAnalysis(
model::LM,
optimizer;
gamma::AbstractFloat = 1.0,
) where {LM<:AbstractLinearModel}
) where {LM<:AbstractCobraModel}
n = nReactions(model)
return fluxVariabilityAnalysis(model, collect(1:n), optimizer)
end
......@@ -26,7 +26,7 @@ function fluxVariabilityAnalysis(
optimizer,
workers = [myid()];
gamma::AbstractFloat = 1.0,
) where {LM<:AbstractLinearModel}
) where {LM<:AbstractCobraModel}
if any(reactions .< 1) || any(reactions .> nReactions(model))
throw(DomainError(reactions, "Index exceeds number of reactions."))
......
......@@ -6,7 +6,7 @@ function makeOptimizationModel(
model::LM,
optimizer;
sense = MOI.MAX_SENSE,
) where {LM<:AbstractLinearModel}
) where {LM<:AbstractCobraModel}
m, n = size(stoichiometry(model))
xl, xu = bounds(model)
......@@ -21,11 +21,7 @@ end
"""
Use JuMP to solve an instance of LinearModel
"""
function solveLP(
model::LM,
optimizer;
sense = MOI.MIN_SENSE,
) where {LM<:AbstractLinearModel}
function solveLP(model::LM, optimizer; sense = MOI.MIN_SENSE) where {LM<:AbstractCobraModel}
optimization_model, x = makeOptimizationModel(model, optimizer; sense = sense)
JuMP.optimize!(optimization_model)
return (optimization_model, x)
......
"""
abstract type AbstractLinearModel end
abstract type AbstractCobraModel end
A helper supertype that wraps everything usable as a LinearModel for COBREXA
functions. If you want to use your own type, make it a subtype (so that the
functions typecheck) and add instances for the data accessor methods below.
"""
abstract type AbstractLinearModel end
abstract type AbstractCobraModel end
const SpMtx = SparseMatrixCSC{Float64,Int}
const SpVec = SparseVector{Float64,Int}
......@@ -17,47 +17,47 @@ const ST = AbstractVector{String}
_missingImplError = (m, a) -> throw(MethodError(m, a))
function reactions(a::LM)::StrVec where {LM<:AbstractLinearModel}
function reactions(a::LM)::StrVec where {LM<:AbstractCobraModel}
_missingImplError(reactions, (a,))
end
function metabolites(a::LM)::StrVec where {LM<:AbstractLinearModel}
function metabolites(a::LM)::StrVec where {LM<:AbstractCobraModel}
_missingImplError(metabolites, (a,))
end
function nReactions(a::LM)::Int where {LM<:AbstractLinearModel}
function nReactions(a::LM)::Int where {LM<:AbstractCobraModel}
length(reactions(a))
end
function nMetabolites(a::LM)::Int where {LM<:AbstractLinearModel}
function nMetabolites(a::LM)::Int where {LM<:AbstractCobraModel}
length(metabolites(a))
end
function stoichiometry(a::LM)::SpMtx where {LM<:AbstractLinearModel}
function stoichiometry(a::LM)::SpMtx where {LM<:AbstractCobraModel}
_missingImplError(stoichiometry, (a,))
end
function bounds(a::LM)::Tuple{SpVec,SpVec} where {LM<:AbstractLinearModel}
function bounds(a::LM)::Tuple{SpVec,SpVec} where {LM<:AbstractCobraModel}
_missingImplError(bounds, (a,))
end
function balance(a::LM)::SpVec where {LM<:AbstractLinearModel}
function balance(a::LM)::SpVec where {LM<:AbstractCobraModel}
_missingImplError(balance, (a,))
end
function objective(a::LM)::SpVec where {LM<:AbstractLinearModel}
function objective(a::LM)::SpVec where {LM<:AbstractCobraModel}
_missingImplError(objective, (a,))
end
function coupling(a::LM)::SpMtx where {LM<:AbstractLinearModel}
function coupling(a::LM)::SpMtx where {LM<:AbstractCobraModel}
_missingImplError(coupling, (a,))
end
function nCouplingConstraints(a::LM)::Int where {LM<:AbstractLinearModel}
function nCouplingConstraints(a::LM)::Int where {LM<:AbstractCobraModel}
size(coupling(a), 1)
end
function couplingBounds(a::LM)::Tuple{SpVec,SpVec} where {LM<:AbstractLinearModel}
function couplingBounds(a::LM)::Tuple{SpVec,SpVec} where {LM<:AbstractCobraModel}
_missingImplError(couplingBounds, (a,))
end
......@@ -73,7 +73,7 @@ s.t. S x = b
This is the default model supported by COBREXA model building functions.
"""
mutable struct LinearModel <: AbstractLinearModel
mutable struct LinearModel <: AbstractCobraModel
S::SpMtx
b::SpVec
C::SpMtx
......
struct FakeModel <: AbstractLinearModel
struct FakeModel <: AbstractCobraModel
dummy::Int
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