Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
GurobiBackend.add_variables: Remove, inherit from GenericBackend
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed May 24, 2016
1 parent afad991 commit 941d30b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 68 deletions.
8 changes: 6 additions & 2 deletions src/sage/numerical/backends/generic_backend.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ cdef class GenericBackend:
"""
raise NotImplementedError()

cpdef int add_variables(self, int n, lower_bound=0, upper_bound=None, binary=False, continuous=True, integer=False, obj=None, names=None) except -1:
cpdef int add_variables(self, int n, lower_bound=False, upper_bound=None, binary=False, continuous=True, integer=False, obj=None, names=None) except -1:
"""
Add ``n`` variables.
This amounts to adding new columns to the matrix. By default,
the variables are both positive and real.
the variables are both nonnegative and real.
INPUT:
Expand Down Expand Up @@ -151,6 +151,10 @@ cdef class GenericBackend:
"""
cdef int i
cdef int value
if lower_bound is False:
lower_bound = self.zero()
if obj is None:
obj = self.zero()
for i in range(n):
value = self.add_variable(lower_bound = lower_bound,
upper_bound = upper_bound,
Expand Down
66 changes: 0 additions & 66 deletions src/sage/numerical/backends/gurobi_backend.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -172,72 +172,6 @@ cdef class GurobiBackend(GenericBackend):

return self.ncols()-1

cpdef int add_variables(self, int number, lower_bound=0.0, upper_bound=None, binary=False, continuous=False, integer=False, obj=0.0, names=None) except -1:
"""
Add ``number`` new variables.
This amounts to adding new columns to the matrix. By default,
the variables are both positive, real and theor coefficient in
the objective function is 0.0.
INPUT:
- ``n`` - the number of new variables (must be > 0)
- ``lower_bound`` - the lower bound of the variable (default: 0)
- ``upper_bound`` - the upper bound of the variable (default: ``None``)
- ``binary`` - ``True`` if the variable is binary (default: ``False``).
- ``continuous`` - ``True`` if the variable is binary (default: ``True``).
- ``integer`` - ``True`` if the variable is binary (default: ``False``).
- ``obj`` - (optional) coefficient of all variables in the objective function (default: 0.0)
- ``names`` - optional list of names (default: ``None``)
OUTPUT: The index of the variable created last.
EXAMPLE::
sage: from sage.numerical.backends.generic_backend import get_solver # optional - Gurobi
sage: p = get_solver(solver = "Gurobi") # optional - Gurobi
sage: p.ncols() # optional - Gurobi
0
sage: p.add_variables(5) # optional - Gurobi
4
sage: p.ncols() # optional - Gurobi
5
sage: p.add_variables(2, lower_bound=-2.0, integer=True, obj=42.0, names=['a','b']) # optional - Gurobi
6
TESTS:
Check that arguments are used::
sage: p.col_bounds(5) # tol 1e-8, optional - Gurobi
(-2.0, None)
sage: p.is_variable_integer(5) # optional - Gurobi
True
sage: p.col_name(5) # optional - Gurobi
'a'
sage: p.objective_coefficient(5) # tol 1e-8, optional - Gurobi
42.0
"""
cdef int i
cdef int value
for i in range(number):
value = self.add_variable(lower_bound = lower_bound,
upper_bound = upper_bound,
binary = binary,
continuous = continuous,
integer = integer,
obj = obj,
name = None if names is None else names[i])
return value

cpdef set_variable_type(self, int variable, int vtype):
"""
Set the type of a variable
Expand Down

0 comments on commit 941d30b

Please sign in to comment.