diff --git a/src/sage/numerical/backends/generic_backend.pyx b/src/sage/numerical/backends/generic_backend.pyx index 69ef5bb389c..6dd85a01d9d 100644 --- a/src/sage/numerical/backends/generic_backend.pyx +++ b/src/sage/numerical/backends/generic_backend.pyx @@ -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: @@ -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, diff --git a/src/sage/numerical/backends/gurobi_backend.pyx b/src/sage/numerical/backends/gurobi_backend.pyx index 574be69f48e..72d4f595808 100644 --- a/src/sage/numerical/backends/gurobi_backend.pyx +++ b/src/sage/numerical/backends/gurobi_backend.pyx @@ -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