Ticket #12736: trac_12736_more_solver_options_for_glpk.patch

File trac_12736_more_solver_options_for_glpk.patch, 32.4 KB (added by john_perry, 9 years ago)
  • sage/numerical/backends/glpk_backend.pxd

    # HG changeset patch
    # User John Perry <john.perry@usm.edu>
    # Date 1332793439 18000
    # Node ID ffb095194f3be09a38e6e7899061c4164839ecf7
    # Parent  72bba20bc1e88b49a1b59f0467133a5e435ae112
    parameters for glpk solver
    
    diff --git a/sage/numerical/backends/glpk_backend.pxd b/sage/numerical/backends/glpk_backend.pxd
    a b  
    2020     ctypedef struct c_glp_prob "glp_prob":
    2121         pass
    2222     ctypedef struct c_glp_iocp "glp_iocp":
     23         int msg_lev
     24         int br_tech
     25         int bt_tech
     26         int pp_tech
     27         int fp_heur
     28         int gmi_cuts
     29         int mir_cuts
     30         int cov_cuts
     31         int clq_cuts
     32         double tol_int
     33         double tol_obj
     34         double mip_gap
     35         int tm_lim
     36         int out_frq
     37         int out_dly
    2338         int presolve
    24          int msg_lev
    25          int gmi_cuts
    26          int fp_heur
    27          int mir_cuts
    28          int tm_lim
     39         int binarize
    2940     ctypedef struct c_glp_smcp "glp_smcp":
    3041         int msg_lev
    3142         int meth
     
    4152         int out_frq
    4253         int out_dly
    4354         int presolve
    44          double foo_bar[36]
    4555     c_glp_iocp * new_c_glp_iocp "new glp_iocp" ()
    4656     #void del_c_glp_iocp "del glp_iocp" ()
    4757     void glp_init_iocp(c_glp_iocp *)
     
    105115     int glp_get_obj_dir(c_glp_prob *lp)
    106116     void glp_copy_prob(c_glp_prob *dst, c_glp_prob *src, int names)
    107117
     118     # constants
    108119
     120     # constants for smcp control
     121
     122     int GLP_MSG_OFF
     123     int GLP_MSG_ERR
     124     int GLP_MSG_ON
     125     int GLP_MSG_ALL
     126
     127     int GLP_PRIMAL
     128     int GLP_DUALP
     129     int GLP_DUAL
     130
     131     int GLP_PT_STD
     132     int GLP_PT_PSE
     133
     134     int GLP_RT_STD
     135     int GLP_RT_HAR
     136
     137     double DBL_MAX
     138
     139     int INT_MAX
    109140
    110141     int GLP_ON
     142     int GLP_OFF
     143
     144     # constants for iocp control, not already in simplex
     145
     146     int GLP_BR_FFV
     147     int GLP_BR_LFV
     148     int GLP_BR_MFV
     149     int GLP_BR_DTH
     150     int GLP_BR_PCH
     151
     152     int GLP_BT_DFS
     153     int GLP_BT_BFS
     154     int GLP_BT_BLB
     155     int GLP_BT_BPH
     156
     157     int GLP_PP_NONE
     158     int GLP_PP_ROOT
     159     int GLP_PP_ALL
     160
     161     # error codes
     162     int GLP_EBADB
     163     int GLP_ESING
     164     int GLP_ECOND
     165     int GLP_EBOUND
     166     int GLP_EFAIL
     167     int GLP_EOBJLL
     168     int GLP_EOBJUL
     169     int GLP_EITLIM
     170     int GLP_ETMLIM
     171     int GLP_EOPFS
     172     int GLP_EODFS
     173
     174     int GLP_UNDEF
     175     int GLP_OPT
     176     int GLP_FEAS
     177     int GLP_NOFEAS
     178     int GLP_INFEAS
     179     int GLP_UNBND
     180
     181     # other constants
     182
    111183     int GLP_MAX
    112184     int GLP_MIN
    113185     int GLP_UP
     
    118190     int GLP_CV
    119191     int GLP_IV
    120192     int GLP_BV
    121      int GLP_MSG_OFF
    122      int GLP_MSG_ERR
    123      int GLP_MSG_ON
    124      int GLP_MSG_ALL
    125193     int GLP_MPS_DECK
    126194     int GLP_MPS_FILE
    127195
    128      int GLP_UNDEF
    129      int GLP_OPT
    130      int GLP_FEAS
    131      int GLP_NOFEAS
    132 
    133196     int GLP_MSG_DBG
    134      int GLP_PRIMAL
    135      int GLP_DUALP
    136      int GLP_DUAL
    137      int GLP_PT_STD
    138      int GLP_PT_PSE
    139      int GLP_RT_STD
    140      int GLP_RT_HAR
    141197
    142198cdef class GLPKBackend(GenericBackend):
    143199    cdef c_glp_prob * lp
    144200    cdef c_glp_iocp * iocp
    145201    cdef c_glp_smcp * smcp
    146     cdef int preprocessing
     202    cdef int simplex_or_intopt
    147203    cpdef GLPKBackend copy(self)
  • sage/numerical/backends/glpk_backend.pyx

    diff --git a/sage/numerical/backends/glpk_backend.pyx b/sage/numerical/backends/glpk_backend.pyx
    a b  
    55
    66- Nathann Cohen (2010-10): initial implementation
    77- John Perry (2012-01): glp_simplex preprocessing
     8- John Perry and Raniere Gaia Silva (2012-03): solver parameters
    89"""
    910
    1011##############################################################################
     
    2930            sage: p = MixedIntegerLinearProgram(solver="GLPK")
    3031        """
    3132        self.lp = glp_create_prob()
    32         self.preprocessing = 0
     33        self.simplex_or_intopt = glp_intopt_only
    3334        self.smcp = <c_glp_smcp* > sage_malloc(sizeof(c_glp_smcp))
    3435        glp_init_smcp(self.smcp)
    3536        self.iocp = <c_glp_iocp* > sage_malloc(sizeof(c_glp_iocp))
     
    696697            Traceback (most recent call last):
    697698            ...
    698699            RuntimeError: GLPK : Signal sent, try preprocessing option
    699             sage: lp.solver_parameter("preprocessing", True)
     700            sage: lp.solver_parameter("simplex_or_intopt", "simplex_then_intopt")
    700701            sage: lp.solve()
    701702            Traceback (most recent call last):
    702703            ...
    703704            MIPSolverException: 'GLPK : Simplex cannot find a feasible solution'
     705
     706        The user can ask sage to solve via ``simplex`` or ``intopt``.
     707        The default solver is ``intopt``, so we get integer solutions.
     708
     709            sage: lp = MixedIntegerLinearProgram(solver = 'GLPK', maximization = False)
     710            sage: x, y = lp[0], lp[1]
     711            sage: lp.add_constraint(-2*x + y <= 1)
     712            sage: lp.add_constraint(x - y <= 1)
     713            sage: lp.add_constraint(x + y >= 2)
     714            sage: lp.set_objective(x + y)
     715            sage: lp.set_integer(x)
     716            sage: lp.set_integer(y)
     717            sage: lp.solve()
     718            2.0
     719            sage: lp.get_values([x, y])
     720            [1.0, 1.0]
     721
     722        If we switch to ``simplex``, we get continuous solutions.
     723
     724            sage: lp.solver_parameter("simplex_or_intopt", "simplex_only") # use simplex only
     725            sage: lp.solve()
     726            2.0
     727            sage: lp.get_values([x, y])
     728            [1.5, 0.5]
    704729        """
    705730
    706731        cdef int status
    707         if self.preprocessing:
     732        if self.simplex_or_intopt == glp_simplex_only or self.simplex_or_intopt == glp_simplex_then_intopt:
    708733            status = glp_simplex(self.lp, self.smcp)
    709734            status = glp_get_prim_stat(self.lp)
    710735            if status == GLP_OPT or status == GLP_FEAS:
     
    712737            elif status == GLP_UNDEF or status == GLP_NOFEAS:
    713738                raise MIPSolverException("GLPK : Simplex cannot find a feasible solution")
    714739
    715         sig_str('GLPK : Signal sent, try preprocessing option')
    716         glp_intopt(self.lp, self.iocp)
    717         sig_off()
     740        if self.simplex_or_intopt != glp_simplex_only:
     741          sig_str('GLPK : Signal sent, try preprocessing option')
     742          status = glp_intopt(self.lp, self.iocp)
     743          sig_off()
     744          # this is necessary to catch errors when certain options are enabled, e.g. tm_lim
     745          if status == GLP_ETMLIM: raise MIPSolverException("GLPK : The time limit was reached")
     746          elif status == GLP_EITLIM: raise MIPSolverException("GLPK : The iteration limit was reached")
    718747
    719         status = glp_mip_status(self.lp)
    720         if status == GLP_OPT:
    721             pass
    722         elif status == GLP_UNDEF:
    723             raise MIPSolverException("GLPK : Solution is undefined")
    724         elif status == GLP_FEAS:
    725             raise MIPSolverException("GLPK : Feasible solution found, while optimality has not been proven")
    726         elif status == GLP_NOFEAS:
    727             raise MIPSolverException("GLPK : There is no feasible integer solution to this Linear Program")
     748          status = glp_mip_status(self.lp)
     749          if status == GLP_OPT:
     750              pass
     751          elif status == GLP_UNDEF:
     752              raise MIPSolverException("GLPK : Solution is undefined")
     753          elif status == GLP_FEAS:
     754              raise MIPSolverException("GLPK : Feasible solution found, while optimality has not been proven")
     755          elif status == GLP_INFEAS:
     756              raise MIPSolverException("GLPK : Solution is infeasible")
     757          elif status == GLP_UNBND:
     758              raise MIPSolverException("GLPK : Problem has unbounded solution")
     759          elif status == GLP_NOFEAS:
     760              raise MIPSolverException("GLPK : There is no feasible integer solution to this Linear Program")
    728761
    729762        return 0
    730763
     
    753786            sage: p.get_variable_value(1)
    754787            1.5
    755788        """
    756         return glp_mip_obj_val(self.lp)
     789        if self.simplex_or_intopt != glp_simplex_only:
     790          return glp_mip_obj_val(self.lp)
     791        else:
     792          return glp_get_obj_val(self.lp)
    757793
    758794    cpdef double get_variable_value(self, int variable):
    759795        """
     
    779815            0.0
    780816            sage: p.get_variable_value(1)
    781817            1.5
    782         """   
    783         return glp_mip_col_val(self.lp, variable+1)
     818        """
     819        if self.simplex_or_intopt != glp_simplex_only:
     820          return glp_mip_col_val(self.lp, variable+1)
     821        else:
     822          return glp_get_col_prim(self.lp, variable+1)
    784823
    785824    cpdef int ncols(self):
    786825        """
     
    11151154            6.0
    11161155        """
    11171156        cdef GLPKBackend p = GLPKBackend(maximization = (1 if self.is_maximization() else -1))
    1118         p.preprocessing = self.preprocessing
     1157        p.simplex_or_intopt = self.simplex_or_intopt
    11191158        p.iocp.tm_lim = self.iocp.tm_lim
    11201159        glp_copy_prob(p.lp, self.lp, 1)
    11211160        return p
     
    11321171        - ``value`` -- the parameter's value if it is to be defined,
    11331172          or ``None`` (default) to obtain its current value.
    11341173
     1174        You can supply the name of a parameter and its value using either a string
     1175        or a ``glp_`` constant.
     1176        In most cases, you can use the same name for a paramter as that given
     1177        in the GLPK documentation, which is available by downloading GLPK from
     1178        <http://www.gnu.org/software/glpk/>. The exceptions relate to parameters
     1179        common to both methods; these require you to append ``_simplex`` or ``_intopt``
     1180        to the name to resolve ambiguity, since the interface allows access to both.
     1181
     1182        We have also provided more meaningful names, to assist readability.
     1183
     1184        Parameter **names** are specified in lower case.
     1185        To use a constant instead of a string, prepend ``glp_`` to the name.
     1186        For example, both ``glp_gmi_cuts`` or ``"gmi_cuts"`` control whether
     1187        to solve using Gomory cuts.
     1188
     1189        Parameter **values** are specificed as strings in upper case,
     1190        or as constants in lower case. For example, both ``glp_on`` and ``"GLP_ON"``
     1191        specify the same thing.
     1192
     1193        Naturally, you can use ``True`` and ``False`` in cases where ``glp_on`` and ``glp_off``
     1194        would be used.
     1195       
     1196        A list of parameter names, with their values:
     1197
     1198        - ``timelimit`` -- specify the time limit IN SECONDS.
     1199          This affects both simplex and intopt.
     1200
     1201        - ``timelimit_simplex`` and ``timelimit_intopt`` -- specify the time limit
     1202          IN MILLISECONDS. (This is glpk's default.)
     1203
     1204        - ``simplex_or_intopt`` -- whether to use the ``simplex`` or ``intopt``
     1205          routines in GLPK. This is controlled by using ``glp_simplex_only``,
     1206          ``glp_intopt_only``, and ``glp_simplex_then_intopt``. The latter is
     1207          useful to deal with a problem in GLPK where problems with no solution
     1208          hang when using integer optimization; if you specify
     1209          ``glp_simplex_then_intopt``, sage will try simplex first,
     1210          then perform integer optimization only if a solution of the LP
     1211          relaxation exists.
     1212
     1213        - ``verbosity_intopt`` and ``verbosity_simplex`` -- one of ``GLP_MSG_OFF``,
     1214          ``GLP_MSG_ERR``, ``GLP_MSG_ON``, or ``GLP_MSG_ALL``. The default in sage
     1215          is ``GLP_MSG_OFF``.
     1216
     1217        - ``output_frequency_intopt`` and ``output_frequency_simplex`` --
     1218          the output frequency, in milliseconds. Default is 5000.
     1219
     1220        - ``output_delay_intopt`` and ``output_delay_simplex`` --
     1221          the output delay, in milliseconds, regarding the use of the simplex
     1222          method on the LP relaxation. Default is 10000.
     1223
     1224        - ``intopt``-specific parameters:
     1225
     1226          - ``branching`` -- one of:
     1227            - ``GLP_BR_FFV`` -- first fractional variable
     1228            - ``GLP_BR_LFV`` -- last fractional variable
     1229            - ``GLP_BR_MFV`` -- most fractional variable
     1230            - ``GLP_BR_DTH`` -- Driebeck-Tomlin heuristic (default)
     1231            - ``GLP_BR_PCH`` -- hybrid pseudocost heuristic
     1232
     1233          - ``backtracking`` -- one of:
     1234            - ``GLP_BT_DFS`` -- depth first search
     1235            - ``GLP_BT_BFS`` -- breadth first search
     1236            - ``GLP_BT_BLB`` -- best local bound (default)
     1237            - ``GLP_BT_BPH`` -- best projection heuristic
     1238
     1239          - ``preprocessing`` -- one of:
     1240            - ``GLP_PP_NONE``
     1241            - ``GLP_PP_ROOT`` -- preprocessing only at root level
     1242            - ``GLP_PP_ALL`` (default)
     1243
     1244          - ``feasibility_pump`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default)
     1245
     1246          - ``gomory_cuts`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default)
     1247
     1248          - ``mixed_int_rounding_cuts`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default)
     1249
     1250          - ``mixed_cover_cuts`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default)
     1251
     1252          - ``clique_cuts`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default)
     1253
     1254          - ``absolute_tolerance`` -- (double) used to check if optimal solution to LP relaxation
     1255            is integer feasible. GLPK manual advises, "do not change... without detailed
     1256            understanding of its purpose."
     1257
     1258          - ``relative_tolerance`` -- (double) used to check if objective value in LP relaxation
     1259            is not better than best known integer solution. GLPK manual advises, "do not
     1260            change... without detailed understanding of its purpose."
     1261
     1262          - ``mip_gap_tolerance`` -- (double) relative mip gap tolerance. Default is 0.0.
     1263
     1264          - ``presolve_intopt`` -- one of ``GLP_ON`` (default in sage) or ``GLP_OFF``.
     1265
     1266          - ``binarize`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default)
     1267
     1268        - ``simplex``-specific parameters:
     1269
     1270          - ``primal_v_dual`` -- one of ``GLP_PRIMAL`` (default), ``GLP_DUAL``, or
     1271            ``GLP_DUALP``.
     1272
     1273          - ``pricing`` -- one of:
     1274            - ``GLP_PT_STD`` -- standard (textbook)
     1275            - ``GLP_PT_PSE`` -- projected steepest edge (default)
     1276
     1277          - ``ratio_test`` -- one of:
     1278            - ``GLP_RT_STD`` -- standard (textbook)
     1279            - ``GLP_RT_HAR`` -- Harris' two-pass ratio test (default)
     1280
     1281          - ``tolerance_primal`` -- (double) tolerance used to check if basic solution
     1282            is primal feasible. GLPK manual advises, "do not
     1283            change... without detailed understanding of its purpose."
     1284
     1285          - ``tolerance_dual`` -- (double) tolerance used to check if basic solution
     1286            is dual feasible. GLPK manual advises, "do not
     1287            change... without detailed understanding of its purpose."
     1288
     1289          - ``tolerance_pivot`` -- (double) tolerance used to choose pivot. GLPK manual advises, "do not
     1290            change... without detailed understanding of its purpose."
     1291
     1292          - ``obj_lower_limit`` -- (double) lower limit of the objective function.
     1293            The default is ``-DBL_MAX``.
     1294
     1295          - ``obj_upper_limit`` -- (double) upper limit of the objective function.
     1296            The default is ``DBL_MAX``.
     1297
     1298          - ``iteration_limit`` -- (int) iteration limit of the simplex algorithn.
     1299            The default is ``INT_MAX``.
     1300
     1301          - ``presolve_simplex`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default).
     1302
    11351303        .. NOTE::
    11361304
    1137            The list of available parameters is available at
    1138            :meth:`sage.numerical.mip.MixedIntegerlinearProgram.solver_parameter`
     1305            The coverage for GLPK's control parameters for simplex and integer optimization
     1306            is nearly complete. The only thing lacking is a wrapper for callback routines.
     1307
     1308            To date, no attempt has been made to expose the interior point methods.
    11391309
    11401310        EXAMPLE::
    11411311
     
    11441314            sage: p.solver_parameter("timelimit", 60)             
    11451315            sage: p.solver_parameter("timelimit")                 
    11461316            60.0
     1317
     1318        Don't forget the difference between ``timelimit`` and ``timelimit_intopt``.
     1319
     1320        ..::
     1321
     1322            sage: p.solver_parameter("timelimit_intopt")
     1323            60000
     1324
     1325        If you don't care for an integer answer, you can ask for an lp relaxation instead.
     1326        The default solver performs integer optimization, but
     1327        you can switch to the standard simplex algorithm.
     1328
     1329        EXAMPLE::
     1330
     1331            sage: lp = MixedIntegerLinearProgram(solver = 'GLPK', maximization = False)
     1332            sage: x, y = lp[0], lp[1]
     1333            sage: lp.add_constraint(-2*x + y <= 1)
     1334            sage: lp.add_constraint(x - y <= 1)
     1335            sage: lp.add_constraint(x + y >= 2)
     1336            sage: lp.set_integer(x); lp.set_integer(y)
     1337            sage: lp.set_objective(x + y)
     1338            sage: lp.solve()
     1339            2.0
     1340            sage: lp.get_values([x,y])
     1341            [1.0, 1.0]
     1342            sage: import sage.numerical.backends.glpk_backend as backend
     1343            sage: lp.solver_parameter(backend.glp_simplex_or_intopt, backend.glp_simplex_only)
     1344            sage: lp.solve()
     1345            2.0
     1346            sage: lp.get_values([x,y])
     1347            [1.5, 0.5]
     1348       
     1349        You can get glpk to spout all sorts of information at you.
     1350        The default is to turn this off, but sometimes (debugging) it's very useful.
     1351       
     1352        .. link
     1353
     1354        ::
     1355
     1356            sage: lp.solver_parameter(backend.glp_simplex_or_intopt, backend.glp_simplex_then_intopt)
     1357            sage: lp.solver_parameter(backend.glp_mir_cuts, backend.glp_on)
     1358            sage: lp.solver_parameter(backend.glp_msg_lev_intopt, backend.glp_msg_all)
     1359            sage: lp.solver_parameter(backend.glp_mir_cuts)
     1360            1
     1361
     1362        If you actually try to solve ``lp``, you will get a lot of detailed information.
    11471363        """
    1148         if name == "timelimit":
    1149             if value == None:
    1150                 return self.iocp.tm_lim/1000.0
     1364
     1365        if type(name) == str:
     1366          if name == "out_frq" or name == "out_dly" or name == "tm_lim" or name == "msg_lev":
     1367            raise ValueError("To set parameter " + name + " you must specify the solver. Append either _simplex or _intopt.")
     1368          name = solver_parameter_names_dict[name]
     1369
     1370        if type(value) == str: value = solver_parameter_values[value]
     1371
     1372        if name == timelimit_intopt:
     1373            if value == None: return self.iocp.tm_lim
     1374            else: self.iocp.tm_lim = value
     1375
     1376        if name == timelimit_seconds:
     1377            if value == None: return self.iocp.tm_lim / 1000.0
    11511378            else:
    1152                 self.iocp.tm_lim = 1000 * value
     1379                self.iocp.tm_lim = value * 1000.0
     1380                self.smcp.tm_lim = value * 1000.0
    11531381
    1154         elif name == "preprocessing":
    1155             if value == None:
    1156                 return self.preprocessing
     1382        elif name == timelimit_simplex:
     1383            if value == None: return self.smcp.tm_lim
     1384            else: self.smcp.tm_lim = value
     1385
     1386        elif name == simplex_or_intopt:
     1387            if value == None: return self.simplex_or_intopt
     1388            if not value in (simplex_only,intopt_only,simplex_then_intopt): raise MIPSolverException, "GLPK: invalid value for simplex_or_intopt; see documentation"
     1389            self.simplex_or_intopt = value
     1390
     1391        elif name == msg_lev_simplex:
     1392            if value == None: return self.smcp.msg_lev
     1393            else: self.smcp.msg_lev = value
     1394
     1395        elif name == msg_lev_intopt:
     1396            if value == None: return self.iocp.msg_lev
     1397            else: self.iocp.msg_lev = value
     1398
     1399        elif name == br_tech:
     1400            if value == None: return self.iocp.br_tech
     1401            else: self.iocp.br_tech = value
     1402
     1403        elif name == bt_tech:
     1404            if value == None: return self.iocp.bt_tech
     1405            else: self.iocp.bt_tech = value
     1406
     1407        elif name == pp_tech:
     1408            if value == None: return self.iocp.pp_tech
     1409            else: self.iocp.pp_tech = value
     1410
     1411        elif name == fp_heur:
     1412            if value == None: return self.iocp.fp_heur
    11571413            else:
    1158                 if value == True: value = 1
    1159                 elif value == False: value = 0
    1160                 self.preprocessing = value
     1414              if value == True: value = GLP_ON
     1415              elif value == False: value = GLP_OFF
     1416              self.iocp.fp_heur = value
     1417
     1418        elif name == gmi_cuts:
     1419            if value == None: return self.iocp.gmi_cuts
     1420            else:
     1421              if value == True: value = GLP_ON
     1422              elif value == False: value = GLP_OFF
     1423              self.iocp.gmi_cuts = value
     1424
     1425        elif name == mir_cuts:
     1426            if value == None: return self.iocp.mir_cuts
     1427            else:
     1428              if value == True: value = GLP_ON
     1429              elif value == False: value = GLP_OFF
     1430              self.iocp.mir_cuts = value
     1431
     1432        elif name == cov_cuts:
     1433            if value == None: return self.iocp.cov_cuts
     1434            else:
     1435              if value == True: value = GLP_ON
     1436              elif value == False: value = GLP_OFF
     1437              self.iocp.cov_cuts = value
     1438
     1439        elif name == clq_cuts:
     1440            if value == None: return self.iocp.clq_cuts
     1441            else:
     1442              if value == True: value = GLP_ON
     1443              elif value == False: value = GLP_OFF
     1444              self.iocp.clq_cuts = value
     1445
     1446        elif name == tol_int:
     1447            if value == None: return self.iocp.tol_int
     1448            else: self.iocp.tol_int = value
     1449
     1450        elif name == tol_obj:
     1451            if value == None: return self.iocp.tol_obj
     1452            else: self.iocp.tol_obj = value
     1453
     1454        elif name == mip_gap:
     1455            if value == None: return self.iocp.mip_gap
     1456            else: self.iocp.mip_gap = value
     1457
     1458        elif name == tm_lim_intopt:
     1459            if value == None: return self.iocp.tm_lim
     1460            else: self.iocp.tm_lim = value
     1461
     1462        elif name == out_frq_intopt:
     1463            if value == None: return self.iocp.out_frq
     1464            else: self.iocp.out_frq = value
     1465
     1466        elif name == out_dly_intopt:
     1467            if value == None: return self.iocp.out_dly
     1468            else: self.iocp.out_dly = value
     1469
     1470        elif name == presolve_intopt:
     1471            if value == None: return self.iocp.presolve
     1472            else:
     1473                if value == True: value = GLP_ON
     1474                elif value == False: value = GLP_OFF
     1475                self.iocp.presolve = value
     1476
     1477        elif name == binarize:
     1478            if value == None: return self.iocp.binarize
     1479            else:
     1480              if value == True: value = GLP_ON
     1481              elif value == False: value = GLP_OFF
     1482              self.iocp.binarize = value
     1483
     1484        elif name == msg_lev_simplex:
     1485            if value == None: return self.smcp.msg_lev
     1486            else: self.smcp.msg_lev = value
     1487
     1488        elif name == meth:
     1489            if value == None: return self.smcp.meth
     1490            else: self.smcp.meth = value
     1491
     1492        elif name == pricing:
     1493            if value == None: return self.smcp.pricing
     1494            else: self.smcp.pricing = value
     1495
     1496        elif name == r_test:
     1497            if value == None: return self.smcp.r_test
     1498            else: self.smcp.r_test = value
     1499
     1500        elif name == tol_bnd:
     1501            if value == None: return self.smcp.tol_bnd
     1502            else: self.smcp.tol_bnd = value
     1503
     1504        elif name == tol_dj:
     1505            if value == None: return self.smcp.tol_dj
     1506            else: self.smcp.tol_dj = value
     1507
     1508        elif name == tol_piv:
     1509            if value == None: return self.smcp.tol_piv
     1510            else: self.smcp.tol_piv = value
     1511
     1512        elif name == obj_ll:
     1513            if value == None: return self.smcp.obj_ll
     1514            else: self.smcp.obj_ll = value
     1515
     1516        elif name == obj_ul:
     1517            if value == None: return self.smcp.obj_ul
     1518            else: self.smcp.obj_ul = value
     1519
     1520        elif name == it_lim:
     1521            if value == None: return self.smcp.it_lim
     1522            else: self.smcp.it_lim = value
     1523
     1524        elif name == tm_lim_simplex:
     1525            if value == None: return self.smcp.tm_lim
     1526            else: self.smcp.tm_lim = value
     1527
     1528        elif name == out_frq_simplex:
     1529            if value == None: return self.smcp.out_frq
     1530            else: self.smcp.out_frq = value
     1531
     1532        elif name == out_dly_simplex:
     1533            if value == None: return self.smcp.out_dly
     1534            else: self.smcp.out_dly = value
     1535
     1536        elif name == presolve_simplex:
     1537            if value == None: return self.smcp.presolve
     1538            else:
     1539              if value == True: value = GLP_ON
     1540              elif value == False: value = GLP_OFF
     1541              self.smcp.presolve = value
    11611542
    11621543        else:
    11631544            raise ValueError("This parameter is not available.")
     
    11691550        glp_delete_prob(self.lp)
    11701551        sage_free(self.iocp)
    11711552        sage_free(self.smcp)
     1553
     1554# parameter names
     1555
     1556cdef enum solver_parameter_names:
     1557  timelimit_seconds, timelimit_simplex, timelimit_intopt, simplex_or_intopt, msg_lev_simplex,
     1558  msg_lev_intopt, br_tech, bt_tech, pp_tech, fp_heur, gmi_cuts,
     1559  mir_cuts, cov_cuts, clq_cuts, tol_int, tol_obj, mip_gap,
     1560  tm_lim_intopt, out_frq_intopt, out_dly_intopt, presolve_intopt,
     1561  binarize, meth, pricing, r_test, tol_bnd, tol_dj, tol_piv, obj_ll,
     1562  obj_ul, it_lim, tm_lim_simplex, out_frq_simplex, out_dly_simplex,
     1563  presolve_simplex
     1564
     1565glp_tm_lim_simplex = timelimit_simplex
     1566glp_tm_lim_intopt = timelimit_intopt
     1567glp_simplex_or_intopt = simplex_or_intopt
     1568glp_msg_lev_intopt = glp_verbosity_intopt = msg_lev_intopt
     1569glp_msg_lev_simplex = glp_verbosity_simplex = msg_lev_simplex
     1570glp_br_tech = glp_branching = br_tech
     1571glp_bt_tech = glp_backtracking = bt_tech
     1572glp_pp_tech = glp_preprocessing = pp_tech
     1573glp_fp_heur = glp_feasibility_pump = fp_heur
     1574glp_gmi_cuts = glp_gomory_cuts = gmi_cuts
     1575glp_mir_cuts = glp_mixed_int_rounding_cuts = mir_cuts
     1576glp_cov_cuts = glp_mixed_cover_cuts = cov_cuts
     1577glp_clq_cuts = glp_clique_cuts = clq_cuts
     1578glp_tol_int = glp_absolute_tolerance = tol_int
     1579glp_tol_obj = glp_relative_tolerance = tol_obj
     1580glp_mip_gap = glp_mip_gap_tolerance = mip_gap
     1581glp_out_frq_intopt = glp_output_frequency_intopt = out_frq_intopt
     1582glp_out_dly_intopt = glp_output_delay_intopt = out_dly_intopt
     1583glp_presolve_intopt = presolve_intopt
     1584glp_binarize = binarize
     1585glp_meth = glp_primal_v_dual = meth
     1586glp_pricing = pricing
     1587glp_r_test = glp_ratio_test = r_test
     1588glp_tol_bnd = glp_tolerance_primal = tol_bnd
     1589glp_tol_dj = glp_tolerance_dual = tol_dj
     1590glp_tol_piv = glp_tolerance_pivot = tol_piv
     1591glp_obj_ll = glp_obj_lower_limit = obj_ll
     1592glp_obj_ul = glp_obj_upper_limit = obj_ul
     1593glp_it_lim = glp_iteration_limit = it_lim
     1594glp_out_frq_simplex = glp_output_frequency_intopt = out_frq_simplex
     1595glp_out_dly_simplex = glp_output_delay_simplex = out_dly_simplex
     1596glp_presolve_simplex = presolve_simplex
     1597
     1598solver_parameter_names_dict = {
     1599  'timelimit': timelimit_seconds,
     1600  'timelimit_intopt': timelimit_intopt,
     1601  'tm_lim_intopt': timelimit_intopt,
     1602  'timelimit_simplex': timelimit_simplex,
     1603  'tm_lim_simplex': timelimit_simplex,
     1604  'simplex_or_intopt': simplex_or_intopt,
     1605  'msg_lev_simplex': msg_lev_simplex, 'verbosity_simplex': msg_lev_simplex,
     1606  'msg_lev_intopt': msg_lev_intopt, 'verbosity_intopt': msg_lev_intopt,
     1607  'br_tech': br_tech, 'branching': br_tech,
     1608  'bt_tech': bt_tech, 'backtracking': bt_tech,
     1609  'pp_tech': pp_tech, 'preprocessing': pp_tech,
     1610  'fp_heur': fp_heur, 'feasibility_pump': fp_heur,
     1611  'gmi_cuts': gmi_cuts, 'gomory_cuts': gmi_cuts,
     1612  'mir_cuts': mir_cuts, 'mixed_int_rounding_cuts': mir_cuts,
     1613  'cov_cuts': cov_cuts, 'mixed_cover_cuts': cov_cuts,
     1614  'clq_cuts': clq_cuts, 'clique_cuts': clq_cuts,
     1615  'tol_int': tol_int, 'absolute_tolerance': tol_int,
     1616  'tol_obj': tol_obj, 'relative_tolerance': tol_obj,
     1617  'mip_gap': mip_gap, 'mip_gap_tolerance': mip_gap,
     1618  'out_frq_intopt': out_frq_intopt, 'output_frequency_intopt': out_frq_intopt,
     1619  'out_dly_intopt': out_dly_intopt, 'output_delay_intopt': out_dly_intopt,
     1620  'presolve_intopt': presolve_intopt, 'binarize': binarize,
     1621  'meth': meth, 'primal_v_dual': meth,
     1622  'pricing': pricing,
     1623  'r_test': r_test, 'ratio_test': r_test,
     1624  'tol_bnd': tol_bnd, 'tolerance_primal': tol_bnd,
     1625  'tol_dj': tol_dj, 'tolerance_dual': tol_dj,
     1626  'tol_piv': tol_piv, 'tolerance_pivot': tol_piv,
     1627  'obj_ll': obj_ll, 'obj_lower_limit': obj_ll,
     1628  'obj_ul': obj_ul, 'obj_upper_limit': obj_ul,
     1629  'it_lim': it_lim, 'iteration_limit': it_lim,
     1630  'out_frq_simplex': out_frq_simplex, 'output_frequency_intopt': out_frq_simplex,
     1631  'out_dly_simplex': out_dly_simplex, 'output_delay_simplex': out_dly_simplex,
     1632  'presolve_simplex': presolve_simplex
     1633}
     1634
     1635# parameter values
     1636
     1637glp_msg_off = GLP_MSG_OFF
     1638glp_msg_on = GLP_MSG_ON
     1639glp_msg_err = GLP_MSG_ERR
     1640glp_msg_all = GLP_MSG_ALL
     1641glp_msg_dbg = GLP_MSG_DBG
     1642
     1643glp_primal = GLP_PRIMAL
     1644glp_dual = GLP_DUAL
     1645glp_dualp = GLP_DUALP
     1646
     1647glp_pt_std = GLP_PT_STD
     1648glp_pt_pse = GLP_PT_PSE
     1649
     1650glp_rt_std = GLP_RT_STD
     1651glp_rt_har = GLP_RT_HAR
     1652
     1653dbl_max = DBL_MAX
     1654int_max = INT_MAX
     1655
     1656glp_on = GLP_ON
     1657glp_off = GLP_OFF
     1658
     1659glp_br_ffv = GLP_BR_FFV
     1660glp_br_lfv = GLP_BR_LFV
     1661glp_br_mfv = GLP_BR_MFV
     1662glp_br_dth = GLP_BR_DTH
     1663glp_br_pch = GLP_BR_PCH
     1664
     1665glp_bt_dfs = GLP_BT_DFS
     1666glp_bt_bfs = GLP_BT_BFS
     1667glp_bt_blb = GLP_BT_BLB
     1668glp_bt_bph = GLP_BT_BPH
     1669
     1670glp_pp_none = GLP_PP_NONE
     1671glp_pp_root = GLP_PP_ROOT
     1672glp_pp_all = GLP_PP_ALL
     1673
     1674glp_max = GLP_MAX
     1675glp_min = GLP_MIN
     1676glp_up = GLP_UP
     1677glp_fr = GLP_FR
     1678glp_db = GLP_DB
     1679glp_fx = GLP_FX
     1680glp_lo = GLP_LO
     1681glp_cv = GLP_CV
     1682glp_iv = GLP_IV
     1683glp_bv = GLP_BV
     1684glp_mps_deck = GLP_MPS_DECK
     1685glp_mps_file = GLP_MPS_FILE
     1686
     1687glp_undef = GLP_UNDEF
     1688glp_opt = GLP_OPT
     1689glp_feas = GLP_FEAS
     1690glp_nofeas = GLP_NOFEAS
     1691
     1692cdef enum more_parameter_values:
     1693  simplex_only, simplex_then_intopt, intopt_only
     1694
     1695glp_simplex_only = simplex_only
     1696glp_simplex_then_intopt = simplex_then_intopt
     1697glp_intopt_only = intopt_only
     1698
     1699# dictionaries for those who prefer to use strings
     1700
     1701solver_parameter_values = {
     1702
     1703  'simplex_only': simplex_only,
     1704  'simplex_then_intopt': simplex_then_intopt,
     1705  'intopt_only': intopt_only,
     1706
     1707  'GLP_MSG_OFF' : GLP_MSG_OFF,
     1708  'GLP_MSG_ON' : GLP_MSG_ON,
     1709  'GLP_MSG_ERR' : GLP_MSG_ERR,
     1710  'GLP_MSG_ALL' : GLP_MSG_ALL,
     1711  'GLP_MSG_DBG' : GLP_MSG_DBG,
     1712
     1713  'GLP_PRIMAL' : GLP_PRIMAL,
     1714  'GLP_DUAL' : GLP_DUAL,
     1715  'GLP_DUALP' : GLP_DUALP,
     1716
     1717  'GLP_PT_STD' : GLP_PT_STD,
     1718  'GLP_PT_PSE' : GLP_PT_PSE,
     1719
     1720  'GLP_RT_STD' : GLP_RT_STD,
     1721  'GLP_RT_HAR' : GLP_RT_HAR,
     1722
     1723  'DBL_MAX' : DBL_MAX,
     1724  'INT_MAX' : INT_MAX,
     1725
     1726  'GLP_ON' : GLP_ON,
     1727  'GLP_OFF' : GLP_OFF,
     1728
     1729  'GLP_BR_FFV' : GLP_BR_FFV,
     1730  'GLP_BR_LFV' : GLP_BR_LFV,
     1731  'GLP_BR_MFV' : GLP_BR_MFV,
     1732  'GLP_BR_DTH' : GLP_BR_DTH,
     1733  'GLP_BR_PCH' : GLP_BR_PCH,
     1734
     1735  'GLP_BT_DFS' : GLP_BT_DFS,
     1736  'GLP_BT_BFS' : GLP_BT_BFS,
     1737  'GLP_BT_BLB' : GLP_BT_BLB,
     1738  'GLP_BT_BPH' : GLP_BT_BPH,
     1739
     1740  'GLP_PP_NONE' : GLP_PP_NONE,
     1741  'GLP_PP_ROOT' : GLP_PP_ROOT,
     1742  'GLP_PP_ALL' : GLP_PP_ALL,
     1743
     1744  'GLP_MAX' : GLP_MAX,
     1745  'GLP_MIN' : GLP_MIN,
     1746  'GLP_UP' : GLP_UP,
     1747  'GLP_FR' : GLP_FR,
     1748  'GLP_DB' : GLP_DB,
     1749  'GLP_FX' : GLP_FX,
     1750  'GLP_LO' : GLP_LO,
     1751  'GLP_CV' : GLP_CV,
     1752  'GLP_IV' : GLP_IV,
     1753  'GLP_BV' : GLP_BV,
     1754  'GLP_MPS_DECK' : GLP_MPS_DECK,
     1755  'GLP_MPS_FILE' : GLP_MPS_FILE,
     1756
     1757  'GLP_UNDEF' : GLP_UNDEF,
     1758  'GLP_OPT' : GLP_OPT,
     1759  'GLP_FEAS' : GLP_FEAS,
     1760  'GLP_NOFEAS' : GLP_NOFEAS
     1761
     1762}
  • sage/numerical/mip.pyx

    diff --git a/sage/numerical/mip.pyx b/sage/numerical/mip.pyx
    a b  
    12751275
    12761276        return self._backend.is_variable_continuous(self._variables[e])
    12771277
    1278     def solve(self, solver=None, log=0, objective_only=False):
     1278    def solve(self, solver=None, log=None, objective_only=False):
    12791279        r"""
    12801280        Solves the ``MixedIntegerLinearProgram``.
    12811281
     
    13411341        if solver != None:
    13421342            raise ValueError("Solver argument deprecated. This parameter now has to be set when calling the class' constructor")
    13431343
    1344         self._backend.set_verbosity(log)
     1344        if log != None: self._backend.set_verbosity(log)
    13451345
    13461346        self._backend.solve()
    13471347
     
    14781478
    14791479        Solver-specific parameters:
    14801480
    1481             - GLPK : only "timelimit" is available at the moment.
    1482 
    1483               .. NOTE::
    1484 
    1485                   In the case of GLPK, It is very easy to expose more
    1486                   solver-specific parameters through this method, so if you need
    1487                   to set a parameter that is not already here complain and/or
    1488                   write the patch !
     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`.
    14891485
    14901486            - CPLEX's parameters are identified by a string. Their
    14911487              list is available `on ILOG's website
     
    22022198
    22032199        self.constraints = other.constraints + self.constraints
    22042200        return self
     2201