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

Commit 941d30b

Browse files
author
Matthias Koeppe
committed
GurobiBackend.add_variables: Remove, inherit from GenericBackend
1 parent afad991 commit 941d30b

File tree

2 files changed

+6
-68
lines changed

2 files changed

+6
-68
lines changed

src/sage/numerical/backends/generic_backend.pyx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ cdef class GenericBackend:
9696
"""
9797
raise NotImplementedError()
9898

99-
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:
99+
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:
100100
"""
101101
Add ``n`` variables.
102102
103103
This amounts to adding new columns to the matrix. By default,
104-
the variables are both positive and real.
104+
the variables are both nonnegative and real.
105105
106106
INPUT:
107107
@@ -151,6 +151,10 @@ cdef class GenericBackend:
151151
"""
152152
cdef int i
153153
cdef int value
154+
if lower_bound is False:
155+
lower_bound = self.zero()
156+
if obj is None:
157+
obj = self.zero()
154158
for i in range(n):
155159
value = self.add_variable(lower_bound = lower_bound,
156160
upper_bound = upper_bound,

src/sage/numerical/backends/gurobi_backend.pyx

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -172,72 +172,6 @@ cdef class GurobiBackend(GenericBackend):
172172

173173
return self.ncols()-1
174174

175-
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:
176-
"""
177-
Add ``number`` new variables.
178-
179-
This amounts to adding new columns to the matrix. By default,
180-
the variables are both positive, real and theor coefficient in
181-
the objective function is 0.0.
182-
183-
INPUT:
184-
185-
- ``n`` - the number of new variables (must be > 0)
186-
187-
- ``lower_bound`` - the lower bound of the variable (default: 0)
188-
189-
- ``upper_bound`` - the upper bound of the variable (default: ``None``)
190-
191-
- ``binary`` - ``True`` if the variable is binary (default: ``False``).
192-
193-
- ``continuous`` - ``True`` if the variable is binary (default: ``True``).
194-
195-
- ``integer`` - ``True`` if the variable is binary (default: ``False``).
196-
197-
- ``obj`` - (optional) coefficient of all variables in the objective function (default: 0.0)
198-
199-
- ``names`` - optional list of names (default: ``None``)
200-
201-
OUTPUT: The index of the variable created last.
202-
203-
EXAMPLE::
204-
205-
sage: from sage.numerical.backends.generic_backend import get_solver # optional - Gurobi
206-
sage: p = get_solver(solver = "Gurobi") # optional - Gurobi
207-
sage: p.ncols() # optional - Gurobi
208-
0
209-
sage: p.add_variables(5) # optional - Gurobi
210-
4
211-
sage: p.ncols() # optional - Gurobi
212-
5
213-
sage: p.add_variables(2, lower_bound=-2.0, integer=True, obj=42.0, names=['a','b']) # optional - Gurobi
214-
6
215-
216-
TESTS:
217-
218-
Check that arguments are used::
219-
220-
sage: p.col_bounds(5) # tol 1e-8, optional - Gurobi
221-
(-2.0, None)
222-
sage: p.is_variable_integer(5) # optional - Gurobi
223-
True
224-
sage: p.col_name(5) # optional - Gurobi
225-
'a'
226-
sage: p.objective_coefficient(5) # tol 1e-8, optional - Gurobi
227-
42.0
228-
"""
229-
cdef int i
230-
cdef int value
231-
for i in range(number):
232-
value = self.add_variable(lower_bound = lower_bound,
233-
upper_bound = upper_bound,
234-
binary = binary,
235-
continuous = continuous,
236-
integer = integer,
237-
obj = obj,
238-
name = None if names is None else names[i])
239-
return value
240-
241175
cpdef set_variable_type(self, int variable, int vtype):
242176
"""
243177
Set the type of a variable

0 commit comments

Comments
 (0)