Ticket #12833: trac_12833-docstrings.patch

File trac_12833-docstrings.patch, 8.2 KB (added by ncohen, 9 years ago)
  • sage/numerical/backends/generic_backend.pyx

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1334927241 -7200
    # Node ID 501d84007144e24da097156db23ce37cb499b962
    # Parent  89d18ab55f9e6be9a4bdafd529f5b26f925098fc
    Fixing doctests in sage/numerical/mip.pyx when using Gurobi
    
    diff --git a/sage/numerical/backends/generic_backend.pyx b/sage/numerical/backends/generic_backend.pyx
    a b  
    854854            return default_solver
    855855
    856856        else:
    857             for s in ["CPLEX", "Gurobi", "Coin", "GLPK"]:
     857            for s in ["Cplex", "Gurobi", "Coin", "Glpk"]:
    858858                try:
    859859                    default_mip_solver(s)
    860860                    return s
    861861                except ValueError:
    862862                    pass
    863863
    864     elif solver == "CPLEX":
     864    solver = solver.capitalize()
     865
     866    if solver == "Cplex":
    865867        try:
    866868            from sage.numerical.backends.cplex_backend import CPLEXBackend
    867869            default_solver = solver
     
    882884        except ImportError:
    883885            raise ValueError("Gurobi is not available. Please refer to the documentation to install it.")
    884886
    885     elif solver == "GLPK":
     887    elif solver == "Glpk":
    886888        default_solver = solver
    887889
    888890    else:
     
    935937        # We do not want to use Coin for constraint_generation. It just does not
    936938        # work
    937939        if solver == "Coin" and constraint_generation:
    938             solver = "GLPK"
     940            solver = "Glpk"
     941
     942    else:
     943        solver = solver.capitalize()
    939944
    940945    if solver == "Coin":
    941946        from sage.numerical.backends.coin_backend import CoinBackend
    942947        return CoinBackend()
    943948
    944     elif solver == "GLPK":
     949    elif solver == "Glpk":
    945950        from sage.numerical.backends.glpk_backend import GLPKBackend
    946951        return GLPKBackend()
    947952
    948     elif solver == "CPLEX":
     953    elif solver == "Cplex":
    949954        from sage.numerical.backends.cplex_backend import CPLEXBackend
    950955        return CPLEXBackend()
    951956
  • sage/numerical/mip.pyx

    diff --git a/sage/numerical/mip.pyx b/sage/numerical/mip.pyx
    a b  
    5252
    5353The following example shows all these steps::
    5454
    55     sage: p = MixedIntegerLinearProgram(maximization=False)
     55    sage: p = MixedIntegerLinearProgram(maximization=False, solver = "GLPK")
    5656    sage: w = p.new_variable(integer=True)
    5757    sage: p.add_constraint(w[0] + w[1] + w[2] - 14*w[3] == 0)
    5858    sage: p.add_constraint(w[1] + 2*w[2] - 8*w[3] == 0)
     
    9696    programming (LP) and mixed integer programming (MIP) solvers.
    9797
    9898    See the Wikipedia article on `linear programming
    99     <http://en.wikipedia.org/wiki/Linear_programming>`_ for further information.
     99    <http://en.wikipedia.org/wiki/Linear_programming>`_ for further information
     100    on linear programming and the documentation of the :mod:`MILP module
     101    <sage.numerical.mip>` for its use in Sage.
    100102
    101103    A mixed integer program consists of variables, linear constraints on these
    102104    variables, and an objective function which is to be maximised or minimised
     
    105107
    106108    INPUT:
    107109
    108     - ``solver`` -- 3 solvers should be available through this class:
     110    - ``solver`` -- 4 solvers should be available through this class:
    109111
    110112      - GLPK (``solver="GLPK"``). See the `GLPK
    111113        <http://www.gnu.org/software/glpk/>`_ web site.
     
    116118      - CPLEX (``solver="CPLEX"``). See the `CPLEX
    117119        <http://www.ilog.com/products/cplex/>`_ web site.
    118120
    119       - GUROBI (``solver="GUROBI"``). See the `GUROBI <http://www.gurobi.com/>`_
     121      - Gurobi (``solver="Gurobi"``). See the `Gurobi <http://www.gurobi.com/>`_
    120122          web site.
    121123
    122124      - If ``solver=None`` (default), the default solver is used (see
     
    158160
    159161        INPUT:
    160162
    161         - ``solver`` -- 3 solvers should be available through this class:
     163        - ``solver`` -- 4 solvers should be available through this class:
    162164
    163165          - GLPK (``solver="GLPK"``). See the `GLPK
    164166            <http://www.gnu.org/software/glpk/>`_ web site.
     
    170172            <http://www.ilog.com/products/cplex/>`_ web site.  An interface to
    171173            CPLEX is not yet implemented.
    172174
    173           - GUROBI (``solver="GUROBI"``). See the `GUROBI
     175          - Gurobi (``solver="Gurobi"``). See the `Gurobi
    174176            <http://www.gurobi.com/>`_ web site.
    175177
    176178          -If ``solver=None`` (default), the default solver is used (see
     
    494496
    495497        Running the examples from above, reordering applied::
    496498
    497             sage: p = MixedIntegerLinearProgram()
     499            sage: p = MixedIntegerLinearProgram(solver = "GLPK")
    498500            sage: p.add_constraint(p[0] - p[2], min = 1, max = 4)
    499501            sage: p.add_constraint(p[0] - 2*p[1], min = 1)
    500502            sage: sorted(map(reorder_constraint,p.constraints()))
     
    542544
    543545        When constraints and variables have names ::
    544546
    545             sage: p = MixedIntegerLinearProgram()
     547            sage: p = MixedIntegerLinearProgram(solver = "GLPK")
    546548            sage: x = p.new_variable(name="Hey")
    547549            sage: p.set_objective(x[1] + x[2])
    548550            sage: p.add_constraint(-3*x[1] + 2*x[2], max=2, name="Constraint_1")
     
    557559
    558560        Without any names ::
    559561
    560             sage: p = MixedIntegerLinearProgram()
     562            sage: p = MixedIntegerLinearProgram(solver = "GLPK")
    561563            sage: x = p.new_variable()
    562564            sage: p.set_objective(x[1] + x[2])
    563565            sage: p.add_constraint(-3*x[1] + 2*x[2], max=2)
     
    807809
    808810        INPUT:
    809811
    810         - ``obj`` -- A linear function to be optimized. 
     812        - ``obj`` -- A linear function to be optimized.
    811813          ( can also be set to ``None`` or ``0`` when just
    812814          looking for a feasible solution )
    813815
     
    834836            sage: round(p.solve(),5)
    835837            6.66667
    836838            sage: p.set_objective(None)
    837             sage: p.solve()
    838             0.0
     839            sage: _ = p.solve()
    839840        """
    840841        cdef list values = []
    841842
     
    850851            f = obj.dict()
    851852        else:
    852853            f = {-1 : 0}
    853        
     854
    854855        f.pop(-1,0)
    855856
    856857        for i in range(self._backend.ncols()):
     
    858859
    859860
    860861        self._backend.set_objective(values)
    861            
     862
    862863    def add_constraint(self, linear_function, max=None, min=None, name=None):
    863864        r"""
    864865        Adds a constraint to the ``MixedIntegerLinearProgram``.
     
    937938
    938939        Complex constraints::
    939940
    940             sage: p = MixedIntegerLinearProgram()
     941            sage: p = MixedIntegerLinearProgram(solver = "GLPK")
    941942            sage: b = p.new_variable()
    942943            sage: p.add_constraint( b[8] - b[15] <= 3*b[8] + 9)
    943944            sage: p.show()
     
    967968            ValueError: min and max arguments are required to be numerical
    968969
    969970        Do not add redundant elements (notice only one copy of each constraint is added)::
    970        
    971             sage: lp = MixedIntegerLinearProgram(check_redundant=True)
    972             sage: for each in xrange(10): lp.add_constraint(lp[0]-lp[1],min=1) 
    973             sage: lp.show() 
    974             Maximization: 
    975             <BLANKLINE> 
    976             Constraints: 
    977               1.0 <= x_0 -x_1 
    978             Variables: 
    979               x_0 is a continuous variable (min=0.0, max=+oo) 
    980               x_1 is a continuous variable (min=0.0, max=+oo) 
    981                
     971
     972            sage: lp = MixedIntegerLinearProgram(solver = "GLPK", check_redundant=True)
     973            sage: for each in xrange(10): lp.add_constraint(lp[0]-lp[1],min=1)
     974            sage: lp.show()
     975            Maximization:
     976            <BLANKLINE>
     977            Constraints:
     978              1.0 <= x_0 -x_1
     979            Variables:
     980              x_0 is a continuous variable (min=0.0, max=+oo)
     981              x_1 is a continuous variable (min=0.0, max=+oo)
     982
    982983        We check for constant multiples of constraints as well::
    983          
    984             sage: for each in xrange(10): lp.add_constraint(2*lp[0]-2*lp[1],min=2) 
    985             sage: lp.show() 
    986             Maximization: 
    987             <BLANKLINE> 
     984
     985            sage: for each in xrange(10): lp.add_constraint(2*lp[0]-2*lp[1],min=2)
     986            sage: lp.show()
     987            Maximization:
     988            <BLANKLINE>
    988989            Constraints:
    989990              1.0 <= x_0 -x_1 
    990991            Variables: