diff --git a/src/sage/numerical/backends/coin_backend.pyx b/src/sage/numerical/backends/coin_backend.pyx index 3a67b413156..6b68f45549f 100644 --- a/src/sage/numerical/backends/coin_backend.pyx +++ b/src/sage/numerical/backends/coin_backend.pyx @@ -179,10 +179,21 @@ cdef class CoinBackend(GenericBackend): 4 sage: p.ncols() # optional - cbc 5 - sage: p.add_variables(2, lower_bound=-2.0, integer=True, names=['a','b']) # optional - cbc + sage: p.add_variables(2, lower_bound=-2.0, integer=True, obj=42.0, names=['a','b']) # optional - cbc 6 - sage: p.col_name(5) # optional - cbc + + TESTS: + + Check that arguments are used:: + + sage: p.col_bounds(5) # tol 1e-8, optional - cbc + (-2.0, None) + sage: p.is_variable_integer(5) # optional - cbc + True + sage: p.col_name(5) # optional - cbc 'a' + sage: p.objective_coefficient(5) # tol 1e-8, optional - cbc + 42.0 """ #cdef int vtype = int(bool(binary)) + int(bool(continuous)) + int(bool(integer)) cdef int vtype = int(binary) + int(continuous) + int(integer) @@ -1685,4 +1696,4 @@ cdef class CoinBackend(GenericBackend): raise MIPSolverException('CBC : Signal sent, getReducedCost() fails') else: cost = [c_cost[i] for i in range(n)] - return cost \ No newline at end of file + return cost diff --git a/src/sage/numerical/backends/cplex_backend.pyx b/src/sage/numerical/backends/cplex_backend.pyx index 4b6f10487d2..8987f016af6 100644 --- a/src/sage/numerical/backends/cplex_backend.pyx +++ b/src/sage/numerical/backends/cplex_backend.pyx @@ -170,8 +170,21 @@ cdef class CPLEXBackend(GenericBackend): 4 sage: p.ncols() # optional - CPLEX 5 - sage: p.add_variables(2, lower_bound=-2.0, integer=True, names=['a','b']) # optional - CPLEX + sage: p.add_variables(2, lower_bound=-2.0, integer=True, obj=42.0, names=['a','b']) # optional - CPLEX 6 + + TESTS: + + Check that arguments are used:: + + sage: p.col_bounds(5) # tol 1e-8, optional - CPLEX + (-2.0, None) + sage: p.is_variable_integer(5) # optional - CPLEX + True + sage: p.col_name(5) # optional - CPLEX + 'a' + sage: p.objective_coefficient(5) # tol 1e-8, optional - CPLEX + 42.0 """ cdef char * c_name cdef double c_coeff = obj diff --git a/src/sage/numerical/backends/cvxopt_backend.pyx b/src/sage/numerical/backends/cvxopt_backend.pyx index a23f32caf5c..37774f0b3b1 100644 --- a/src/sage/numerical/backends/cvxopt_backend.pyx +++ b/src/sage/numerical/backends/cvxopt_backend.pyx @@ -138,7 +138,7 @@ cdef class CVXOPTBackend(GenericBackend): ... RuntimeError: CVXOPT only supports continuous variables """ - if obj == None: + if obj is None: obj = 0.0 if binary or integer: raise RuntimeError("CVXOPT only supports continuous variables") @@ -150,7 +150,7 @@ cdef class CVXOPTBackend(GenericBackend): return len(self.objective_function) - 1 - cpdef int add_variables(self, int n, lower_bound=None, upper_bound=None, binary=False, continuous=True, integer=False, obj=None, names=None) except -1: + cpdef int add_variables(self, int n, lower_bound=0.0, upper_bound=None, binary=False, continuous=True, integer=False, obj=None, names=None) except -1: """ Add ``n`` variables. @@ -187,11 +187,23 @@ cdef class CVXOPTBackend(GenericBackend): 4 sage: p.ncols() 5 - sage: p.add_variables(2, lower_bound=-2.0, integer=True, names=['a','b']) + sage: p.add_variables(2, lower_bound=-2.0, obj=42.0, names=['a','b']) 6 + + TESTS: + + Check that arguments are used:: + + sage: p.col_bounds(5) # tol 1e-8 + (-2.0, None) + sage: p.col_name(5) + 'a' + sage: p.objective_coefficient(5) # tol 1e-8 + 42.0 """ for i in range(n): - self.add_variable() + self.add_variable(lower_bound, upper_bound, binary, continuous, integer, obj, + None if names is None else names[i]) return len(self.objective_function) - 1; @@ -417,10 +429,17 @@ cdef class CVXOPTBackend(GenericBackend): ([], []) sage: p.row_bounds(4) (None, 2) + + TESTS: + + It does not add mysterious new variables:: + + sage: p.ncols() + 5 + """ for i in range(number): - self.add_linear_constraint(zip(range(self.ncols()+1),[0]*(self.ncols()+1)), - lower_bound, upper_bound, + self.add_linear_constraint([], lower_bound, upper_bound, name=None if names is None else names[i]) cpdef int solve(self) except -1: @@ -1022,7 +1041,7 @@ cdef class CVXOPTBackend(GenericBackend): sage: p.solver_parameter("show_progress") True """ - if value == None: + if value is None: return self.param[name] else: self.param[name] = value diff --git a/src/sage/numerical/backends/glpk_backend.pyx b/src/sage/numerical/backends/glpk_backend.pyx index 13132293630..bfe9f7b5a7c 100644 --- a/src/sage/numerical/backends/glpk_backend.pyx +++ b/src/sage/numerical/backends/glpk_backend.pyx @@ -176,8 +176,21 @@ cdef class GLPKBackend(GenericBackend): 4 sage: p.ncols() 5 - sage: p.add_variables(2, lower_bound=-2.0, integer=True, names=['a','b']) + sage: p.add_variables(2, lower_bound=-2.0, integer=True, obj=42.0, names=['a','b']) 6 + + TESTS: + + Check that arguments are used:: + + sage: p.col_bounds(5) # tol 1e-8 + (-2.0, None) + sage: p.is_variable_integer(5) + True + sage: p.col_name(5) + 'a' + sage: p.objective_coefficient(5) + 42.0 """ cdef int vtype = int(bool(binary)) + int(bool(continuous)) + int(bool(integer)) if vtype == 0: @@ -206,7 +219,7 @@ cdef class GLPKBackend(GenericBackend): self.objective_coefficient(n_var - i - 1, obj) if names is not None: - glp_set_col_name(self.lp, n_var, names[number - i - 1]) + glp_set_col_name(self.lp, n_var - i, names[number - i - 1]) return n_var - 1 diff --git a/src/sage/numerical/backends/gurobi_backend.pyx b/src/sage/numerical/backends/gurobi_backend.pyx index 67a17c030d9..b025a8273a3 100644 --- a/src/sage/numerical/backends/gurobi_backend.pyx +++ b/src/sage/numerical/backends/gurobi_backend.pyx @@ -196,8 +196,21 @@ cdef class GurobiBackend(GenericBackend): 4 sage: p.ncols() # optional - Gurobi 5 - sage: p.add_variables(2, lower_bound=-2.0, integer=True, names=['a','b']) # optional - Gurobi + 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 diff --git a/src/sage/numerical/backends/ppl_backend.pyx b/src/sage/numerical/backends/ppl_backend.pyx index b696612fa93..e633fd31f21 100644 --- a/src/sage/numerical/backends/ppl_backend.pyx +++ b/src/sage/numerical/backends/ppl_backend.pyx @@ -178,7 +178,13 @@ cdef class PPLBackend(GenericBackend): 'x' sage: p.objective_coefficient(2) 2/3 + sage: p.add_variable(integer=True) + Traceback (most recent call last): + ... + NotImplementedError: The PPL backend in Sage only supports continuous variables """ + if binary or integer: + raise NotImplementedError("The PPL backend in Sage only supports continuous variables") for i in range(len(self.Matrix)): self.Matrix[i].append(0) self.col_lower_bound.append(lower_bound) @@ -226,9 +232,22 @@ cdef class PPLBackend(GenericBackend): 4 sage: p.ncols() 5 - sage: p.add_variables(2, lower_bound=-2.0, names=['a','b']) + sage: p.add_variables(2, lower_bound=-2.0, obj=42.0, names=['a','b']) 6 + + TESTS: + + Check that arguments are used:: + + sage: p.col_bounds(5) # tol 1e-8 + (-2.0, None) + sage: p.col_name(5) + 'a' + sage: p.objective_coefficient(5) # tol 1e-8 + 42.0 """ + if binary or integer: + raise NotImplementedError("The PPL backend in Sage only supports continuous variables") for k in range(n): for i in range(len(self.Matrix)): self.Matrix[i].append(0)