Ticket #12823: trac_12823_alternate_removal.patch

File trac_12823_alternate_removal.patch, 34.7 KB (added by john_perry, 7 years ago)
  • sage/numerical/backends/generic_backend.pyx

    # HG changeset patch
    # User John Perry <john.perry@usm.edu>
    # Date 1332793439 18000
    # Node ID 51fd499fda3e65db6b7959039924f6e721edb861
    # Parent  8ae435d3ca273c3a8c5e3fa549359ca54cbdbf6b
    parameters for glpk solver
    
    diff --git a/sage/numerical/backends/generic_backend.pyx b/sage/numerical/backends/generic_backend.pyx
    a b  
    252252
    253253      - ``constraints`` -- an iterable containing the indices of the rows to remove.
    254254      """
    255       raise NotImplementedError()
     255      if type(constraints) == int: self.remove_constraint(constraints)
     256
     257      cdef int c
     258      cdef int last = self.nrows() + 1
     259
     260      for c in sorted(constraints, reverse=True):
     261          if c != last:
     262              self.remove_constraint(c)
     263              last = c
    256264
    257265    cpdef add_linear_constraint(self, coefficients, lower_bound, upper_bound, name=None):
    258266        """
  • sage/numerical/backends/glpk_backend.pxd

    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 *)
     
    106116     int glp_get_obj_dir(c_glp_prob *lp)
    107117     void glp_copy_prob(c_glp_prob *dst, c_glp_prob *src, int names)
    108118
     119     # constants
    109120
     121     # constants for smcp control
     122
     123     int GLP_MSG_OFF
     124     int GLP_MSG_ERR
     125     int GLP_MSG_ON
     126     int GLP_MSG_ALL
     127
     128     int GLP_PRIMAL
     129     int GLP_DUALP
     130     int GLP_DUAL
     131
     132     int GLP_PT_STD
     133     int GLP_PT_PSE
     134
     135     int GLP_RT_STD
     136     int GLP_RT_HAR
     137
     138     double DBL_MAX
     139
     140     int INT_MAX
    110141
    111142     int GLP_ON
     143     int GLP_OFF
     144
     145     # constants for iocp control, not already in simplex
     146
     147     int GLP_BR_FFV
     148     int GLP_BR_LFV
     149     int GLP_BR_MFV
     150     int GLP_BR_DTH
     151     int GLP_BR_PCH
     152
     153     int GLP_BT_DFS
     154     int GLP_BT_BFS
     155     int GLP_BT_BLB
     156     int GLP_BT_BPH
     157
     158     int GLP_PP_NONE
     159     int GLP_PP_ROOT
     160     int GLP_PP_ALL
     161
     162     # error codes
     163     int GLP_EBADB
     164     int GLP_ESING
     165     int GLP_ECOND
     166     int GLP_EBOUND
     167     int GLP_EFAIL
     168     int GLP_EOBJLL
     169     int GLP_EOBJUL
     170     int GLP_EITLIM
     171     int GLP_ETMLIM
     172     int GLP_EOPFS
     173     int GLP_EODFS
     174
     175     int GLP_UNDEF
     176     int GLP_OPT
     177     int GLP_FEAS
     178     int GLP_NOFEAS
     179     int GLP_INFEAS
     180     int GLP_UNBND
     181
     182     # other constants
     183
    112184     int GLP_MAX
    113185     int GLP_MIN
    114186     int GLP_UP
     
    119191     int GLP_CV
    120192     int GLP_IV
    121193     int GLP_BV
    122      int GLP_MSG_OFF
    123      int GLP_MSG_ERR
    124      int GLP_MSG_ON
    125      int GLP_MSG_ALL
    126194     int GLP_MPS_DECK
    127195     int GLP_MPS_FILE
    128196
    129      int GLP_UNDEF
    130      int GLP_OPT
    131      int GLP_FEAS
    132      int GLP_NOFEAS
    133 
    134197     int GLP_MSG_DBG
    135      int GLP_PRIMAL
    136      int GLP_DUALP
    137      int GLP_DUAL
    138      int GLP_PT_STD
    139      int GLP_PT_PSE
    140      int GLP_RT_STD
    141      int GLP_RT_HAR
    142198
    143199cdef class GLPKBackend(GenericBackend):
    144200    cdef c_glp_prob * lp
    145201    cdef c_glp_iocp * iocp
    146202    cdef c_glp_smcp * smcp
    147     cdef int preprocessing
     203    cdef int simplex_or_intopt
    148204    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))
     
    773774            Traceback (most recent call last):
    774775            ...
    775776            RuntimeError: GLPK : Signal sent, try preprocessing option
    776             sage: lp.solver_parameter("preprocessing", True)
     777            sage: lp.solver_parameter("simplex_or_intopt", "simplex_then_intopt")
    777778            sage: lp.solve()
    778779            Traceback (most recent call last):
    779780            ...
    780781            MIPSolverException: 'GLPK : Simplex cannot find a feasible solution'
     782
     783        The user can ask sage to solve via ``simplex`` or ``intopt``.
     784        The default solver is ``intopt``, so we get integer solutions.
     785
     786            sage: lp = MixedIntegerLinearProgram(solver = 'GLPK', maximization = False)
     787            sage: x, y = lp[0], lp[1]
     788            sage: lp.add_constraint(-2*x + y <= 1)
     789            sage: lp.add_constraint(x - y <= 1)
     790            sage: lp.add_constraint(x + y >= 2)
     791            sage: lp.set_objective(x + y)
     792            sage: lp.set_integer(x)
     793            sage: lp.set_integer(y)
     794            sage: lp.solve()
     795            2.0
     796            sage: lp.get_values([x, y])
     797            [1.0, 1.0]
     798
     799        If we switch to ``simplex``, we get continuous solutions.
     800
     801            sage: lp.solver_parameter("simplex_or_intopt", "simplex_only") # use simplex only
     802            sage: lp.solve()
     803            2.0
     804            sage: lp.get_values([x, y])
     805            [1.5, 0.5]
    781806        """
    782807
    783808        cdef int status
    784         if self.preprocessing:
     809        if self.simplex_or_intopt == glp_simplex_only or self.simplex_or_intopt == glp_simplex_then_intopt:
    785810            status = glp_simplex(self.lp, self.smcp)
    786811            status = glp_get_prim_stat(self.lp)
    787812            if status == GLP_OPT or status == GLP_FEAS:
     
    789814            elif status == GLP_UNDEF or status == GLP_NOFEAS:
    790815                raise MIPSolverException("GLPK : Simplex cannot find a feasible solution")
    791816
    792         sig_str('GLPK : Signal sent, try preprocessing option')
    793         glp_intopt(self.lp, self.iocp)
    794         sig_off()
     817        if self.simplex_or_intopt != glp_simplex_only:
     818          sig_str('GLPK : Signal sent, try preprocessing option')
     819          status = glp_intopt(self.lp, self.iocp)
     820          sig_off()
     821          # this is necessary to catch errors when certain options are enabled, e.g. tm_lim
     822          if status == GLP_ETMLIM: raise MIPSolverException("GLPK : The time limit was reached")
     823          elif status == GLP_EITLIM: raise MIPSolverException("GLPK : The iteration limit was reached")
    795824
    796         status = glp_mip_status(self.lp)
    797         if status == GLP_OPT:
    798             pass
    799         elif status == GLP_UNDEF:
    800             raise MIPSolverException("GLPK : Solution is undefined")
    801         elif status == GLP_FEAS:
    802             raise MIPSolverException("GLPK : Feasible solution found, while optimality has not been proven")
    803         elif status == GLP_NOFEAS:
    804             raise MIPSolverException("GLPK : There is no feasible integer solution to this Linear Program")
     825          status = glp_mip_status(self.lp)
     826          if status == GLP_OPT:
     827              pass
     828          elif status == GLP_UNDEF:
     829              raise MIPSolverException("GLPK : Solution is undefined")
     830          elif status == GLP_FEAS:
     831              raise MIPSolverException("GLPK : Feasible solution found, while optimality has not been proven")
     832          elif status == GLP_INFEAS:
     833              raise MIPSolverException("GLPK : Solution is infeasible")
     834          elif status == GLP_UNBND:
     835              raise MIPSolverException("GLPK : Problem has unbounded solution")
     836          elif status == GLP_NOFEAS:
     837              raise MIPSolverException("GLPK : There is no feasible integer solution to this Linear Program")
    805838
    806839        return 0
    807840
     
    830863            sage: p.get_variable_value(1)
    831864            1.5
    832865        """
    833         return glp_mip_obj_val(self.lp)
     866        if self.simplex_or_intopt != glp_simplex_only:
     867          return glp_mip_obj_val(self.lp)
     868        else:
     869          return glp_get_obj_val(self.lp)
    834870
    835871    cpdef double get_variable_value(self, int variable):
    836872        """
     
    856892            0.0
    857893            sage: p.get_variable_value(1)
    858894            1.5
    859         """   
    860         return glp_mip_col_val(self.lp, variable+1)
     895        """
     896        if self.simplex_or_intopt != glp_simplex_only:
     897          return glp_mip_col_val(self.lp, variable+1)
     898        else:
     899          return glp_get_col_prim(self.lp, variable+1)
    861900
    862901    cpdef int ncols(self):
    863902        """
     
    11921231            6.0
    11931232        """
    11941233        cdef GLPKBackend p = GLPKBackend(maximization = (1 if self.is_maximization() else -1))
    1195         p.preprocessing = self.preprocessing
     1234        p.simplex_or_intopt = self.simplex_or_intopt
    11961235        p.iocp.tm_lim = self.iocp.tm_lim
    11971236        glp_copy_prob(p.lp, self.lp, 1)
    11981237        return p
     
    12091248        - ``value`` -- the parameter's value if it is to be defined,
    12101249          or ``None`` (default) to obtain its current value.
    12111250
     1251        You can supply the name of a parameter and its value using either a string
     1252        or a ``glp_`` constant.
     1253        In most cases, you can use the same name for a paramter as that given
     1254        in the GLPK documentation, which is available by downloading GLPK from
     1255        <http://www.gnu.org/software/glpk/>. The exceptions relate to parameters
     1256        common to both methods; these require you to append ``_simplex`` or ``_intopt``
     1257        to the name to resolve ambiguity, since the interface allows access to both.
     1258
     1259        We have also provided more meaningful names, to assist readability.
     1260
     1261        Parameter **names** are specified in lower case.
     1262        To use a constant instead of a string, prepend ``glp_`` to the name.
     1263        For example, both ``glp_gmi_cuts`` or ``"gmi_cuts"`` control whether
     1264        to solve using Gomory cuts.
     1265
     1266        Parameter **values** are specificed as strings in upper case,
     1267        or as constants in lower case. For example, both ``glp_on`` and ``"GLP_ON"``
     1268        specify the same thing.
     1269
     1270        Naturally, you can use ``True`` and ``False`` in cases where ``glp_on`` and ``glp_off``
     1271        would be used.
     1272       
     1273        A list of parameter names, with their values:
     1274
     1275        - ``timelimit`` -- specify the time limit IN SECONDS.
     1276          This affects both simplex and intopt.
     1277
     1278        - ``timelimit_simplex`` and ``timelimit_intopt`` -- specify the time limit
     1279          IN MILLISECONDS. (This is glpk's default.)
     1280
     1281        - ``simplex_or_intopt`` -- whether to use the ``simplex`` or ``intopt``
     1282          routines in GLPK. This is controlled by using ``glp_simplex_only``,
     1283          ``glp_intopt_only``, and ``glp_simplex_then_intopt``. The latter is
     1284          useful to deal with a problem in GLPK where problems with no solution
     1285          hang when using integer optimization; if you specify
     1286          ``glp_simplex_then_intopt``, sage will try simplex first,
     1287          then perform integer optimization only if a solution of the LP
     1288          relaxation exists.
     1289
     1290        - ``verbosity_intopt`` and ``verbosity_simplex`` -- one of ``GLP_MSG_OFF``,
     1291          ``GLP_MSG_ERR``, ``GLP_MSG_ON``, or ``GLP_MSG_ALL``. The default in sage
     1292          is ``GLP_MSG_OFF``.
     1293
     1294        - ``output_frequency_intopt`` and ``output_frequency_simplex`` --
     1295          the output frequency, in milliseconds. Default is 5000.
     1296
     1297        - ``output_delay_intopt`` and ``output_delay_simplex`` --
     1298          the output delay, in milliseconds, regarding the use of the simplex
     1299          method on the LP relaxation. Default is 10000.
     1300
     1301        - ``intopt``-specific parameters:
     1302
     1303          - ``branching`` -- one of:
     1304            - ``GLP_BR_FFV`` -- first fractional variable
     1305            - ``GLP_BR_LFV`` -- last fractional variable
     1306            - ``GLP_BR_MFV`` -- most fractional variable
     1307            - ``GLP_BR_DTH`` -- Driebeck-Tomlin heuristic (default)
     1308            - ``GLP_BR_PCH`` -- hybrid pseudocost heuristic
     1309
     1310          - ``backtracking`` -- one of:
     1311            - ``GLP_BT_DFS`` -- depth first search
     1312            - ``GLP_BT_BFS`` -- breadth first search
     1313            - ``GLP_BT_BLB`` -- best local bound (default)
     1314            - ``GLP_BT_BPH`` -- best projection heuristic
     1315
     1316          - ``preprocessing`` -- one of:
     1317            - ``GLP_PP_NONE``
     1318            - ``GLP_PP_ROOT`` -- preprocessing only at root level
     1319            - ``GLP_PP_ALL`` (default)
     1320
     1321          - ``feasibility_pump`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default)
     1322
     1323          - ``gomory_cuts`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default)
     1324
     1325          - ``mixed_int_rounding_cuts`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default)
     1326
     1327          - ``mixed_cover_cuts`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default)
     1328
     1329          - ``clique_cuts`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default)
     1330
     1331          - ``absolute_tolerance`` -- (double) used to check if optimal solution to LP relaxation
     1332            is integer feasible. GLPK manual advises, "do not change... without detailed
     1333            understanding of its purpose."
     1334
     1335          - ``relative_tolerance`` -- (double) used to check if objective value in LP relaxation
     1336            is not better than best known integer solution. GLPK manual advises, "do not
     1337            change... without detailed understanding of its purpose."
     1338
     1339          - ``mip_gap_tolerance`` -- (double) relative mip gap tolerance. Default is 0.0.
     1340
     1341          - ``presolve_intopt`` -- one of ``GLP_ON`` (default in sage) or ``GLP_OFF``.
     1342
     1343          - ``binarize`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default)
     1344
     1345        - ``simplex``-specific parameters:
     1346
     1347          - ``primal_v_dual`` -- one of ``GLP_PRIMAL`` (default), ``GLP_DUAL``, or
     1348            ``GLP_DUALP``.
     1349
     1350          - ``pricing`` -- one of:
     1351            - ``GLP_PT_STD`` -- standard (textbook)
     1352            - ``GLP_PT_PSE`` -- projected steepest edge (default)
     1353
     1354          - ``ratio_test`` -- one of:
     1355            - ``GLP_RT_STD`` -- standard (textbook)
     1356            - ``GLP_RT_HAR`` -- Harris' two-pass ratio test (default)
     1357
     1358          - ``tolerance_primal`` -- (double) tolerance used to check if basic solution
     1359            is primal feasible. GLPK manual advises, "do not
     1360            change... without detailed understanding of its purpose."
     1361
     1362          - ``tolerance_dual`` -- (double) tolerance used to check if basic solution
     1363            is dual feasible. GLPK manual advises, "do not
     1364            change... without detailed understanding of its purpose."
     1365
     1366          - ``tolerance_pivot`` -- (double) tolerance used to choose pivot. GLPK manual advises, "do not
     1367            change... without detailed understanding of its purpose."
     1368
     1369          - ``obj_lower_limit`` -- (double) lower limit of the objective function.
     1370            The default is ``-DBL_MAX``.
     1371
     1372          - ``obj_upper_limit`` -- (double) upper limit of the objective function.
     1373            The default is ``DBL_MAX``.
     1374
     1375          - ``iteration_limit`` -- (int) iteration limit of the simplex algorithn.
     1376            The default is ``INT_MAX``.
     1377
     1378          - ``presolve_simplex`` -- one of ``GLP_ON`` or ``GLP_OFF`` (default).
     1379
    12121380        .. NOTE::
    12131381
    1214            The list of available parameters is available at
    1215            :meth:`sage.numerical.mip.MixedIntegerlinearProgram.solver_parameter`
     1382            The coverage for GLPK's control parameters for simplex and integer optimization
     1383            is nearly complete. The only thing lacking is a wrapper for callback routines.
     1384
     1385            To date, no attempt has been made to expose the interior point methods.
    12161386
    12171387        EXAMPLE::
    12181388
     
    12211391            sage: p.solver_parameter("timelimit", 60)             
    12221392            sage: p.solver_parameter("timelimit")                 
    12231393            60.0
     1394
     1395        Don't forget the difference between ``timelimit`` and ``timelimit_intopt``.
     1396
     1397        ..::
     1398
     1399            sage: p.solver_parameter("timelimit_intopt")
     1400            60000
     1401
     1402        If you don't care for an integer answer, you can ask for an lp relaxation instead.
     1403        The default solver performs integer optimization, but
     1404        you can switch to the standard simplex algorithm.
     1405
     1406        EXAMPLE::
     1407
     1408            sage: lp = MixedIntegerLinearProgram(solver = 'GLPK', maximization = False)
     1409            sage: x, y = lp[0], lp[1]
     1410            sage: lp.add_constraint(-2*x + y <= 1)
     1411            sage: lp.add_constraint(x - y <= 1)
     1412            sage: lp.add_constraint(x + y >= 2)
     1413            sage: lp.set_integer(x); lp.set_integer(y)
     1414            sage: lp.set_objective(x + y)
     1415            sage: lp.solve()
     1416            2.0
     1417            sage: lp.get_values([x,y])
     1418            [1.0, 1.0]
     1419            sage: import sage.numerical.backends.glpk_backend as backend
     1420            sage: lp.solver_parameter(backend.glp_simplex_or_intopt, backend.glp_simplex_only)
     1421            sage: lp.solve()
     1422            2.0
     1423            sage: lp.get_values([x,y])
     1424            [1.5, 0.5]
     1425       
     1426        You can get glpk to spout all sorts of information at you.
     1427        The default is to turn this off, but sometimes (debugging) it's very useful.
     1428       
     1429        .. link
     1430
     1431        ::
     1432
     1433            sage: lp.solver_parameter(backend.glp_simplex_or_intopt, backend.glp_simplex_then_intopt)
     1434            sage: lp.solver_parameter(backend.glp_mir_cuts, backend.glp_on)
     1435            sage: lp.solver_parameter(backend.glp_msg_lev_intopt, backend.glp_msg_all)
     1436            sage: lp.solver_parameter(backend.glp_mir_cuts)
     1437            1
     1438
     1439        If you actually try to solve ``lp``, you will get a lot of detailed information.
    12241440        """
    1225         if name == "timelimit":
    1226             if value == None:
    1227                 return self.iocp.tm_lim/1000.0
     1441
     1442        if type(name) == str:
     1443          if name == "out_frq" or name == "out_dly" or name == "tm_lim" or name == "msg_lev":
     1444            raise ValueError("To set parameter " + name + " you must specify the solver. Append either _simplex or _intopt.")
     1445          name = solver_parameter_names_dict[name]
     1446
     1447        if type(value) == str: value = solver_parameter_values[value]
     1448
     1449        if name == timelimit_intopt:
     1450            if value == None: return self.iocp.tm_lim
     1451            else: self.iocp.tm_lim = value
     1452
     1453        if name == timelimit_seconds:
     1454            if value == None: return self.iocp.tm_lim / 1000.0
    12281455            else:
    1229                 self.iocp.tm_lim = 1000 * value
     1456                self.iocp.tm_lim = value * 1000.0
     1457                self.smcp.tm_lim = value * 1000.0
    12301458
    1231         elif name == "preprocessing":
    1232             if value == None:
    1233                 return self.preprocessing
     1459        elif name == timelimit_simplex:
     1460            if value == None: return self.smcp.tm_lim
     1461            else: self.smcp.tm_lim = value
     1462
     1463        elif name == simplex_or_intopt:
     1464            if value == None: return self.simplex_or_intopt
     1465            if not value in (simplex_only,intopt_only,simplex_then_intopt): raise MIPSolverException, "GLPK: invalid value for simplex_or_intopt; see documentation"
     1466            self.simplex_or_intopt = value
     1467
     1468        elif name == msg_lev_simplex:
     1469            if value == None: return self.smcp.msg_lev
     1470            else: self.smcp.msg_lev = value
     1471
     1472        elif name == msg_lev_intopt:
     1473            if value == None: return self.iocp.msg_lev
     1474            else: self.iocp.msg_lev = value
     1475
     1476        elif name == br_tech:
     1477            if value == None: return self.iocp.br_tech
     1478            else: self.iocp.br_tech = value
     1479
     1480        elif name == bt_tech:
     1481            if value == None: return self.iocp.bt_tech
     1482            else: self.iocp.bt_tech = value
     1483
     1484        elif name == pp_tech:
     1485            if value == None: return self.iocp.pp_tech
     1486            else: self.iocp.pp_tech = value
     1487
     1488        elif name == fp_heur:
     1489            if value == None: return self.iocp.fp_heur
    12341490            else:
    1235                 if value == True: value = 1
    1236                 elif value == False: value = 0
    1237                 self.preprocessing = value
     1491              if value == True: value = GLP_ON
     1492              elif value == False: value = GLP_OFF
     1493              self.iocp.fp_heur = value
     1494
     1495        elif name == gmi_cuts:
     1496            if value == None: return self.iocp.gmi_cuts
     1497            else:
     1498              if value == True: value = GLP_ON
     1499              elif value == False: value = GLP_OFF
     1500              self.iocp.gmi_cuts = value
     1501
     1502        elif name == mir_cuts:
     1503            if value == None: return self.iocp.mir_cuts
     1504            else:
     1505              if value == True: value = GLP_ON
     1506              elif value == False: value = GLP_OFF
     1507              self.iocp.mir_cuts = value
     1508
     1509        elif name == cov_cuts:
     1510            if value == None: return self.iocp.cov_cuts
     1511            else:
     1512              if value == True: value = GLP_ON
     1513              elif value == False: value = GLP_OFF
     1514              self.iocp.cov_cuts = value
     1515
     1516        elif name == clq_cuts:
     1517            if value == None: return self.iocp.clq_cuts
     1518            else:
     1519              if value == True: value = GLP_ON
     1520              elif value == False: value = GLP_OFF
     1521              self.iocp.clq_cuts = value
     1522
     1523        elif name == tol_int:
     1524            if value == None: return self.iocp.tol_int
     1525            else: self.iocp.tol_int = value
     1526
     1527        elif name == tol_obj:
     1528            if value == None: return self.iocp.tol_obj
     1529            else: self.iocp.tol_obj = value
     1530
     1531        elif name == mip_gap:
     1532            if value == None: return self.iocp.mip_gap
     1533            else: self.iocp.mip_gap = value
     1534
     1535        elif name == tm_lim_intopt:
     1536            if value == None: return self.iocp.tm_lim
     1537            else: self.iocp.tm_lim = value
     1538
     1539        elif name == out_frq_intopt:
     1540            if value == None: return self.iocp.out_frq
     1541            else: self.iocp.out_frq = value
     1542
     1543        elif name == out_dly_intopt:
     1544            if value == None: return self.iocp.out_dly
     1545            else: self.iocp.out_dly = value
     1546
     1547        elif name == presolve_intopt:
     1548            if value == None: return self.iocp.presolve
     1549            else:
     1550                if value == True: value = GLP_ON
     1551                elif value == False: value = GLP_OFF
     1552                self.iocp.presolve = value
     1553
     1554        elif name == binarize:
     1555            if value == None: return self.iocp.binarize
     1556            else:
     1557              if value == True: value = GLP_ON
     1558              elif value == False: value = GLP_OFF
     1559              self.iocp.binarize = value
     1560
     1561        elif name == msg_lev_simplex:
     1562            if value == None: return self.smcp.msg_lev
     1563            else: self.smcp.msg_lev = value
     1564
     1565        elif name == meth:
     1566            if value == None: return self.smcp.meth
     1567            else: self.smcp.meth = value
     1568
     1569        elif name == pricing:
     1570            if value == None: return self.smcp.pricing
     1571            else: self.smcp.pricing = value
     1572
     1573        elif name == r_test:
     1574            if value == None: return self.smcp.r_test
     1575            else: self.smcp.r_test = value
     1576
     1577        elif name == tol_bnd:
     1578            if value == None: return self.smcp.tol_bnd
     1579            else: self.smcp.tol_bnd = value
     1580
     1581        elif name == tol_dj:
     1582            if value == None: return self.smcp.tol_dj
     1583            else: self.smcp.tol_dj = value
     1584
     1585        elif name == tol_piv:
     1586            if value == None: return self.smcp.tol_piv
     1587            else: self.smcp.tol_piv = value
     1588
     1589        elif name == obj_ll:
     1590            if value == None: return self.smcp.obj_ll
     1591            else: self.smcp.obj_ll = value
     1592
     1593        elif name == obj_ul:
     1594            if value == None: return self.smcp.obj_ul
     1595            else: self.smcp.obj_ul = value
     1596
     1597        elif name == it_lim:
     1598            if value == None: return self.smcp.it_lim
     1599            else: self.smcp.it_lim = value
     1600
     1601        elif name == tm_lim_simplex:
     1602            if value == None: return self.smcp.tm_lim
     1603            else: self.smcp.tm_lim = value
     1604
     1605        elif name == out_frq_simplex:
     1606            if value == None: return self.smcp.out_frq
     1607            else: self.smcp.out_frq = value
     1608
     1609        elif name == out_dly_simplex:
     1610            if value == None: return self.smcp.out_dly
     1611            else: self.smcp.out_dly = value
     1612
     1613        elif name == presolve_simplex:
     1614            if value == None: return self.smcp.presolve
     1615            else:
     1616              if value == True: value = GLP_ON
     1617              elif value == False: value = GLP_OFF
     1618              self.smcp.presolve = value
    12381619
    12391620        else:
    12401621            raise ValueError("This parameter is not available.")
     
    12461627        glp_delete_prob(self.lp)
    12471628        sage_free(self.iocp)
    12481629        sage_free(self.smcp)
     1630
     1631# parameter names
     1632
     1633cdef enum solver_parameter_names:
     1634  timelimit_seconds, timelimit_simplex, timelimit_intopt, simplex_or_intopt, msg_lev_simplex,
     1635  msg_lev_intopt, br_tech, bt_tech, pp_tech, fp_heur, gmi_cuts,
     1636  mir_cuts, cov_cuts, clq_cuts, tol_int, tol_obj, mip_gap,
     1637  tm_lim_intopt, out_frq_intopt, out_dly_intopt, presolve_intopt,
     1638  binarize, meth, pricing, r_test, tol_bnd, tol_dj, tol_piv, obj_ll,
     1639  obj_ul, it_lim, tm_lim_simplex, out_frq_simplex, out_dly_simplex,
     1640  presolve_simplex
     1641
     1642glp_tm_lim_simplex = timelimit_simplex
     1643glp_tm_lim_intopt = timelimit_intopt
     1644glp_simplex_or_intopt = simplex_or_intopt
     1645glp_msg_lev_intopt = glp_verbosity_intopt = msg_lev_intopt
     1646glp_msg_lev_simplex = glp_verbosity_simplex = msg_lev_simplex
     1647glp_br_tech = glp_branching = br_tech
     1648glp_bt_tech = glp_backtracking = bt_tech
     1649glp_pp_tech = glp_preprocessing = pp_tech
     1650glp_fp_heur = glp_feasibility_pump = fp_heur
     1651glp_gmi_cuts = glp_gomory_cuts = gmi_cuts
     1652glp_mir_cuts = glp_mixed_int_rounding_cuts = mir_cuts
     1653glp_cov_cuts = glp_mixed_cover_cuts = cov_cuts
     1654glp_clq_cuts = glp_clique_cuts = clq_cuts
     1655glp_tol_int = glp_absolute_tolerance = tol_int
     1656glp_tol_obj = glp_relative_tolerance = tol_obj
     1657glp_mip_gap = glp_mip_gap_tolerance = mip_gap
     1658glp_out_frq_intopt = glp_output_frequency_intopt = out_frq_intopt
     1659glp_out_dly_intopt = glp_output_delay_intopt = out_dly_intopt
     1660glp_presolve_intopt = presolve_intopt
     1661glp_binarize = binarize
     1662glp_meth = glp_primal_v_dual = meth
     1663glp_pricing = pricing
     1664glp_r_test = glp_ratio_test = r_test
     1665glp_tol_bnd = glp_tolerance_primal = tol_bnd
     1666glp_tol_dj = glp_tolerance_dual = tol_dj
     1667glp_tol_piv = glp_tolerance_pivot = tol_piv
     1668glp_obj_ll = glp_obj_lower_limit = obj_ll
     1669glp_obj_ul = glp_obj_upper_limit = obj_ul
     1670glp_it_lim = glp_iteration_limit = it_lim
     1671glp_out_frq_simplex = glp_output_frequency_intopt = out_frq_simplex
     1672glp_out_dly_simplex = glp_output_delay_simplex = out_dly_simplex
     1673glp_presolve_simplex = presolve_simplex
     1674
     1675solver_parameter_names_dict = {
     1676  'timelimit': timelimit_seconds,
     1677  'timelimit_intopt': timelimit_intopt,
     1678  'tm_lim_intopt': timelimit_intopt,
     1679  'timelimit_simplex': timelimit_simplex,
     1680  'tm_lim_simplex': timelimit_simplex,
     1681  'simplex_or_intopt': simplex_or_intopt,
     1682  'msg_lev_simplex': msg_lev_simplex, 'verbosity_simplex': msg_lev_simplex,
     1683  'msg_lev_intopt': msg_lev_intopt, 'verbosity_intopt': msg_lev_intopt,
     1684  'br_tech': br_tech, 'branching': br_tech,
     1685  'bt_tech': bt_tech, 'backtracking': bt_tech,
     1686  'pp_tech': pp_tech, 'preprocessing': pp_tech,
     1687  'fp_heur': fp_heur, 'feasibility_pump': fp_heur,
     1688  'gmi_cuts': gmi_cuts, 'gomory_cuts': gmi_cuts,
     1689  'mir_cuts': mir_cuts, 'mixed_int_rounding_cuts': mir_cuts,
     1690  'cov_cuts': cov_cuts, 'mixed_cover_cuts': cov_cuts,
     1691  'clq_cuts': clq_cuts, 'clique_cuts': clq_cuts,
     1692  'tol_int': tol_int, 'absolute_tolerance': tol_int,
     1693  'tol_obj': tol_obj, 'relative_tolerance': tol_obj,
     1694  'mip_gap': mip_gap, 'mip_gap_tolerance': mip_gap,
     1695  'out_frq_intopt': out_frq_intopt, 'output_frequency_intopt': out_frq_intopt,
     1696  'out_dly_intopt': out_dly_intopt, 'output_delay_intopt': out_dly_intopt,
     1697  'presolve_intopt': presolve_intopt, 'binarize': binarize,
     1698  'meth': meth, 'primal_v_dual': meth,
     1699  'pricing': pricing,
     1700  'r_test': r_test, 'ratio_test': r_test,
     1701  'tol_bnd': tol_bnd, 'tolerance_primal': tol_bnd,
     1702  'tol_dj': tol_dj, 'tolerance_dual': tol_dj,
     1703  'tol_piv': tol_piv, 'tolerance_pivot': tol_piv,
     1704  'obj_ll': obj_ll, 'obj_lower_limit': obj_ll,
     1705  'obj_ul': obj_ul, 'obj_upper_limit': obj_ul,
     1706  'it_lim': it_lim, 'iteration_limit': it_lim,
     1707  'out_frq_simplex': out_frq_simplex, 'output_frequency_intopt': out_frq_simplex,
     1708  'out_dly_simplex': out_dly_simplex, 'output_delay_simplex': out_dly_simplex,
     1709  'presolve_simplex': presolve_simplex
     1710}
     1711
     1712# parameter values
     1713
     1714glp_msg_off = GLP_MSG_OFF
     1715glp_msg_on = GLP_MSG_ON
     1716glp_msg_err = GLP_MSG_ERR
     1717glp_msg_all = GLP_MSG_ALL
     1718glp_msg_dbg = GLP_MSG_DBG
     1719
     1720glp_primal = GLP_PRIMAL
     1721glp_dual = GLP_DUAL
     1722glp_dualp = GLP_DUALP
     1723
     1724glp_pt_std = GLP_PT_STD
     1725glp_pt_pse = GLP_PT_PSE
     1726
     1727glp_rt_std = GLP_RT_STD
     1728glp_rt_har = GLP_RT_HAR
     1729
     1730dbl_max = DBL_MAX
     1731int_max = INT_MAX
     1732
     1733glp_on = GLP_ON
     1734glp_off = GLP_OFF
     1735
     1736glp_br_ffv = GLP_BR_FFV
     1737glp_br_lfv = GLP_BR_LFV
     1738glp_br_mfv = GLP_BR_MFV
     1739glp_br_dth = GLP_BR_DTH
     1740glp_br_pch = GLP_BR_PCH
     1741
     1742glp_bt_dfs = GLP_BT_DFS
     1743glp_bt_bfs = GLP_BT_BFS
     1744glp_bt_blb = GLP_BT_BLB
     1745glp_bt_bph = GLP_BT_BPH
     1746
     1747glp_pp_none = GLP_PP_NONE
     1748glp_pp_root = GLP_PP_ROOT
     1749glp_pp_all = GLP_PP_ALL
     1750
     1751glp_max = GLP_MAX
     1752glp_min = GLP_MIN
     1753glp_up = GLP_UP
     1754glp_fr = GLP_FR
     1755glp_db = GLP_DB
     1756glp_fx = GLP_FX
     1757glp_lo = GLP_LO
     1758glp_cv = GLP_CV
     1759glp_iv = GLP_IV
     1760glp_bv = GLP_BV
     1761glp_mps_deck = GLP_MPS_DECK
     1762glp_mps_file = GLP_MPS_FILE
     1763
     1764glp_undef = GLP_UNDEF
     1765glp_opt = GLP_OPT
     1766glp_feas = GLP_FEAS
     1767glp_nofeas = GLP_NOFEAS
     1768
     1769cdef enum more_parameter_values:
     1770  simplex_only, simplex_then_intopt, intopt_only
     1771
     1772glp_simplex_only = simplex_only
     1773glp_simplex_then_intopt = simplex_then_intopt
     1774glp_intopt_only = intopt_only
     1775
     1776# dictionaries for those who prefer to use strings
     1777
     1778solver_parameter_values = {
     1779
     1780  'simplex_only': simplex_only,
     1781  'simplex_then_intopt': simplex_then_intopt,
     1782  'intopt_only': intopt_only,
     1783
     1784  'GLP_MSG_OFF' : GLP_MSG_OFF,
     1785  'GLP_MSG_ON' : GLP_MSG_ON,
     1786  'GLP_MSG_ERR' : GLP_MSG_ERR,
     1787  'GLP_MSG_ALL' : GLP_MSG_ALL,
     1788  'GLP_MSG_DBG' : GLP_MSG_DBG,
     1789
     1790  'GLP_PRIMAL' : GLP_PRIMAL,
     1791  'GLP_DUAL' : GLP_DUAL,
     1792  'GLP_DUALP' : GLP_DUALP,
     1793
     1794  'GLP_PT_STD' : GLP_PT_STD,
     1795  'GLP_PT_PSE' : GLP_PT_PSE,
     1796
     1797  'GLP_RT_STD' : GLP_RT_STD,
     1798  'GLP_RT_HAR' : GLP_RT_HAR,
     1799
     1800  'DBL_MAX' : DBL_MAX,
     1801  'INT_MAX' : INT_MAX,
     1802
     1803  'GLP_ON' : GLP_ON,
     1804  'GLP_OFF' : GLP_OFF,
     1805
     1806  'GLP_BR_FFV' : GLP_BR_FFV,
     1807  'GLP_BR_LFV' : GLP_BR_LFV,
     1808  'GLP_BR_MFV' : GLP_BR_MFV,
     1809  'GLP_BR_DTH' : GLP_BR_DTH,
     1810  'GLP_BR_PCH' : GLP_BR_PCH,
     1811
     1812  'GLP_BT_DFS' : GLP_BT_DFS,
     1813  'GLP_BT_BFS' : GLP_BT_BFS,
     1814  'GLP_BT_BLB' : GLP_BT_BLB,
     1815  'GLP_BT_BPH' : GLP_BT_BPH,
     1816
     1817  'GLP_PP_NONE' : GLP_PP_NONE,
     1818  'GLP_PP_ROOT' : GLP_PP_ROOT,
     1819  'GLP_PP_ALL' : GLP_PP_ALL,
     1820
     1821  'GLP_MAX' : GLP_MAX,
     1822  'GLP_MIN' : GLP_MIN,
     1823  'GLP_UP' : GLP_UP,
     1824  'GLP_FR' : GLP_FR,
     1825  'GLP_DB' : GLP_DB,
     1826  'GLP_FX' : GLP_FX,
     1827  'GLP_LO' : GLP_LO,
     1828  'GLP_CV' : GLP_CV,
     1829  'GLP_IV' : GLP_IV,
     1830  'GLP_BV' : GLP_BV,
     1831  'GLP_MPS_DECK' : GLP_MPS_DECK,
     1832  'GLP_MPS_FILE' : GLP_MPS_FILE,
     1833
     1834  'GLP_UNDEF' : GLP_UNDEF,
     1835  'GLP_OPT' : GLP_OPT,
     1836  'GLP_FEAS' : GLP_FEAS,
     1837  'GLP_NOFEAS' : GLP_NOFEAS
     1838
     1839}
  • sage/numerical/mip.pyx

    diff --git a/sage/numerical/mip.pyx b/sage/numerical/mip.pyx
    a b  
    10381038                self.add_constraint(functions[0] - functions[1], max=0, name=name)
    10391039                self.add_constraint(functions[1] - functions[2], max=0, name=name)
    10401040
    1041     def remove_constraint(self, int i):
    1042         r"""
    1043         Removes a constraint from self.
    1044 
    1045         INPUT:
    1046 
    1047         - ``i`` -- Index of the constraint to remove.
    1048 
    1049         EXAMPLE::
    1050 
    1051             sage: p = MixedIntegerLinearProgram()
    1052             sage: x, y = p[0], p[1]
    1053             sage: p.add_constraint(x + y, max = 10)
    1054             sage: p.add_constraint(x - y, max = 0)
    1055             sage: p.add_constraint(x - y, max = 0)
    1056             sage: p.add_constraint(x, max = 4)
    1057             sage: p.remove_constraint(2)
    1058             sage: p.show()
    1059             Maximization:
    1060             <BLANKLINE>
    1061             Constraints:
    1062               x_0 + x_1 <= 10.0
    1063               x_0 - x_1 <= 0.0
    1064               x_0 <= 4.0
    1065             ...
    1066             sage: p.number_of_constraints()
    1067             3
    1068 
    1069         WARN::
    1070 
    1071             Whether the first constraint is numbered 0 or 1 depends on the backend.
    1072             For GLPK, the first constraint has index 1; for Coin, it has index 0.
    1073             This is why the example above adds the same constraint twice,
    1074             and tries to remove on of its copies. Whether it removes the first
    1075             or the second depends on the backend.
    1076             Since supplying an invalid number WILL CAUSE A CRASH, please be careful!
    1077         """
    1078         self._backend.remove_constraint(i)
    1079 
    10801041    def remove_constraints(self, constraints):
    10811042        """
    10821043        Remove several constraints.
     
    13291290
    13301291        return self._backend.is_variable_continuous(self._variables[e])
    13311292
    1332     def solve(self, solver=None, log=0, objective_only=False):
     1293    def solve(self, solver=None, log=None, objective_only=False):
    13331294        r"""
    13341295        Solves the ``MixedIntegerLinearProgram``.
    13351296
     
    14061367        if solver != None:
    14071368            raise ValueError("Solver argument deprecated. This parameter now has to be set when calling the class' constructor")
    14081369
    1409         self._backend.set_verbosity(log)
     1370        if log != None: self._backend.set_verbosity(log)
    14101371
    14111372        self._backend.solve()
    14121373
     
    15431504
    15441505        Solver-specific parameters:
    15451506
    1546             - GLPK : only "timelimit" is available at the moment.
    1547 
    1548               .. NOTE::
    1549 
    1550                   In the case of GLPK, It is very easy to expose more
    1551                   solver-specific parameters through this method, so if you need
    1552                   to set a parameter that is not already here complain and/or
    1553                   write the patch !
     1507            - GLPK : We have implemented very close to comprehensive coverage
     1508              of the GLPK solver parameters for the simplex and integer optimization
     1509              methods. For details, see the documentation in
     1510              :meth:`sage.numerical.backends.glpk_backend`.
    15541511
    15551512            - CPLEX's parameters are identified by a string. Their
    15561513              list is available `on ILOG's website
     
    22672224
    22682225        self.constraints = other.constraints + self.constraints
    22692226        return self
     2227