Ticket #12736: trac_12736.patch

File trac_12736.patch, 16.0 KB (added by ncohen, 9 years ago)
  • sage/numerical/backends/glpk_backend.pyx

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1334084542 -7200
    # Node ID 9a266d3ccde8e05346193548461b3b85df9d43e8
    # Parent  3958172983d67a3a881b749265284c37748aa5c7
    More solver options for GLPK -- reviewer's patch
    
    diff --git a/sage/numerical/backends/glpk_backend.pyx b/sage/numerical/backends/glpk_backend.pyx
    a b  
    11191119        Write the problem to a .mps file
    11201120
    11211121        INPUT:
    1122        
     1122
    11231123        - ``filename`` (string)
    11241124
    11251125        EXAMPLE::
     
    11421142
    11431143            sage: from sage.numerical.backends.generic_backend import get_solver
    11441144            sage: p = MixedIntegerLinearProgram(solver = "GLPK")
    1145             sage: b = p.new_variable()                         
    1146             sage: p.add_constraint(b[1] + b[2] <= 6)           
    1147             sage: p.set_objective(b[1] + b[2])                 
    1148             sage: copy(p).solve()                             
     1145            sage: b = p.new_variable()
     1146            sage: p.add_constraint(b[1] + b[2] <= 6)
     1147            sage: p.set_objective(b[1] + b[2])
     1148            sage: copy(p).solve()
    11491149            6.0
    11501150        """
    11511151        cdef GLPKBackend p = GLPKBackend(maximization = (1 if self.is_maximization() else -1))
     
    11661166        - ``value`` -- the parameter's value if it is to be defined,
    11671167          or ``None`` (default) to obtain its current value.
    11681168
    1169         You can supply the name of a parameter and its value using either a string
    1170         or a ``glp_`` constant.
    1171         In most cases, you can use the same name for a paramter as that given
     1169        You can supply the name of a parameter and its value using either a
     1170        string or a ``glp_`` constant (which are defined as Cython variables of
     1171        this module).
     1172
     1173        In most cases, you can use the same name for a parameter as that given
    11721174        in the GLPK documentation, which is available by downloading GLPK from
    11731175        <http://www.gnu.org/software/glpk/>. The exceptions relate to parameters
    1174         common to both methods; these require you to append ``_simplex`` or ``_intopt``
    1175         to the name to resolve ambiguity, since the interface allows access to both.
     1176        common to both methods; these require you to append ``_simplex`` or
     1177        ``_intopt`` to the name to resolve ambiguity, since the interface allows
     1178        access to both.
    11761179
    11771180        We have also provided more meaningful names, to assist readability.
    11781181
     
    11871190
    11881191        Naturally, you can use ``True`` and ``False`` in cases where ``glp_on`` and ``glp_off``
    11891192        would be used.
    1190        
    1191         A list of parameter names, with their values:
    11921193
    1193         - ``timelimit`` -- specify the time limit IN SECONDS.
    1194           This affects both simplex and intopt.
     1194        A list of parameter names, with their possible values:
    11951195
    1196         - ``timelimit_simplex`` and ``timelimit_intopt`` -- specify the time limit
    1197           IN MILLISECONDS. (This is glpk's default.)
     1196        **General-purpose parameters:**
    11981197
    1199         - ``simplex_or_intopt`` -- whether to use the ``simplex`` or ``intopt``
    1200           routines in GLPK. This is controlled by using ``glp_simplex_only``,
    1201           ``glp_intopt_only``, and ``glp_simplex_then_intopt``. The latter is
    1202           useful to deal with a problem in GLPK where problems with no solution
    1203           hang when using integer optimization; if you specify
    1204           ``glp_simplex_then_intopt``, sage will try simplex first,
    1205           then perform integer optimization only if a solution of the LP
    1206           relaxation exists.
     1198        .. list-table::
     1199         :widths: 30 70
    12071200
    1208         - ``verbosity_intopt`` and ``verbosity_simplex`` -- one of ``GLP_MSG_OFF``,
    1209           ``GLP_MSG_ERR``, ``GLP_MSG_ON``, or ``GLP_MSG_ALL``. The default in sage
    1210           is ``GLP_MSG_OFF``.
     1201         * - ``timelimit``
    12111202
    1212         - ``output_frequency_intopt`` and ``output_frequency_simplex`` --
    1213           the output frequency, in milliseconds. Default is 5000.
     1203           - specify the time limit IN SECONDS.  This affects both simplex
     1204             and intopt.
    12141205
    1215         - ``output_delay_intopt`` and ``output_delay_simplex`` --
    1216           the output delay, in milliseconds, regarding the use of the simplex
    1217           method on the LP relaxation. Default is 10000.
     1206         * - ``timelimit_simplex`` and ``timelimit_intopt``
    12181207
    1219         - ``intopt``-specific parameters:
     1208           - specify the time limit IN MILLISECONDS. (This is glpk's
     1209             default.)
    12201210
    1221           - ``branching`` -- one of:
    1222             - ``GLP_BR_FFV`` -- first fractional variable
    1223             - ``GLP_BR_LFV`` -- last fractional variable
    1224             - ``GLP_BR_MFV`` -- most fractional variable
    1225             - ``GLP_BR_DTH`` -- Driebeck-Tomlin heuristic (default)
    1226             - ``GLP_BR_PCH`` -- hybrid pseudocost heuristic
     1211         * - ``simplex_or_intopt``
    12271212
    1228           - ``backtracking`` -- one of:
    1229             - ``GLP_BT_DFS`` -- depth first search
    1230             - ``GLP_BT_BFS`` -- breadth first search
    1231             - ``GLP_BT_BLB`` -- best local bound (default)
    1232             - ``GLP_BT_BPH`` -- best projection heuristic
     1213           - whether to use the ``simplex`` or ``intopt`` routines in
     1214             GLPK. This is controlled by using ``glp_simplex_only``,
     1215             ``glp_intopt_only``, and ``glp_simplex_then_intopt``. The latter
     1216             is useful to deal with a problem in GLPK where problems with no
     1217             solution hang when using integer optimization; if you specify
     1218             ``glp_simplex_then_intopt``, sage will try simplex first, then
     1219             perform integer optimization only if a solution of the LP
     1220             relaxation exists.
    12331221
    1234           - ``preprocessing`` -- one of:
    1235             - ``GLP_PP_NONE``
    1236             - ``GLP_PP_ROOT`` -- preprocessing only at root level
    1237             - ``GLP_PP_ALL`` (default)
     1222         * - ``verbosity_intopt`` and ``verbosity_simplex``
    12381223
    1239           - ``feasibility_pump`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default)
     1224           - one of ``GLP_MSG_OFF``, ``GLP_MSG_ERR``, ``GLP_MSG_ON``, or
     1225             ``GLP_MSG_ALL``. The default is ``GLP_MSG_OFF``.
    12401226
    1241           - ``gomory_cuts`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default)
     1227         * - ``output_frequency_intopt`` and ``output_frequency_simplex``
    12421228
    1243           - ``mixed_int_rounding_cuts`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default)
     1229           - the output frequency, in milliseconds. Default is 5000.
    12441230
    1245           - ``mixed_cover_cuts`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default)
     1231         * - ``output_delay_intopt`` and ``output_delay_simplex``
    12461232
    1247           - ``clique_cuts`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default)
     1233           - the output delay, in milliseconds, regarding the use of the
     1234             simplex method on the LP relaxation. Default is 10000.
    12481235
    1249           - ``absolute_tolerance`` -- (double) used to check if optimal solution to LP relaxation
    1250             is integer feasible. GLPK manual advises, "do not change... without detailed
    1251             understanding of its purpose."
    12521236
    1253           - ``relative_tolerance`` -- (double) used to check if objective value in LP relaxation
    1254             is not better than best known integer solution. GLPK manual advises, "do not
    1255             change... without detailed understanding of its purpose."
     1237        **intopt-specific parameters:**
    12561238
    1257           - ``mip_gap_tolerance`` -- (double) relative mip gap tolerance. Default is 0.0.
     1239        .. list-table::
     1240         :widths: 30 70
    12581241
    1259           - ``presolve_intopt`` -- one of ``GLP_ON`` (default in sage) or ``GLP_OFF``.
     1242         * - ``branching``
     1243           - - ``GLP_BR_FFV``  first fractional variable
     1244             - ``GLP_BR_LFV``  last fractional variable
     1245             - ``GLP_BR_MFV``  most fractional variable
     1246             - ``GLP_BR_DTH``  Driebeck-Tomlin heuristic (default)
     1247             - ``GLP_BR_PCH``  hybrid pseudocost heuristic
    12601248
    1261           - ``binarize`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default)
     1249         * - ``backtracking``
     1250           - - ``GLP_BT_DFS``  depth first search
     1251             - ``GLP_BT_BFS``  breadth first search
     1252             - ``GLP_BT_BLB``  best local bound (default)
     1253             - ``GLP_BT_BPH``  best projection heuristic
    12621254
    1263         - ``simplex``-specific parameters:
     1255         * - ``preprocessing``
     1256           - - ``GLP_PP_NONE``
     1257             - ``GLP_PP_ROOT``  preprocessing only at root level
     1258             - ``GLP_PP_ALL``   (default)
    12641259
    1265           - ``primal_v_dual`` -- one of ``GLP_PRIMAL`` (default), ``GLP_DUAL``, or
    1266             ``GLP_DUALP``.
    12671260
    1268           - ``pricing`` -- one of:
    1269             - ``GLP_PT_STD`` -- standard (textbook)
    1270             - ``GLP_PT_PSE`` -- projected steepest edge (default)
     1261         * - ``feasibility_pump``
    12711262
    1272           - ``ratio_test`` -- one of:
    1273             - ``GLP_RT_STD`` -- standard (textbook)
    1274             - ``GLP_RT_HAR`` -- Harris' two-pass ratio test (default)
     1263           - ``GLP_ON`` or ``GLP_OFF`` (default)
    12751264
    1276           - ``tolerance_primal`` -- (double) tolerance used to check if basic solution
    1277             is primal feasible. GLPK manual advises, "do not
    1278             change... without detailed understanding of its purpose."
     1265         * - ``gomory_cuts``
    12791266
    1280           - ``tolerance_dual`` -- (double) tolerance used to check if basic solution
    1281             is dual feasible. GLPK manual advises, "do not
    1282             change... without detailed understanding of its purpose."
     1267           - ``GLP_ON`` or ``GLP_OFF`` (default)
    12831268
    1284           - ``tolerance_pivot`` -- (double) tolerance used to choose pivot. GLPK manual advises, "do not
    1285             change... without detailed understanding of its purpose."
     1269         * - ``mixed_int_rounding_cuts``
    12861270
    1287           - ``obj_lower_limit`` -- (double) lower limit of the objective function.
    1288             The default is ``-DBL_MAX``.
     1271           - ``GLP_ON`` or ``GLP_OFF`` (default)
    12891272
    1290           - ``obj_upper_limit`` -- (double) upper limit of the objective function.
    1291             The default is ``DBL_MAX``.
     1273         * - ``mixed_cover_cuts``
    12921274
    1293           - ``iteration_limit`` -- (int) iteration limit of the simplex algorithn.
    1294             The default is ``INT_MAX``.
     1275           - ``GLP_ON`` or ``GLP_OFF`` (default)
    12951276
    1296           - ``presolve_simplex`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default).
     1277         * - ``clique_cuts``
     1278
     1279           - ``GLP_ON`` or ``GLP_OFF`` (default)
     1280
     1281         * - ``absolute_tolerance``
     1282
     1283           - (double) used to check if optimal solution to LP relaxation is
     1284             integer feasible. GLPK manual advises, "do not change... without
     1285             detailed understanding of its purpose."
     1286
     1287         * - ``relative_tolerance``
     1288
     1289           - (double) used to check if objective value in LP relaxation is not
     1290             better than best known integer solution. GLPK manual advises, "do
     1291             not change... without detailed understanding of its purpose."
     1292
     1293         * - ``mip_gap_tolerance``
     1294
     1295           - (double) relative mip gap tolerance. Default is 0.0.
     1296
     1297         * - ``presolve_intopt``
     1298
     1299           - ``GLP_ON`` (default) or ``GLP_OFF``.
     1300
     1301         * - ``binarize``
     1302
     1303           - ``GLP_ON`` or ``GLP_OFF`` (default)
     1304
     1305
     1306        **simplex-specific parameters:**
     1307
     1308        .. list-table::
     1309         :widths: 30 70
     1310
     1311         * - ``primal_v_dual``
     1312
     1313           - - ``GLP_PRIMAL``  (default)
     1314             - ``GLP_DUAL``
     1315             - ``GLP_DUALP``
     1316
     1317         * - ``pricing``
     1318
     1319           - - ``GLP_PT_STD``    standard (textbook)
     1320             - ``GLP_PT_PSE``    projected steepest edge (default)
     1321
     1322         * - ``ratio_test``
     1323
     1324           - - ``GLP_RT_STD``  standard (textbook)
     1325             - ``GLP_RT_HAR``  Harris' two-pass ratio test (default)
     1326
     1327         * - ``tolerance_primal``
     1328
     1329           - (double) tolerance used to check if basic solution is primal
     1330             feasible. GLPK manual advises, "do not change... without
     1331             detailed understanding of its purpose."
     1332
     1333         * - ``tolerance_dual``
     1334
     1335           - (double) tolerance used to check if basic solution is dual
     1336             feasible. GLPK manual advises, "do not change... without
     1337             detailed understanding of its purpose."
     1338
     1339         * - ``tolerance_pivot``
     1340
     1341           - (double) tolerance used to choose pivot. GLPK manual advises,
     1342             "do not change... without detailed understanding of its
     1343             purpose."
     1344
     1345         * - ``obj_lower_limit``
     1346
     1347           - (double) lower limit of the objective function.  The default is
     1348             ``-DBL_MAX``.
     1349
     1350         * - ``obj_upper_limit``
     1351
     1352           - (double) upper limit of the objective function.  The default is
     1353             ``DBL_MAX``.
     1354
     1355         * - ``iteration_limit``
     1356
     1357           - (int) iteration limit of the simplex algorithn.  The default is
     1358             ``INT_MAX``.
     1359
     1360         * - ``presolve_simplex``
     1361
     1362           - ``GLP_ON`` or ``GLP_OFF`` (default).
    12971363
    12981364        .. NOTE::
    12991365
     
    13061372
    13071373            sage: from sage.numerical.backends.generic_backend import get_solver
    13081374            sage: p = get_solver(solver = "GLPK")
    1309             sage: p.solver_parameter("timelimit", 60)             
    1310             sage: p.solver_parameter("timelimit")                 
     1375            sage: p.solver_parameter("timelimit", 60)
     1376            sage: p.solver_parameter("timelimit")
    13111377            60.0
    13121378
    1313         Don't forget the difference between ``timelimit`` and ``timelimit_intopt``.
     1379        - Don't forget the difference between ``timelimit`` and ``timelimit_intopt``
    13141380
    1315         ..::
     1381        ::
    13161382
    13171383            sage: p.solver_parameter("timelimit_intopt")
    13181384            60000
    13191385
    1320         If you don't care for an integer answer, you can ask for an lp relaxation instead.
    1321         The default solver performs integer optimization, but
    1322         you can switch to the standard simplex algorithm.
     1386        If you don't care for an integer answer, you can ask for an lp
     1387        relaxation instead.  The default solver performs integer optimization,
     1388        but you can switch to the standard simplex algorithm through the
     1389        ``glp_simplex_or_intopt`` parameter.
    13231390
    13241391        EXAMPLE::
    13251392
     
    13401407            2.0
    13411408            sage: lp.get_values([x,y])
    13421409            [1.5, 0.5]
    1343        
     1410
    13441411        You can get glpk to spout all sorts of information at you.
    1345         The default is to turn this off, but sometimes (debugging) it's very useful.
    1346        
    1347         .. link
    1348 
    1349         ::
     1412        The default is to turn this off, but sometimes (debugging) it's very useful::
    13501413
    13511414            sage: lp.solver_parameter(backend.glp_simplex_or_intopt, backend.glp_simplex_then_intopt)
    13521415            sage: lp.solver_parameter(backend.glp_mir_cuts, backend.glp_on)
     
    13801443
    13811444        elif name == simplex_or_intopt:
    13821445            if value == None: return self.simplex_or_intopt
    1383             if not value in (simplex_only,intopt_only,simplex_then_intopt): raise MIPSolverException, "GLPK: invalid value for simplex_or_intopt; see documentation"
     1446            if not value in (simplex_only,intopt_only,simplex_then_intopt):
     1447                raise MIPSolverException, "GLPK: invalid value for simplex_or_intopt; see documentation"
    13841448            self.simplex_or_intopt = value
    13851449
    13861450        elif name == msg_lev_simplex:
  • sage/numerical/mip.pyx

    diff --git a/sage/numerical/mip.pyx b/sage/numerical/mip.pyx
    a b  
    14781478
    14791479        Solver-specific parameters:
    14801480
    1481             - GLPK : We have implemented very close to comprehensive coverage
    1482               of the GLPK solver parameters for the simplex and integer optimization
    1483               methods. For details, see the documentation in
    1484               :meth:`sage.numerical.backends.glpk_backend`.
     1481            - GLPK : We have implemented very close to comprehensive coverage of
     1482              the GLPK solver parameters for the simplex and integer
     1483              optimization methods. For details, see the documentation of
     1484              :meth:`GLPKBackend.solver_parameter
     1485              <sage.numerical.backends.glpk_backend.GLPKBackend.solver_parameter>`.
    14851486
    14861487            - CPLEX's parameters are identified by a string. Their
    14871488              list is available `on ILOG's website