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

Commit

Permalink
trac #28756: fix failing doctests and compilation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoudert committed Nov 18, 2019
1 parent 232ae1b commit 5c6d5fb
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/sage/numerical/backends/gurobi_backend.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ cdef class GurobiBackend(GenericBackend):

if name is None:
name = b"x_" + bytes(self.ncols())

else:
name = str_to_bytes(name)
c_name = name

if upper_bound is None:
Expand All @@ -182,6 +183,7 @@ cdef class GurobiBackend(GenericBackend):

if coefficients is not None:

coefficients = list(coefficients)
nonzeros = len(coefficients)
c_indices = <int *> sig_malloc(nonzeros * sizeof(int))
c_coeff = <double *> sig_malloc(nonzeros * sizeof(double))
Expand Down Expand Up @@ -518,7 +520,7 @@ cdef class GurobiBackend(GenericBackend):
"""

if lower_bound is None and upper_bound is None:
raise ValueError("At least one of 'upper_bound' or 'lower_bound' must be set.")
raise ValueError("at least one of 'upper_bound' or 'lower_bound' must be set")

coefficients = list(coefficients)
cdef int n = len(coefficients)
Expand Down Expand Up @@ -549,6 +551,10 @@ cdef class GurobiBackend(GenericBackend):
else:
error = GRBaddrangeconstr(self.model, n, row_i, row_values, <double> lower_bound, <double> upper_bound, str_to_bytes(name))

else:
# This case is repeated here to avoid compilation warnings
raise ValueError("at least one of 'upper_bound' or 'lower_bound' must be set")

check(self.env,error)

error = GRBupdatemodel(self.model)
Expand Down Expand Up @@ -850,7 +856,7 @@ cdef class GurobiBackend(GenericBackend):
if name[0] == NULL:
value = ""
else:
value = str(name[0])
value = char_to_str(name[0])
return value

cpdef row_name(self, int index):
Expand All @@ -874,7 +880,7 @@ cdef class GurobiBackend(GenericBackend):
if name[0] == NULL:
value = ""
else:
value = str(name[0])
value = char_to_str(name[0])
return value

cpdef bint is_variable_binary(self, int index):
Expand Down Expand Up @@ -1152,6 +1158,8 @@ cdef class GurobiBackend(GenericBackend):
raise ValueError("This parameter is not available. "+
"Enabling it may not be so hard, though.")

name = str_to_bytes(name)

if t == "int":
if value is None:
check(self.env, GRBgetintparam(self.env, name, tmp_int))
Expand All @@ -1167,9 +1175,9 @@ cdef class GurobiBackend(GenericBackend):
elif t == "string":
if value is None:
check(self.env, GRBgetstrparam(self.env, name, c_name))
return str(c_name)
return char_to_str(c_name)
else:
check(self.env, GRBsetstrparam(self.env, name, value))
check(self.env, GRBsetstrparam(self.env, name, str_to_bytes(value)))
else:
raise RuntimeError("This should not happen.")

Expand Down

0 comments on commit 5c6d5fb

Please sign in to comment.