# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1334234028 -7200
# Node ID 89d18ab55f9e6be9a4bdafd529f5b26f925098fc
# Parent  7d8ac0ee679de0e5eeba4966fe280f5f65295472
Crashes and broken doctests with Gurobi

diff --git a/sage/graphs/digraph.py b/sage/graphs/digraph.py
--- a/sage/graphs/digraph.py
+++ b/sage/graphs/digraph.py
@@ -1314,18 +1314,18 @@
         - ``verbose`` -- integer (default: ``0``). Sets the level of
           verbosity. Set to 0 by default, which means quiet.
 
-        ALGORITHM: 
+        ALGORITHM:
 
         This problem is solved using Linear Programming, in two different
         ways. The first one is to solve the following formulation:
 
         .. MATH::
 
-            \mbox{Minimize : }&\sum_{(u,v)\in G} b_{(u,v)}\\ 
-            \mbox{Such that : }&\\ 
-            &\forall (u,v)\in G, d_u-d_v+nb_{(u,v)}\geq 0\\
+            \mbox{Minimize : }&\sum_{(u,v)\in G} b_{(u,v)}\\
+            \mbox{Such that : }&\\
+            &\forall (u,v)\in G, d_u-d_v+ n \cdot b_{(u,v)}\geq 0\\
             &\forall u\in G, 0\leq d_u\leq |G|\\
-                        
+
         An explanation:
 
         An acyclic digraph can be seen as a poset, and every poset has a linear
@@ -1339,17 +1339,17 @@
 
         The number of edges removed is then minimized, which is the objective.
 
-        (Constraint Generation) 
- 
+        (Constraint Generation)
+
         If the parameter ``constraint_generation`` is enabled, a more efficient
         formulation is used :
- 
-        .. MATH:: 
- 
-            \mbox{Minimize : }&\sum_{(u,v)\in G} b_{(u,v)}\\  
-            \mbox{Such that : }&\\  
-            &\forall C\text{ circuits }\subseteq G, \sum_{uv\in C}b_{(u,v)}\geq 1\\ 
- 
+
+        .. MATH::
+
+            \mbox{Minimize : }&\sum_{(u,v)\in G} b_{(u,v)}\\
+            \mbox{Such that : }&\\
+            &\forall C\text{ circuits }\subseteq G, \sum_{uv\in C}b_{(u,v)}\geq 1\\
+
         As the number of circuits contained in a graph is exponential, this LP
         is solved through constraint generation. This means that the solver is
         sequentially asked to solved the problem, knowing only a portion of the
@@ -1364,11 +1364,11 @@
 
             sage: cycle=graphs.CycleGraph(5)
             sage: dcycle=DiGraph(cycle)
-            sage: cycle.size() 
+            sage: cycle.size()
             5
             sage: dcycle.feedback_edge_set(value_only=True)
             5
-        
+
         And in this situation, for any edge `uv` of the first graph, `uv` of
         `vu` is in the returned feedback arc set::
 
@@ -1379,16 +1379,18 @@
            sage: (u,v) in feedback or (v,u) in feedback
            True
 
-        TESTS: 
- 
-        Comparing with/without constraint generation::
- 
-            sage: g = digraphs.RandomDirectedGNP(10,.3) 
-            sage: x = g.feedback_edge_set(value_only = True) 
-            sage: y = g.feedback_edge_set(value_only = True, 
-            ...          constraint_generation = False) 
-            sage: x == y 
-            True 
+        TESTS:
+
+        Comparing with/without constraint generation. Also double-checks ticket :trac:`12833`::
+
+            sage: for i in range(20):
+            ...      g = digraphs.RandomDirectedGNP(10,.3)
+            ...      x = g.feedback_edge_set(value_only = True)
+            ...      y = g.feedback_edge_set(value_only = True,
+            ...             constraint_generation = False)
+            ...      if x != y:
+            ...         print "Oh my, oh my !"
+            ...         break
         """
         # It would be a pity to start a LP if the digraph is already acyclic
         if self.is_directed_acyclic():
@@ -1409,14 +1411,14 @@
 
             # Variables are binary, and their coefficient in the objective is 1
 
-            p.set_objective( Sum( b[u][v] 
+            p.set_objective( Sum( b[u][v]
                                   for u,v in self.edges(labels = False)))
 
             p.solve(log = verbose)
 
             # For as long as we do not break because the digraph is
             # acyclic....
-            while (1):
+            while True:
 
                 # Building the graph without the edges removed by the LP
                 h = DiGraph()
@@ -1426,7 +1428,7 @@
 
                 # Is the digraph acyclic ?
                 isok, certificate = h.is_directed_acyclic(certificate = True)
-        
+
                 # If so, we are done !
                 if isok:
                     break
@@ -1437,18 +1439,18 @@
                 # There is a circuit left. Let's add the corresponding
                 # constraint !
 
-                p.add_constraint( 
-                    Sum( b[u][v] for u,v in 
+                p.add_constraint(
+                    Sum( b[u][v] for u,v in
                          zip(certificate, certificate[1:] + [certificate[0]])),
                     min = 1)
-                
+
                 obj = p.solve(log = verbose)
 
             if value_only:
                 return Integer(round(obj))
-            
+
             else:
-            
+
                 # listing the edges contained in the MFAS
                 return [(u,v) for u,v in self.edges(labels = False)
                         if p.get_values(b[u][v]) > .5]
@@ -1458,7 +1460,7 @@
         ######################################
         else:
             p=MixedIntegerLinearProgram(maximization=False, solver=solver)
-        
+
             b=p.new_variable(binary = True)
             d=p.new_variable(integer = True)
 
@@ -1468,8 +1470,7 @@
                 p.add_constraint(d[u]-d[v]+n*(b[(u,v)]),min=1)
 
             for v in self:
-                p.add_constraint(d[v],min=n)
-
+                p.add_constraint(d[v] <= n)
 
             p.set_objective(Sum([b[(u,v)] for (u,v) in self.edges(labels=None)]))
 
@@ -1477,9 +1478,9 @@
                 return Integer(round(p.solve(objective_only=True, log=verbose)))
             else:
                 p.solve(log=verbose)
-                
+
                 b_sol=p.get_values(b)
-                
+
                 return [(u,v) for (u,v) in self.edges(labels=None) if b_sol[(u,v)]==1]
 
     def feedback_vertex_set(self, value_only=False, solver=None, verbose=0, constraint_generation = True):
diff --git a/sage/numerical/backends/generic_backend.pyx b/sage/numerical/backends/generic_backend.pyx
--- a/sage/numerical/backends/generic_backend.pyx
+++ b/sage/numerical/backends/generic_backend.pyx
@@ -818,11 +818,11 @@
         - CPLEX (``solver="CPLEX"``). See the
           `CPLEX <http://www.ilog.com/products/cplex/>`_ web site.
 
-        - GUROBI (``solver="GUROBI"``). See the `GUROBI
+        - Gurobi (``solver="Gurobi"``). See the `Gurobi
           <http://www.gurobi.com/>`_ web site.
 
         ``solver`` should then be equal to one of ``"GLPK"``,
-        ``"Coin"``, ``"CPLEX"``, or ``"GUROBI"``.
+        ``"Coin"``, ``"CPLEX"``, or ``"Gurobi"``.
 
         - If ``solver=None`` (default), the current default solver's name is
           returned.
@@ -843,7 +843,7 @@
         sage: default_mip_solver("Yeahhhhhhhhhhh")
         Traceback (most recent call last):
         ...
-        ValueError: 'solver' should be set to 'GLPK', 'Coin', 'CPLEX', 'GUROBI' or None.
+        ValueError: 'solver' should be set to 'GLPK', 'Coin', 'CPLEX', 'Gurobi' or None.
         sage: default_mip_solver(former_solver)
     """
     global default_solver
@@ -854,7 +854,7 @@
             return default_solver
 
         else:
-            for s in ["CPLEX", "GUROBI", "Coin", "GLPK"]:
+            for s in ["CPLEX", "Gurobi", "Coin", "GLPK"]:
                 try:
                     default_mip_solver(s)
                     return s
@@ -875,7 +875,7 @@
         except ImportError:
             raise ValueError("COIN is not available. Please refer to the documentation to install it.")
 
-    elif solver == "GUROBI":
+    elif solver == "Gurobi":
         try:
             from sage.numerical.backends.gurobi_backend import GurobiBackend
             default_solver = solver
@@ -886,7 +886,7 @@
         default_solver = solver
 
     else:
-        raise ValueError("'solver' should be set to 'GLPK', 'Coin', 'CPLEX', 'GUROBI' or None.")
+        raise ValueError("'solver' should be set to 'GLPK', 'Coin', 'CPLEX', 'Gurobi' or None.")
 
 cpdef GenericBackend get_solver(constraint_generation = False, solver = None):
     """
@@ -905,11 +905,11 @@
         - CPLEX (``solver="CPLEX"``). See the
           `CPLEX <http://www.ilog.com/products/cplex/>`_ web site.
 
-        - GUROBI (``solver="GUROBI"``). See the `GUROBI
+        - Gurobi (``solver="Gurobi"``). See the `Gurobi
           <http://www.gurobi.com/>`_ web site.
 
         ``solver`` should then be equal to one of ``"GLPK"``, ``"Coin"``,
-        ``"CPLEX"``, ``"GUROBI"``, or ``None``. If ``solver=None`` (default),
+        ``"CPLEX"``, ``"Gurobi"``, or ``None``. If ``solver=None`` (default),
         the default solver is used (see ``default_mip_solver`` method.
 
     - ``constraint_generation`` (boolean) -- whether the solver
@@ -949,11 +949,11 @@
         from sage.numerical.backends.cplex_backend import CPLEXBackend
         return CPLEXBackend()
 
-    elif solver == "GUROBI":
+    elif solver == "Gurobi":
         from sage.numerical.backends.gurobi_backend import GurobiBackend
         return GurobiBackend()
 
     else:
-        raise ValueError("'solver' should be set to 'GLPK', 'Coin', 'CPLEX', 'GUROBI' or None (in which case the default one is used).")
+        raise ValueError("'solver' should be set to 'GLPK', 'Coin', 'CPLEX', 'Gurobi' or None (in which case the default one is used).")
 
 
diff --git a/sage/numerical/backends/gurobi_backend.pxd b/sage/numerical/backends/gurobi_backend.pxd
--- a/sage/numerical/backends/gurobi_backend.pxd
+++ b/sage/numerical/backends/gurobi_backend.pxd
@@ -61,7 +61,7 @@
      int GRBsetintparam(GRBenv *env, char * attrname, int value)
 
      GRBenv * GRBgetenv (GRBmodel * model )
-     
+
 
      int GRBgetconstrs (GRBmodel * model, int * numnzP, int * cbeg, int * cind, double * cval, int start, int len )
 
@@ -95,7 +95,7 @@
 
     cdef GRBenv * env
     cdef GRBmodel ** model
-    
+
     cdef int num_vars
 
 
diff --git a/sage/numerical/backends/gurobi_backend.pyx b/sage/numerical/backends/gurobi_backend.pyx
--- a/sage/numerical/backends/gurobi_backend.pyx
+++ b/sage/numerical/backends/gurobi_backend.pyx
@@ -1,9 +1,22 @@
 """
 Gurobi Backend
 
-AUTHORS: 
+AUTHORS:
 
 - Nathann Cohen (2011-10): initial implementation
+
+TESTS:
+
+Bug from :trac:`12833`::
+
+    sage: g = DiGraph('IESK@XgAbCgH??KG??')
+    sage: g.feedback_edge_set(value_only = True, constraint_generation = False)
+    7
+    sage: g.feedback_edge_set(value_only = True, constraint_generation = False, solver = "Gurobi") # optional - Gurobi
+    7
+
+Methods
+-------
 """
 
 ##############################################################################
@@ -16,32 +29,32 @@
 from sage.numerical.mip import MIPSolverException
 
 cdef class GurobiBackend(GenericBackend):
-    def __cinit__(self, maximization = True):
+    def __init__(self, maximization = True):
         """
         Constructor
 
         EXAMPLE::
 
-            sage: p = MixedIntegerLinearProgram(solver="Gurobi")            # optional - GUROBI
+            sage: p = MixedIntegerLinearProgram(solver="Gurobi")            # optional - Gurobi
         """
-        cdef int error 
+        cdef int error
 
         cdef GRBenv ** env
         env = <GRBenv **> sage_malloc(sizeof(GRBenv *))
-        
 
         error = GRBloadenv(env, NULL)
 
-        if error or (env[0] == NULL):
+        check(self.env, error)
+
+        if env[0] == NULL:
             raise Exception("Could not initialize Gurobi environment")
 
         self.model = <GRBmodel **> sage_malloc(sizeof(GRBmodel *))
+
         error = GRBnewmodel(env[0], self.model, NULL, 0, NULL, NULL, NULL, NULL, NULL)
 
-
         self.env = GRBgetenv (self.model[0])
 
-
         if error:
             raise Exception("Could not initialize Gurobi model")
 
@@ -82,37 +95,37 @@
 
         - ``name`` - an optional name for the newly added variable (default: ``None``).
 
-        OUTPUT: The index of the newly created variable            
+        OUTPUT: The index of the newly created variable
 
         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
+            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_variable()                                               # optional - GUROBI
+            sage: p.add_variable()                                               # optional - Gurobi
             0
-            sage: p.ncols()                                                      # optional - GUROBI
+            sage: p.ncols()                                                      # optional - Gurobi
             1
-            sage: p.add_variable(binary=True)                                    # optional - GUROBI
+            sage: p.add_variable(binary=True)                                    # optional - Gurobi
             1
-            sage: p.add_variable(lower_bound=-2.0, integer=True)                 # optional - GUROBI
+            sage: p.add_variable(lower_bound=-2.0, integer=True)                 # optional - Gurobi
             2
-            sage: p.add_variable(continuous=True, integer=True)                  # optional - GUROBI
+            sage: p.add_variable(continuous=True, integer=True)                  # optional - Gurobi
             Traceback (most recent call last):
             ...
-            ValueError: ...            
-            sage: p.add_variable(name='x',obj=1.0)                               # optional - GUROBI
+            ValueError: ...
+            sage: p.add_variable(name='x',obj=1.0)                               # optional - Gurobi
             3
-            sage: p.col_name(3)                                                  # optional - GUROBI
+            sage: p.col_name(3)                                                  # optional - Gurobi
             'x'
-            sage: p.objective_coefficient(3)                                     # optional - GUROBI
+            sage: p.objective_coefficient(3)                                     # optional - Gurobi
             1.0
         """
         # Checking the input
         cdef char vtype = int(bool(binary)) + int(bool(continuous)) + int(bool(integer))
         if  vtype == 0:
-            continuous = True            
+            continuous = True
         elif vtype != 1:
             raise ValueError("Exactly one parameter of 'binary', 'integer' and 'continuous' must be 'True'.")
 
@@ -125,7 +138,7 @@
         elif integer:
             vtype = GRB_INTEGER
 
-        cdef char * c_name = "" 
+        cdef char * c_name = ""
 
         if name is None:
             name = "x_"+str(self.ncols())
@@ -136,8 +149,8 @@
             upper_bound = GRB_INFINITY
         if lower_bound is None:
             lower_bound = -GRB_INFINITY
-        
-        
+
+
         error = GRBaddvar(self.model[0], 0, NULL, NULL, obj, <double> lower_bound, <double> upper_bound, vtype, c_name)
 
         check(self.env,error)
@@ -176,22 +189,22 @@
 
         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
+            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
+            sage: p.add_variables(5)                                                       # optional - Gurobi
             4
-            sage: p.ncols()                                                                # optional - GUROBI
+            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, names=['a','b'])      # optional - Gurobi
             6
         """
         cdef int i
         cdef int value
         for i in range(number):
-            value = self.add_variable(lower_bound = lower_bound, 
-                              upper_bound = upper_bound, 
+            value = self.add_variable(lower_bound = lower_bound,
+                              upper_bound = upper_bound,
                               binary = binary,
                               continuous = continuous,
                               integer = integer,
@@ -233,7 +246,7 @@
 #                p_types[0] = GRB_BINARY
 #            else:
 #                p_types[0] = GRB_INTEGER
-#                
+#
 #            for i in range(2, number):
 #                p_types[i] = p_types[i-1]
 #
@@ -244,7 +257,7 @@
 #            for i, name in enumerate(names):
 #                p_names[i+1] = p_names[i] + NAME_MAX_LEN
 #                p_names[i][0] = str(name)
-#                
+#
 #        error = GRBaddvars (self.model[0], number, 0, NULL, NULL, NULL, p_obj, p_lb, p_ub, p_types, p_names)
 #
 #        # Freeing the memory
@@ -279,14 +292,14 @@
 
         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
+            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_variable()                                                # optional - GUROBI
+            sage: p.add_variable()                                                # optional - Gurobi
             0
-            sage: p.set_variable_type(0,1)                                        # optional - GUROBI
-            sage: p.is_variable_integer(0)                                        # optional - GUROBI
+            sage: p.set_variable_type(0,1)                                        # optional - Gurobi
+            sage: p.is_variable_integer(0)                                        # optional - Gurobi
             True
         """
         cdef int error
@@ -314,12 +327,12 @@
 
         EXAMPLE::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver   # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                                # optional - GUROBI
-            sage: p.is_maximization()                                              # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver   # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                                # optional - Gurobi
+            sage: p.is_maximization()                                              # optional - Gurobi
             True
-            sage: p.set_sense(-1)                                                  # optional - GUROBI
-            sage: p.is_maximization()                                              # optional - GUROBI
+            sage: p.set_sense(-1)                                                  # optional - Gurobi
+            sage: p.is_maximization()                                              # optional - Gurobi
             False
         """
         cdef int error
@@ -345,14 +358,14 @@
 
         EXAMPLE::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver   # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                                # optional - GUROBI
-            sage: p.add_variable()                                                 # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver   # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                                # optional - Gurobi
+            sage: p.add_variable()                                                 # optional - Gurobi
             0
-            sage: p.objective_coefficient(0) == 0                                  # optional - GUROBI
+            sage: p.objective_coefficient(0) == 0                                  # optional - Gurobi
             True
-            sage: p.objective_coefficient(0,2)                                     # optional - GUROBI
-            sage: p.objective_coefficient(0)                                       # optional - GUROBI
+            sage: p.objective_coefficient(0,2)                                     # optional - Gurobi
+            sage: p.objective_coefficient(0)                                       # optional - Gurobi
             2.0
         """
         cdef int error
@@ -378,17 +391,17 @@
 
         EXAMPLE::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver      # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                                   # optional - GUROBI
-            sage: p.problem_name("There once was a french fry")                       # optional - GUROBI
-            sage: print p.problem_name()                                              # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver      # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                                   # optional - Gurobi
+            sage: p.problem_name("There once was a french fry")                       # optional - Gurobi
+            sage: print p.problem_name()                                              # optional - Gurobi
             There once was a french fry
 
         TESTS::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver    # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                                 # optional - GUROBI
-            sage: print p.problem_name()                                            # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver    # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                                 # optional - Gurobi
+            sage: print p.problem_name()                                            # optional - Gurobi
         """
         cdef int error
         cdef char * pp_name[1]
@@ -397,7 +410,7 @@
             error = GRBsetstrattr(self.model[0], "ModelName", name)
             check(self.env, error)
             check(self.env,GRBupdatemodel(self.model[0]))
-        
+
         else:
             check(self.env,GRBgetstrattr(self.model[0], "ModelName", <char **> pp_name))
             if pp_name[0] == NULL:
@@ -405,7 +418,7 @@
             else:
                 value = str(pp_name[0])
 
-            return value        
+            return value
 
     cpdef set_objective(self, list coeff):
         """
@@ -418,18 +431,18 @@
 
         EXAMPLE::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver     # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                                  # optional - GUROBI
-            sage: p.add_variables(5)                                                 # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver     # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                                  # optional - Gurobi
+            sage: p.add_variables(5)                                                 # optional - Gurobi
             4
-            sage: p.set_objective([1, 1, 2, 1, 3])                                   # optional - GUROBI
-            sage: map(lambda x :p.objective_coefficient(x), range(5))                # optional - GUROBI
+            sage: p.set_objective([1, 1, 2, 1, 3])                                   # optional - Gurobi
+            sage: map(lambda x :p.objective_coefficient(x), range(5))                # optional - Gurobi
             [1.0, 1.0, 2.0, 1.0, 3.0]
         """
         cdef int i = 0
         cdef double value
         cdef int error
-        
+
         for value in coeff:
             error = GRBsetdblattrelement (self.model[0], "Obj", i, value)
             check(self.env,error)
@@ -447,9 +460,9 @@
 
         EXAMPLE::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver   # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                                # optional - GUROBI
-            sage: p.set_verbosity(2)                                               # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver   # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                                # optional - Gurobi
+            sage: p.set_verbosity(2)                                               # optional - Gurobi
 
         """
         cdef int error
@@ -475,20 +488,20 @@
         - ``upper_bound`` - an upper bound, either a real value or ``None``
 
         - ``name`` - an optional name for this row (default: ``None``)
-  
+
         EXAMPLE::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver          # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                                       # optional - GUROBI
-            sage: p.add_variables(5)                                                      # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver          # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                                       # optional - Gurobi
+            sage: p.add_variables(5)                                                      # optional - Gurobi
             4
-            sage: p.add_linear_constraint( zip(range(5), range(5)), 2.0, 2.0)             # optional - GUROBI
-            sage: p.row(0)                                                                # optional - GUROBI
+            sage: p.add_linear_constraint( zip(range(5), range(5)), 2.0, 2.0)             # optional - Gurobi
+            sage: p.row(0)                                                                # optional - Gurobi
             ([0, 1, 2, 3, 4], [0.0, 1.0, 2.0, 3.0, 4.0])
-            sage: p.row_bounds(0)                                                         # optional - GUROBI
+            sage: p.row_bounds(0)                                                         # optional - Gurobi
             (2.0, 2.0)
-            sage: p.add_linear_constraint( zip(range(5), range(5)), 1.0, 1.0, name='foo') # optional - GUROBI
-            sage: p.row_name(1)                                                           # optional - GUROBI
+            sage: p.add_linear_constraint( zip(range(5), range(5)), 1.0, 1.0, name='foo') # optional - Gurobi
+            sage: p.row_name(1)                                                           # optional - Gurobi
             'foo'
         """
 
@@ -500,7 +513,7 @@
 
         row_i = <int *> sage_malloc((len(coefficients)) * sizeof(int))
         row_values = <double *> sage_malloc((len(coefficients)) * sizeof(double))
-        
+
 
         for i,(c,v) in enumerate(coefficients):
             row_i[i] = c
@@ -523,7 +536,7 @@
                 error = GRBaddrangeconstr(self.model[0], len(coefficients), row_i, row_values, <double> lower_bound, <double> upper_bound, name)
 
         check(self.env,error)
-        
+
         error = GRBupdatemodel(self.model[0])
 
         check(self.env,error)
@@ -548,14 +561,14 @@
 
         EXAMPLE::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver   # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                                # optional - GUROBI
-            sage: p.add_variables(5)                                               # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver   # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                                # optional - Gurobi
+            sage: p.add_variables(5)                                               # optional - Gurobi
             4
-            sage: p.add_linear_constraint(zip(range(5), range(5)), 2, 2)           # optional - GUROBI
-            sage: p.row(0)                                                         # optional - GUROBI
+            sage: p.add_linear_constraint(zip(range(5), range(5)), 2, 2)           # optional - Gurobi
+            sage: p.row(0)                                                         # optional - Gurobi
             ([0, 1, 2, 3, 4], [0.0, 1.0, 2.0, 3.0, 4.0])
-            sage: p.row_bounds(0)                                                  # optional - GUROBI
+            sage: p.row_bounds(0)                                                  # optional - Gurobi
             (2.0, 2.0)
         """
         cdef int error
@@ -564,10 +577,10 @@
         cdef int length[1]
         error =  GRBgetconstrs(self.model[0], length, NULL, NULL, NULL, index, 1 )
         check(self.env,error)
-        
+
         cdef int * p_indices = <int *> sage_malloc(length[0] * sizeof(int))
         cdef double * p_values = <double *> sage_malloc(length[0] * sizeof(double))
-        
+
         error =  GRBgetconstrs(self.model[0], length, <int *> fake, p_indices, p_values, index, 1 )
         check(self.env,error)
 
@@ -581,7 +594,7 @@
 
         sage_free(p_indices)
         sage_free(p_values)
-        
+
         return indices, values
 
 
@@ -601,14 +614,14 @@
 
         EXAMPLE::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver    # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                                 # optional - GUROBI
-            sage: p.add_variables(5)                                                # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver    # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                                 # optional - Gurobi
+            sage: p.add_variables(5)                                                # optional - Gurobi
             4
-            sage: p.add_linear_constraint(zip(range(5), range(5)), 2, 2)            # optional - GUROBI
-            sage: p.row(0)                                                          # optional - GUROBI
+            sage: p.add_linear_constraint(zip(range(5), range(5)), 2, 2)            # optional - Gurobi
+            sage: p.row(0)                                                          # optional - Gurobi
             ([0, 1, 2, 3, 4], [0.0, 1.0, 2.0, 3.0, 4.0])
-            sage: p.row_bounds(0)                                                   # optional - GUROBI
+            sage: p.row_bounds(0)                                                   # optional - Gurobi
             (2.0, 2.0)
         """
         cdef double d[1]
@@ -644,14 +657,14 @@
 
         EXAMPLE::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver    # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                                 # optional - GUROBI
-            sage: p.add_variable()                                                  # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver    # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                                 # optional - Gurobi
+            sage: p.add_variable()                                                  # optional - Gurobi
             0
-            sage: p.col_bounds(0)                                                   # optional - GUROBI
+            sage: p.col_bounds(0)                                                   # optional - Gurobi
             (0.0, None)
-            sage: p.variable_upper_bound(0, 5)                                      # optional - GUROBI
-            sage: p.col_bounds(0)                                                   # optional - GUROBI
+            sage: p.variable_upper_bound(0, 5)                                      # optional - Gurobi
+            sage: p.col_bounds(0)                                                   # optional - Gurobi
             (0.0, 5.0)
         """
 
@@ -660,12 +673,11 @@
         error = GRBgetdblattrelement(self.model[0], "LB", index, <double *> lb)
         check(self.env, error)
 
-
         error = GRBgetdblattrelement(self.model[0], "UB", index, <double *> ub)
         check(self.env, error)
 
         return (None if lb[0] <= -2147483647 else lb[0],
-                None if  (<int> ub[0]) >= 2147483647 else ub[0])
+                None if  ub[0] >= 2147483647 else ub[0])
 
     cpdef int solve(self) except -1:
         """
@@ -679,21 +691,21 @@
 
         EXAMPLE::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver  # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                               # optional - GUROBI
-            sage: p.add_variables(5)                                              # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver  # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                               # optional - Gurobi
+            sage: p.add_variables(5)                                              # optional - Gurobi
             4
-            sage: p.add_linear_constraint([(0,1), (1, 1)], 1.2, 1.7)              # optional - GUROBI
-            sage: p.set_variable_type(0, 1)                                       # optional - GUROBI
-            sage: p.set_variable_type(1, 1)                                       # optional - GUROBI
-            sage: p.solve()                                                       # optional - GUROBI
+            sage: p.add_linear_constraint([(0,1), (1, 1)], 1.2, 1.7)              # optional - Gurobi
+            sage: p.set_variable_type(0, 1)                                       # optional - Gurobi
+            sage: p.set_variable_type(1, 1)                                       # optional - Gurobi
+            sage: p.solve()                                                       # optional - Gurobi
             Traceback (most recent call last):
             ...
             MIPSolverException: 'Gurobi: The problem is infeasible'
         """
         cdef int error
         global mip_status
-        
+
         check(self.env, GRBoptimize(self.model[0]))
 
         cdef int status[1]
@@ -714,23 +726,23 @@
 
         EXAMPLE::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver  # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                               # optional - GUROBI
-            sage: p.add_variables(2)                                              # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver  # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                               # optional - Gurobi
+            sage: p.add_variables(2)                                              # optional - Gurobi
             1
-            sage: p.add_linear_constraint([[0, 1], [1, 2]], None, 3)              # optional - GUROBI
-            sage: p.set_objective([2, 5])                                         # optional - GUROBI
-            sage: p.solve()                                                       # optional - GUROBI
+            sage: p.add_linear_constraint([[0, 1], [1, 2]], None, 3)              # optional - Gurobi
+            sage: p.set_objective([2, 5])                                         # optional - Gurobi
+            sage: p.solve()                                                       # optional - Gurobi
             0
-            sage: p.get_objective_value()                                         # optional - GUROBI
+            sage: p.get_objective_value()                                         # optional - Gurobi
             7.5
-            sage: p.get_variable_value(0)                                         # optional - GUROBI
+            sage: p.get_variable_value(0)                                         # optional - Gurobi
             0.0
-            sage: p.get_variable_value(1)                                         # optional - GUROBI
+            sage: p.get_variable_value(1)                                         # optional - Gurobi
             1.5
         """
         cdef double p_value[1]
-        
+
         check(self.env,GRBgetdblattr(self.model[0], "ObjVal", <double* >p_value))
 
         return p_value[0]
@@ -745,19 +757,19 @@
 
         EXAMPLE::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver   # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                                # optional - GUROBI
-            sage: p.add_variables(2)                                               # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver   # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                                # optional - Gurobi
+            sage: p.add_variables(2)                                               # optional - Gurobi
             1
-            sage: p.add_linear_constraint([[0, 1], [1, 2]], None, 3)               # optional - GUROBI
-            sage: p.set_objective([2, 5])                                          # optional - GUROBI
-            sage: p.solve()                                                        # optional - GUROBI
+            sage: p.add_linear_constraint([[0, 1], [1, 2]], None, 3)               # optional - Gurobi
+            sage: p.set_objective([2, 5])                                          # optional - Gurobi
+            sage: p.solve()                                                        # optional - Gurobi
             0
-            sage: p.get_objective_value()                                          # optional - GUROBI
+            sage: p.get_objective_value()                                          # optional - Gurobi
             7.5
-            sage: p.get_variable_value(0)                                          # optional - GUROBI
+            sage: p.get_variable_value(0)                                          # optional - Gurobi
             0.0
-            sage: p.get_variable_value(1)                                          # optional - GUROBI
+            sage: p.get_variable_value(1)                                          # optional - Gurobi
             1.5
         """
 
@@ -771,13 +783,13 @@
 
         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
+            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(2)                                              # optional - GUROBI
+            sage: p.add_variables(2)                                              # optional - Gurobi
             1
-            sage: p.ncols()                                                       # optional - GUROBI
+            sage: p.ncols()                                                       # optional - Gurobi
             2
         """
         cdef int i[1]
@@ -790,13 +802,13 @@
 
         EXAMPLE::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                              # optional - GUROBI
-            sage: p.nrows()                                                      # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                              # optional - Gurobi
+            sage: p.nrows()                                                      # optional - Gurobi
             0
-            sage: p.add_linear_constraint([], 2, None)                           # optional - GUROBI
-            sage: p.add_linear_constraint([], 2, None)                           # optional - GUROBI
-            sage: p.nrows()                                                      # optional - GUROBI
+            sage: p.add_linear_constraint([], 2, None)                           # optional - Gurobi
+            sage: p.add_linear_constraint([], 2, None)                           # optional - Gurobi
+            sage: p.nrows()                                                      # optional - Gurobi
             2
         """
         cdef int i[1]
@@ -813,11 +825,11 @@
 
         EXAMPLE::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver  # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                               # optional - GUROBI
-            sage: p.add_variable(name='I am a variable')                          # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver  # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                               # optional - Gurobi
+            sage: p.add_variable(name='I am a variable')                          # optional - Gurobi
             0
-            sage: p.col_name(0)                                                   # optional - GUROBI
+            sage: p.col_name(0)                                                   # optional - Gurobi
             'I am a variable'
         """
         cdef char * name[1]
@@ -838,10 +850,10 @@
 
         EXAMPLE::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver  # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                               # optional - GUROBI
-            sage: p.add_linear_constraint([], 2, None, name='Empty constraint 1') # optional - GUROBI
-            sage: p.row_name(0)                                                   # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver  # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                               # optional - Gurobi
+            sage: p.add_linear_constraint([], 2, None, name='Empty constraint 1') # optional - Gurobi
+            sage: p.row_name(0)                                                   # optional - Gurobi
             'Empty constraint 1'
         """
         cdef char * name[1]
@@ -862,14 +874,14 @@
 
         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
+            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_variable()                                                 # optional - GUROBI
+            sage: p.add_variable()                                                 # optional - Gurobi
             0
-            sage: p.set_variable_type(0,0)                                         # optional - GUROBI
-            sage: p.is_variable_binary(0)                                          # optional - GUROBI
+            sage: p.set_variable_type(0,0)                                         # optional - Gurobi
+            sage: p.is_variable_binary(0)                                          # optional - Gurobi
             True
         """
         cdef char vtype[1]
@@ -887,14 +899,14 @@
 
         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
+            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_variable()                                                # optional - GUROBI
+            sage: p.add_variable()                                                # optional - Gurobi
             0
-            sage: p.set_variable_type(0,1)                                        # optional - GUROBI
-            sage: p.is_variable_integer(0)                                        # optional - GUROBI
+            sage: p.set_variable_type(0,1)                                        # optional - Gurobi
+            sage: p.is_variable_integer(0)                                        # optional - Gurobi
             True
         """
         cdef char vtype[1]
@@ -911,16 +923,16 @@
 
         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
+            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_variable()                                                 # optional - GUROBI
+            sage: p.add_variable()                                                 # optional - Gurobi
             0
-            sage: p.is_variable_continuous(0)                                      # optional - GUROBI
+            sage: p.is_variable_continuous(0)                                      # optional - Gurobi
             True
-            sage: p.set_variable_type(0,1)                                         # optional - GUROBI
-            sage: p.is_variable_continuous(0)                                      # optional - GUROBI
+            sage: p.set_variable_type(0,1)                                         # optional - Gurobi
+            sage: p.is_variable_continuous(0)                                      # optional - Gurobi
             False
 
         """
@@ -934,12 +946,12 @@
 
         EXAMPLE::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver    # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                                 # optional - GUROBI
-            sage: p.is_maximization()                                               # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver    # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                                 # optional - Gurobi
+            sage: p.is_maximization()                                               # optional - Gurobi
             True
-            sage: p.set_sense(-1)                                                   # optional - GUROBI
-            sage: p.is_maximization()                                               # optional - GUROBI
+            sage: p.set_sense(-1)                                                   # optional - Gurobi
+            sage: p.is_maximization()                                               # optional - Gurobi
             False
         """
         cdef int sense[1]
@@ -960,22 +972,22 @@
 
         EXAMPLE::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver    # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                                 # optional - GUROBI
-            sage: p.add_variable()                                                  # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver    # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                                 # optional - Gurobi
+            sage: p.add_variable()                                                  # optional - Gurobi
             0
-            sage: p.col_bounds(0)                                                   # optional - GUROBI
+            sage: p.col_bounds(0)                                                   # optional - Gurobi
             (0.0, None)
-            sage: p.variable_upper_bound(0, 5)                                      # optional - GUROBI
-            sage: p.col_bounds(0)                                                   # optional - GUROBI
+            sage: p.variable_upper_bound(0, 5)                                      # optional - Gurobi
+            sage: p.col_bounds(0)                                                   # optional - Gurobi
             (0.0, 5.0)
         """
         cdef double b[1]
 
         if not value is False:
             check(self.env, GRBsetdblattrelement(
-                    self.model[0], "UB", 
-                    index, 
+                    self.model[0], "UB",
+                    index,
                     value if value is not None else GRB_INFINITY))
 
             check(self.env,GRBupdatemodel(self.model[0]))
@@ -998,23 +1010,23 @@
 
         EXAMPLE::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver    # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                                 # optional - GUROBI
-            sage: p.add_variable()                                                  # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver    # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                                 # optional - Gurobi
+            sage: p.add_variable()                                                  # optional - Gurobi
             0
-            sage: p.col_bounds(0)                                                   # optional - GUROBI
+            sage: p.col_bounds(0)                                                   # optional - Gurobi
             (0.0, None)
-            sage: p.variable_lower_bound(0, 5)                                      # optional - GUROBI
-            sage: p.col_bounds(0)                                                   # optional - GUROBI
+            sage: p.variable_lower_bound(0, 5)                                      # optional - Gurobi
+            sage: p.col_bounds(0)                                                   # optional - Gurobi
             (5.0, None)
         """
         cdef double b[1]
 
-        
+
         if not value is False:
             check(self.env, GRBsetdblattrelement(
-                    self.model[0], "LB", 
-                    index, 
+                    self.model[0], "LB",
+                    index,
                     value if value is not None else -GRB_INFINITY))
 
             check(self.env,GRBupdatemodel(self.model[0]))
@@ -1029,18 +1041,18 @@
         Write the problem to a .lp file
 
         INPUT:
-        
+
         - ``filename`` (string)
 
         EXAMPLE::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver    # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                                 # optional - GUROBI
-            sage: p.add_variables(2)                                                # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver    # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                                 # optional - Gurobi
+            sage: p.add_variables(2)                                                # optional - Gurobi
             1
-            sage: p.add_linear_constraint([[0, 1], [1, 2]], None, 3)                # optional - GUROBI
-            sage: p.set_objective([2, 5])                                           # optional - GUROBI
-            sage: p.write_lp(SAGE_TMP+"/lp_problem.lp")                             # optional - GUROBI
+            sage: p.add_linear_constraint([[0, 1], [1, 2]], None, 3)                # optional - Gurobi
+            sage: p.set_objective([2, 5])                                           # optional - Gurobi
+            sage: p.write_lp(SAGE_TMP+"/lp_problem.lp")                             # optional - Gurobi
         """
         check(self.env, GRBwrite(self.model[0], filename))
 
@@ -1049,18 +1061,18 @@
         Write the problem to a .mps file
 
         INPUT:
-        
+
         - ``filename`` (string)
 
         EXAMPLE::
 
-            sage: from sage.numerical.backends.generic_backend import get_solver    # optional - GUROBI
-            sage: p = get_solver(solver = "Gurobi")                                 # optional - GUROBI
-            sage: p.add_variables(2)                                                # optional - GUROBI
+            sage: from sage.numerical.backends.generic_backend import get_solver    # optional - Gurobi
+            sage: p = get_solver(solver = "Gurobi")                                 # optional - Gurobi
+            sage: p.add_variables(2)                                                # optional - Gurobi
             1
-            sage: p.add_linear_constraint([[0, 1], [1, 2]], None, 3)                # optional - GUROBI
-            sage: p.set_objective([2, 5])                                           # optional - GUROBI
-            sage: p.write_lp(SAGE_TMP+"/lp_problem.lp")                             # optional - GUROBI
+            sage: p.add_linear_constraint([[0, 1], [1, 2]], None, 3)                # optional - Gurobi
+            sage: p.set_objective([2, 5])                                           # optional - Gurobi
+            sage: p.write_lp(SAGE_TMP+"/lp_problem.lp")                             # optional - Gurobi
         """
         check(self.env, GRBwrite(self.model[0], filename))
 
@@ -1068,7 +1080,8 @@
         """
         Destructor
         """
-        GRBfreemodel(self.model[0])
+        if self.model != NULL:
+            GRBfreemodel(self.model[0])
 
 
 cdef dict errors = {
diff --git a/sage/numerical/mip.pyx b/sage/numerical/mip.pyx
--- a/sage/numerical/mip.pyx
+++ b/sage/numerical/mip.pyx
@@ -456,7 +456,7 @@
         others.
 
         ``lower_bound`` and ``upper_bound`` are numerical values.
-        
+
         EXAMPLE:
 
         First, let us define a small LP::
@@ -526,7 +526,7 @@
             for i in indices:
                 lb, ub = b.row_bounds(i)
                 result.append((lb, b.row(i), ub))
-        
+
             return result
 
         # Weird Input
@@ -576,11 +576,11 @@
         cdef GenericBackend b = self._backend
 
         # inv_variables associates a MIPVariable object to an id
-        inv_variables = [0]*len(self._variables)
+        inv_variables = {}
+
         for (v, id) in self._variables.iteritems():
             inv_variables[id]=v
 
-
         # varid_name associates variables id to names
         varid_name = {}
 
@@ -592,7 +592,7 @@
 
         print ("Maximization:" if b.is_maximization() else "Minimization:")
         print " ",
-        
+
         first = True
         for 0<= i< b.ncols():
             c = b.objective_coefficient(i)
@@ -1493,7 +1493,8 @@
 
               The command ::
 
-                  sage: p.solver_parameter("CPX_PARAM_TILIM", 60) # optional - CPLEX
+                  sage: p = MixedIntegerLinearProgram(solver = "CPLEX") # optional - CPLEX
+                  sage: p.solver_parameter("CPX_PARAM_TILIM", 60)       # optional - CPLEX
 
               works as intended.
 
