Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-cygwin-standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ jobs:
with:
stage: v-c
previous_stages: iv
targets: sage_numerical_backends_coin
targets: cylp cvxopt
needs: [cygwin-stage-iv]

cygwin-stage-v-d:
Expand Down
6 changes: 3 additions & 3 deletions build/pkgs/cbc/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tarball=cbc-VERSION.tar.gz
sha1=d937d6af1ee8838d44659ebd4cf7bbb1b20372ce
md5=2134576233cc95cdfedc63991a4944ec
cksum=1215468781
sha1=1ead967d3d5610e3c434c9aec76a31ea90eb578f
md5=c31255a6bd4ab7136f1d044f39c372da
cksum=3510659652
upstream_url=https://github.com/coin-or/Cbc/archive/refs/tags/releases/VERSION.tar.gz
2 changes: 1 addition & 1 deletion build/pkgs/cbc/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.9.4.p0
2.10.10
9 changes: 7 additions & 2 deletions build/pkgs/sage_numerical_backends_coin/SPKG.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
sage_numerical_backends_coin: COIN-OR backend for Sage MixedIntegerLinearProgram
================================================================================
sage_numerical_backends_coin: COIN-OR backend for Sage MixedIntegerLinearProgram (deprecated)
=============================================================================================

Description
-----------

COIN-OR backend for Sage MixedIntegerLinearProgram

This package is deprecated and will be removed soon.

Install packages ``cvxpy`` and ``cylp`` instead.


License
-------

Expand Down
4 changes: 3 additions & 1 deletion build/pkgs/sage_numerical_backends_coin/dependencies
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cbc cysignals $(SAGE_SRC)/sage/numerical/backends/generic_backend.pxd $(SAGE_SRC)/sage/cpython/string.pxd $(SAGE_SRC)/sage/cpython/string_impl.h | $(SAGERUNTIME) $(PYTHON_TOOLCHAIN) cython ipywidgets
cylp cvxpy cbc cysignals $(SAGE_SRC)/sage/numerical/backends/generic_backend.pxd $(SAGE_SRC)/sage/cpython/string.pxd $(SAGE_SRC)/sage/cpython/string_impl.h | $(SAGERUNTIME) $(PYTHON_TOOLCHAIN) cython ipywidgets

----------
All lines of this file are ignored except the first.

cylp and cvxpy are the recommended replacement for this deprecated package - added them to the dependencies.
6 changes: 3 additions & 3 deletions src/doc/en/thematic_tutorials/linear_programming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,10 @@ following libraries are currently supported:
* `CBC <https://github.com/coin-or/Cbc>`_: A solver from
`COIN-OR <http://www.coin-or.org/>`_,
provided under the Eclipse Public License (EPL), which is an open source
license but incompatible with GPL. CBC and the Sage CBC backend can be
installed using the shell command::
license but incompatible with GPL. Sage can use CBC via the optional
packages CyLP and CVXPy, which can be installed using the shell command::

$ sage -i -c sage_numerical_backends_coin
$ sage -i -c cylp cvxpy

* `CPLEX
<https://www.ibm.com/products/ilog-cplex-optimization-studio/>`_:
Expand Down
76 changes: 76 additions & 0 deletions src/sage/numerical/backends/cvxpy_backend.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@ cdef class CVXPYBackend:
sage: p.row_name(1)
'constraint_1'
"""
if not isinstance(coefficients, (list, tuple)):
# may be generator
coefficients = list(coefficients)
last = len(self.Matrix)
self.Matrix.append([])
for i in range(len(self.objective_coefficients)):
Expand Down Expand Up @@ -930,3 +933,76 @@ cdef class CVXPYBackend:
self.col_lower_bound[index] = value
else:
return self.col_lower_bound[index]

cpdef remove_constraint(self, int index):
"""
Remove a linear constraint by index.

INPUT:

- ``index`` -- integer. The index of the constraint to remove.

EXAMPLES::

sage: from sage.numerical.backends.generic_backend import get_solver
sage: p = get_solver(solver="CVXPY")
sage: p.add_variables(5)
4
sage: row_index = p.nrows(); row_index
5
sage: p.add_linear_constraint(zip(range(5), range(5)), 2, 2)
sage: p.nrows() - row_index
1
sage: p.add_linear_constraint(zip(range(5), range(5)), 1, 1, name='foo')
sage: p.nrows() - row_index
2
sage: p.remove_constraint(row_index)
sage: p.nrows() - row_index
1
sage: p.row_name(row_index)
'foo'
sage: p.row_bounds(row_index)
(1, 1)
sage: p.cvxpy_problem().constraints[row_index:]
[Equality(Expression(AFFINE, UNKNOWN, ()), Constant(CONSTANT, NONNEGATIVE, ()))]
"""
self.remove_constraints([index])

cpdef remove_constraints(self, indices):
r"""
Remove several constraints.

INPUT:

- ``indices`` -- iterable of integers. The indices of the constraints to remove,
in arbitrary order.

EXAMPLES::

sage: from sage.numerical.backends.generic_backend import get_solver
sage: p = get_solver(solver="CVXPY")
sage: p.add_variables(5)
4
sage: row_index = p.nrows(); row_index
5
sage: for i in range(3):
....: p.add_linear_constraint(zip(range(5), range(5)), None, 5)
sage: p.add_linear_constraint(zip(range(5), range(5)), 1, 1, name='foo')
sage: p.cvxpy_problem().constraints[row_index:]
[Inequality(Expression(AFFINE, UNKNOWN, ())),
Inequality(Expression(AFFINE, UNKNOWN, ())),
Inequality(Expression(AFFINE, UNKNOWN, ())),
Equality(Expression(AFFINE, UNKNOWN, ()), Constant(CONSTANT, NONNEGATIVE, ()))]
sage: p.remove_constraints(range(row_index, row_index + 3))
sage: p.cvxpy_problem().constraints[row_index:]
[Equality(Expression(AFFINE, UNKNOWN, ()), Constant(CONSTANT, NONNEGATIVE, ()))]
"""
indices = sorted(indices)
constraints = list(self.problem.constraints)
for index in reversed(indices):
del self.Matrix[index]
del self.row_lower_bound[index]
del self.row_upper_bound[index]
del self.constraint_names[index]
del constraints[index]
self.problem = cvxpy.Problem(self.problem.objective, constraints)
17 changes: 6 additions & 11 deletions src/sage/numerical/backends/generic_backend.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,7 @@ def default_mip_solver(solver=None):
return default_solver

else:
for s in ["Cplex", "Gurobi", "Cvxpy/cbc", "Coin", "Glpk", "SCIP"]:
for s in ["Cplex", "Gurobi", "Cvxpy/cbc", "Glpk", "SCIP"]:
try:
default_mip_solver(s)
return s
Expand All @@ -1608,20 +1608,16 @@ def default_mip_solver(solver=None):

solver = solver.capitalize()

if solver == "Coin":
solver = "Cvxpy/cbc"

if solver == "Cplex":
try:
from sage_numerical_backends_cplex.cplex_backend import CPLEXBackend
default_solver = solver
except ImportError:
raise ValueError("CPLEX is not available. Please refer to the documentation to install it.")

elif solver == "Coin":
try:
from sage_numerical_backends_coin.coin_backend import CoinBackend
default_solver = solver
except ImportError:
raise ValueError("COIN is not available. Please refer to the documentation to install it.")

elif solver == "Cvxopt":
try:
from sage.numerical.backends.cvxopt_backend import CVXOPTBackend
Expand Down Expand Up @@ -1801,10 +1797,9 @@ cpdef GenericBackend get_solver(constraint_generation = False, solver = None, ba
solver = solver.capitalize()

if solver == "Coin":
from sage_numerical_backends_coin.coin_backend import CoinBackend
return CoinBackend()
solver = "Cvxpy/cbc"

elif solver == "Glpk":
if solver == "Glpk":
from sage.numerical.backends.glpk_backend import GLPKBackend
return GLPKBackend()

Expand Down