diff --git a/Project.toml b/Project.toml index 3380385..c9bbab8 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "COBRA" uuid = "58298e0b-d05c-52ec-a210-0694647ebfc7" -version = "0.4.1" +version = "0.4.2" [deps] CPLEX = "a076750e-1247-5638-91d2-ce28b192dca0" diff --git a/src/solve.jl b/src/solve.jl index ebf8ccc..a545e45 100644 --- a/src/solve.jl +++ b/src/solve.jl @@ -145,128 +145,6 @@ function linprog(c, A, sense, b, l, u, solver) ) 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, c -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) - optimize!(model) - return ( - status = termination_status(model), - objval = objective_value(model), - sol = value.(x) - ) -end - -#------------------------------------------------------------------------------------------- -""" - linprog(c, A, sense, b, l, u, solver) - -Function used to build and solve a LPproblem 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 - -- `status`: Termination status -- `objval`: Optimal objective value -- `sol`: Primal solution vector - -# EXAMPLES - -```julia -julia> status, objval, sol = linprog(c, A, sense, b, l, u, solver) -``` - -""" - -function linprog(c, A, sense, b, l, u, solver) - N = length(c) - model = Model(solver) - @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]) - optimize!(model) - return ( - status = termination_status(model), - objval = objective_value(model), - sol = value.(x) - ) -end - #------------------------------------------------------------------------------------------- """ buildCobraLP(model, solver) @@ -360,7 +238,7 @@ function changeCobraSolver(name, params=[]; printLevel::Int=1) if abs(printLevel) > 1 printLevel = 1 end - solver.handle = CplexSolver(CPX_PARAM_SCRIND=printLevel) + solver.handle = CPLEX.Optimizer catch error("The solver `CPLEX` cannot be set using `changeCobraSolver()`.") end @@ -373,7 +251,7 @@ function changeCobraSolver(name, params=[]; printLevel::Int=1) solver.handle = GLPK.Optimizer end catch - error("The solver `GLPK` or `GLPKMathProgInterface` cannot be set using `changeCobraSolver()`.") + error("The solver `GLPK` cannot be set using `changeCobraSolver()`.") end elseif name == "Gurobi"