Commit f19754a4 authored by Sylvain Arreckx's avatar Sylvain Arreckx
Browse files

use JuMP to solve the LP

parent 140d21af
......@@ -4,5 +4,7 @@ authors = ["Some people"]
version = "0.1.0"
[deps]
GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
module ***REMOVED***
export CobraLP, addReaction, addReactions
export CobraLP, addReaction, addReactions, solveLP
include("modeling.jl")
include("solveLP.jl")
end
import ..CobraLP
using JuMP
using GLPK
function solveLP(model::CobraLP)
m, n = size(model.S)
optimization_model = JuMP.Model(GLPK.Optimizer)
@variable(optimization_model, x[i=1:n], lower_bound=model.lb[i], upper_bound=model.ub[i])
@objective(optimization_model, Min, model.c' * x)
@constraint(optimization_model, model.S * x .== model.b)
JuMP.optimize!(optimization_model)
return (optimization_model, x)
end
using Test
using SparseArrays
using ***REMOVED***
using JuMP
test_cobraLP() = CobraLP(zeros(4, 3),
zeros(4),
......@@ -10,6 +11,15 @@ test_cobraLP() = CobraLP(zeros(4, 3),
["r1"],
["m1"])
test_simpleCobraLP() = CobraLP([1.0 1.0
-1.0 1.0],
[3., 1.],
[-0.25, 1.],
-ones(2),
2.0 * ones(2),
["r1"],
["m1"])
test_sparseCobraLP() = CobraLP(sprand(4000, 3000, 0.5),
sprand(4000, 0.5),
sprand(3000, 0.5),
......@@ -51,3 +61,12 @@ end
cp = addReactions(cp, 2. * ones(1000, 3000), ones(1000))
@test size(cp.S) == (5002, 3000)
end
@testset "Solve CobraLP" begin
cp = test_simpleCobraLP()
(lp, x) = solveLP(cp)
@test termination_status(lp) === MOI.OPTIMAL
sol = JuMP.value.(x)
@test sol [1., 2.]
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