From c2fd6a26eb4d769b2916a3f565be5493873aad3e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 7 Oct 2022 00:54:36 +0000 Subject: [PATCH 1/2] CompatHelper: bump compat for "HTTP" to "1.4" --- Project.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index de181d4..3380385 100644 --- a/Project.toml +++ b/Project.toml @@ -7,21 +7,21 @@ CPLEX = "a076750e-1247-5638-91d2-ce28b192dca0" Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6" HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3" +JuMP = "4076af6c-e467-56ae-b986-b466b2749572" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MAT = "23992714-dd62-5051-b70f-ba57cb901cac" MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" -JuMP = "4076af6c-e467-56ae-b986-b466b2749572" [compat] CPLEX = "0.9" GLPK = "1.0" -HTTP = "0.9" +HTTP = "0.9, 1.4" +JuMP = "1.0" MAT = "0.10" MathOptInterface = "0.10, 1.1" julia = "1" -JuMP = "1.0" [extras] CPLEX = "a076750e-1247-5638-91d2-ce28b192dca0" From 49547d18793362446b6bc03f67bacf4beb890efd Mon Sep 17 00:00:00 2001 From: iManGHD Date: Fri, 21 Oct 2022 15:52:45 +0330 Subject: [PATCH 2/2] Updating solve.jl --- Project.toml | 2 +- src/solve.jl | 126 +-------------------------------------------------- 2 files changed, 3 insertions(+), 125 deletions(-) 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"