Skip to content

Commit 301bd14

Browse files
authored
Merge pull request #119 from opencobra/develop
CPLEX solver
2 parents adf125e + 49547d1 commit 301bd14

File tree

2 files changed

+3
-125
lines changed

2 files changed

+3
-125
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.1"
3+
version = "0.4.2"
44

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

src/solve.jl

+2-124
Original file line numberDiff line numberDiff line change
@@ -145,128 +145,6 @@ 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-
270148
#-------------------------------------------------------------------------------------------
271149
"""
272150
buildCobraLP(model, solver)
@@ -360,7 +238,7 @@ function changeCobraSolver(name, params=[]; printLevel::Int=1)
360238
if abs(printLevel) > 1
361239
printLevel = 1
362240
end
363-
solver.handle = CplexSolver(CPX_PARAM_SCRIND=printLevel)
241+
solver.handle = CPLEX.Optimizer
364242
catch
365243
error("The solver `CPLEX` cannot be set using `changeCobraSolver()`.")
366244
end
@@ -373,7 +251,7 @@ function changeCobraSolver(name, params=[]; printLevel::Int=1)
373251
solver.handle = GLPK.Optimizer
374252
end
375253
catch
376-
error("The solver `GLPK` or `GLPKMathProgInterface` cannot be set using `changeCobraSolver()`.")
254+
error("The solver `GLPK` cannot be set using `changeCobraSolver()`.")
377255
end
378256

379257
elseif name == "Gurobi"

0 commit comments

Comments
 (0)