Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mtefagh authored Sep 29, 2022
2 parents 7d726f1 + 8464e18 commit dedd6c9
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "COBRA"
uuid = "58298e0b-d05c-52ec-a210-0694647ebfc7"
version = "0.4.2"
version = "0.4.1"

[deps]
CPLEX = "a076750e-1247-5638-91d2-ce28b192dca0"
Expand Down
2 changes: 1 addition & 1 deletion src/COBRA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module COBRA
# include the load file to load a model of .mat format
import Pkg
using SparseArrays, Distributed, LinearAlgebra
using MAT, JuMP
using MAT, MathOptInterface, JuMP
using MATLAB

include("checkSetup.jl")
Expand Down
3 changes: 1 addition & 2 deletions src/distributedFBA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function preFBA!(model, solver, optPercentage::Float64=0.0, osenseStr::String="m

# solve the original LP problem
status, objval, sol = solveCobraLP(model, solver)

if status == MathOptInterface.TerminationStatusCode(1)
# retrieve the solution to the initial LP
FBAobj = objval
Expand Down Expand Up @@ -124,7 +124,6 @@ function preFBA!(model, solver, optPercentage::Float64=0.0, osenseStr::String="m
end

end

#-------------------------------------------------------------------------------------------
"""
splitRange(model, rxnsList, nWorkers, strategy, printLevel)
Expand Down
81 changes: 81 additions & 0 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
=#

#-------------------------------------------------------------------------------------------

"""
SolverConfig(name, handle)
Expand All @@ -22,6 +23,86 @@ mutable struct SolverConfig
end

#-------------------------------------------------------------------------------------------

"""
buildlp(c, A, sense, b, l, u, solver)
Function used to build a model using JuMP.
# INPUTS
- `c`: The objective vector, always in the sense of minimization
- `A`: Constraint matrix
- `sense`: Vector of constraint sense characters '<', '=', and '>'
- `b`: Right-hand side vector
- `l`: Vector of lower bounds on the variables
- `u`: Vector of upper bounds on the variables
- `solver`: A `::SolverConfig` object that contains a valid `handle`to the solver
# OUTPUTS
- `model`: An `::LPproblem` object that has been built using the JuMP.
- `x`: Primal solution vector
# EXAMPLES
```julia
julia> model, x = buildlp(c, A, sense, b, l, u, solver)
```
"""

function buildlp(c, A, sense, b, l, u, solver)
N = length(c)
model = Model(solver)
x = @variable(model, l[i] <= x[i=1:N] <= u[i])
@objective(model, Min, c' * x)
eq_rows, ge_rows, le_rows = sense .== '=', sense .== '>', sense .== '<'
@constraint(model, A[eq_rows, :] * x .== b[eq_rows])
@constraint(model, A[ge_rows, :] * x .>= b[ge_rows])
@constraint(model, A[le_rows, :] * x .<= b[le_rows])
return model, x
end

#-------------------------------------------------------------------------------------------

"""
solvelp(model, x)
Function used to solve a LPproblem using JuMP.
# INPUTS
- `model`: An `::LPproblem` object that has been built using the JuMP.
- `x`: Primal solution vector
# OUTPUTS
- `status`: Termination status
- `objval`: Optimal objective value
- `sol`: Primal solution vector
# EXAMPLES
```julia
julia> status, objval, sol = solvelp(model, x)
```
"""

function solvelp(model, x)
#println(x)
optimize!(model)
return (
status = termination_status(model),
objval = objective_value(model),
sol = value.(x)
)
end

#-------------------------------------------------------------------------------------------


"""
buildlp(c, A, sense, b, l, u, solver)
Expand Down

0 comments on commit dedd6c9

Please sign in to comment.