Skip to content

Commit 2876ea9

Browse files
authored
Merge pull request #114 from opencobra/master
Compatibility of SRC and Test with MOI (#111)
2 parents a245f73 + 69f8736 commit 2876ea9

File tree

5 files changed

+127
-5
lines changed

5 files changed

+127
-5
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "COBRA"
22
uuid = "58298e0b-d05c-52ec-a210-0694647ebfc7"
3-
version = "0.4.2"
3+
version = "0.4.1"
44

55
[deps]
66
CPLEX = "a076750e-1247-5638-91d2-ce28b192dca0"

src/connect.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function createPool(localWorkers::Int, connectSSH::Bool=false, connectionFile::S
124124
if printLevel > 0
125125
println(" >> Connecting ", sshWorkers[i]["procs"], " workers on ", sshWorkers[i]["usernode"])
126126
end
127-
127+
128128
try
129129
if !(Sys.iswindows())
130130
# try logging in quietly to defined node using SSH

src/distributedFBA.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function preFBA!(model, solver, optPercentage::Float64=0.0, osenseStr::String="m
9595
hasObjective = false
9696
fbaSol = NaN
9797
end
98-
98+
9999
# add a condition if the LP has an extra condition based on the FBA solution
100100
if hasObjective
101101
if printLevel > 0
@@ -368,7 +368,7 @@ function loopFBA(m, x, c, rxnsList, nRxns::Int, rxnsOptMode=2 .+ zeros(Int, leng
368368
else
369369
performOptim = false
370370
end
371-
371+
372372
if performOptim
373373

374374
# Set the objective vector coefficients

src/load.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,4 @@ end
226226
loadModel(fileName, matrixAS::String="S", modelName::String="model", modelFields::Array{String,1}=["ub", "lb", "osense", "c", "b", "csense", "rxns", "mets"], printLevel::Int=1) = loadModel(fileName, modelName, printLevel)
227227

228228
export loadModel
229-
#-------------------------------------------------------------------------------------------
229+
#-------------------------------------------------------------------------------------------

src/solve.jl

+122
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,128 @@ function linprog(c, A, sense, b, l, u, solver)
145145
)
146146
end
147147

148+
#-------------------------------------------------------------------------------------------
149+
"""
150+
buildlp(c, A, sense, b, l, u, solver)
151+
152+
Function used to build a model using JuMP.
153+
154+
# INPUTS
155+
156+
- `c`: The objective vector, always in the sense of minimization
157+
- `A`: Constraint matrix
158+
- `sense`: Vector of constraint sense characters '<', '=', and '>'
159+
- `b`: Right-hand side vector
160+
- `l`: Vector of lower bounds on the variables
161+
- `u`: Vector of upper bounds on the variables
162+
- `solver`: A `::SolverConfig` object that contains a valid `handle`to the solver
163+
164+
# OUTPUTS
165+
166+
- `model`: An `::LPproblem` object that has been built using the JuMP.
167+
- `x`: Primal solution vector
168+
169+
# EXAMPLES
170+
171+
```julia
172+
julia> model, x = buildlp(c, A, sense, b, l, u, solver)
173+
```
174+
175+
"""
176+
177+
function buildlp(c, A, sense, b, l, u, solver)
178+
N = length(c)
179+
model = Model(solver)
180+
x = @variable(model, l[i] <= x[i=1:N] <= u[i])
181+
@objective(model, Min, c' * x)
182+
eq_rows, ge_rows, le_rows = sense .== '=', sense .== '>', sense .== '<'
183+
@constraint(model, A[eq_rows, :] * x .== b[eq_rows])
184+
@constraint(model, A[ge_rows, :] * x .>= b[ge_rows])
185+
@constraint(model, A[le_rows, :] * x .<= b[le_rows])
186+
return model, x, c
187+
end
188+
189+
#-------------------------------------------------------------------------------------------
190+
"""
191+
solvelp(model, x)
192+
193+
Function used to solve a LPproblem using JuMP.
194+
195+
# INPUTS
196+
197+
- `model`: An `::LPproblem` object that has been built using the JuMP.
198+
- `x`: Primal solution vector
199+
200+
# OUTPUTS
201+
202+
- `status`: Termination status
203+
- `objval`: Optimal objective value
204+
- `sol`: Primal solution vector
205+
206+
# EXAMPLES
207+
208+
```julia
209+
julia> status, objval, sol = solvelp(model, x)
210+
```
211+
212+
"""
213+
214+
function solvelp(model, x)
215+
optimize!(model)
216+
return (
217+
status = termination_status(model),
218+
objval = objective_value(model),
219+
sol = value.(x)
220+
)
221+
end
222+
223+
#-------------------------------------------------------------------------------------------
224+
"""
225+
linprog(c, A, sense, b, l, u, solver)
226+
227+
Function used to build and solve a LPproblem using JuMP.
228+
229+
# INPUTS
230+
231+
- `c`: The objective vector, always in the sense of minimization
232+
- `A`: Constraint matrix
233+
- `sense`: Vector of constraint sense characters '<', '=', and '>'
234+
- `b`: Right-hand side vector
235+
- `l`: Vector of lower bounds on the variables
236+
- `u`: Vector of upper bounds on the variables
237+
- `solver`: A `::SolverConfig` object that contains a valid `handle`to the solver
238+
239+
# OUTPUTS
240+
241+
- `status`: Termination status
242+
- `objval`: Optimal objective value
243+
- `sol`: Primal solution vector
244+
245+
# EXAMPLES
246+
247+
```julia
248+
julia> status, objval, sol = linprog(c, A, sense, b, l, u, solver)
249+
```
250+
251+
"""
252+
253+
function linprog(c, A, sense, b, l, u, solver)
254+
N = length(c)
255+
model = Model(solver)
256+
@variable(model, l[i] <= x[i=1:N] <= u[i])
257+
@objective(model, Min, c' * x)
258+
eq_rows, ge_rows, le_rows = sense .== '=', sense .== '>', sense .== '<'
259+
@constraint(model, A[eq_rows, :] * x .== b[eq_rows])
260+
@constraint(model, A[ge_rows, :] * x .>= b[ge_rows])
261+
@constraint(model, A[le_rows, :] * x .<= b[le_rows])
262+
optimize!(model)
263+
return (
264+
status = termination_status(model),
265+
objval = objective_value(model),
266+
sol = value.(x)
267+
)
268+
end
269+
148270
#-------------------------------------------------------------------------------------------
149271
"""
150272
buildCobraLP(model, solver)

0 commit comments

Comments
 (0)