Ticket #10785: trac_10785.patch
File trac_10785.patch, 15.9 KB (added by , 9 years ago) |
---|
-
sage/numerical/backends/cplex_backend.pxd
# HG changeset patch # User Nathann Cohen <nathann.cohen@gmail.com> # Date 1297790620 -3600 # Node ID 3e77dc1a14ed7932034ce611b9a38c763a52a93a # Parent b72663c760492cc8c360d328a6d370c8f88d2069 trac 10785 -- setting a solver-specific parameter in MixedIntegerLinearProgram diff --git a/sage/numerical/backends/cplex_backend.pxd b/sage/numerical/backends/cplex_backend.pxd
a b 170 170 # Copy a LP 171 171 c_cpxlp * CPXcloneprob(c_cpxlp * env, c_cpxlp * lp, int * status_p) 172 172 173 # Gets the type of a CPLEX parameter 174 int CPXgetparamtype(c_cpxlp * env, int paramid, int * paramtype) 175 176 # returns the value of an integer prameter 177 int CPXgetintparam(c_cpxlp * env, int paramid, int * intv) 178 179 # returns the value of a double prameter 180 int CPXgetdblparam(c_cpxlp * env, int paramid, double * doublev) 181 182 # returns the value of a string prameter 183 int CPXgetstrparam(c_cpxlp * env, int paramid, char * strv) 184 185 # sets the value of an integer parameter 186 int CPXsetintparam(c_cpxlp * env, int paramid, int value) 187 188 # sets the value of a double parameter 189 int CPXsetdblparam(c_cpxlp * env, int paramid, double value) 190 191 # sets the value of a string parameter 192 int CPXsetstrparam(c_cpxlp * env, int paramid, char * value) 193 173 194 # CONSTANTS 174 195 int CPX_ON = 1 175 196 int CPX_PARAM_SCRIND = 1035 -
sage/numerical/backends/cplex_backend.pyx
diff --git a/sage/numerical/backends/cplex_backend.pyx b/sage/numerical/backends/cplex_backend.pyx
a b 1268 1268 1269 1269 return p 1270 1270 1271 cpdef solver_parameter(self, name, value = None): 1272 """ 1273 Return or define a solver parameter 1274 1275 INPUT: 1276 1277 - ``name`` (string) -- the parameter 1278 1279 - ``value`` -- the parameter's value if it is to be defined, 1280 or ``None`` (default) to obtain its current value. 1281 1282 .. NOTE:: 1283 1284 The list of available parameters is available at 1285 :meth:`sage.numerical.mip.MixedIntegerlinearProgram.solver_parameter` 1286 1287 EXAMPLE:: 1288 1289 sage: from sage.numerical.backends.generic_backend import get_solver 1290 sage: p = get_solver(solver = "CPLEX") # optional - CPLEX 1291 sage: p.solver_parameter("timelimit", 60) # optional - CPLEX 1292 sage: p.solver_parameter("timelimit") # optional - CPLEX 1293 60.0 1294 """ 1295 cdef int intv 1296 cdef double doublev 1297 cdef char * strv 1298 1299 # If the name has to be translated to a CPLEX parameter ID 1300 if name == "timelimit": 1301 name = "CPX_PARAM_TILIM" 1302 1303 cdef int paramid = parameters.get(name,-1) 1304 1305 if paramid == -1: 1306 raise ValueError("This parameter is not available.") 1307 1308 # Type of the parameter. Can be INT (1), Double(2) or String(3) 1309 cdef int paramtype 1310 CPXgetparamtype(self.env, paramid, ¶mtype) 1311 1312 if value is None: 1313 if paramtype == 1: 1314 CPXgetintparam(self.env, paramid, &intv) 1315 return intv 1316 elif paramtype == 2: 1317 CPXgetdblparam(self.env, paramid, &doublev) 1318 return doublev 1319 else: 1320 strv = <char *>sage_malloc(500*sizeof(char)) 1321 CPXgetstrparam(self.env, paramid, strv) 1322 s = str(strv) 1323 sage_free(strv) 1324 return s 1325 else: 1326 if paramtype == 1: 1327 CPXsetintparam(self.env, paramid, value) 1328 elif paramtype == 2: 1329 CPXsetdblparam(self.env, paramid, value) 1330 else: 1331 CPXsetstrparam(self.env, paramid, value) 1332 1271 1333 def __dealloc__(self): 1272 1334 r""" 1273 1335 Destructor for the class … … 1296 1358 # Todo : when common error codes are returned, rewrite the message to 1297 1359 # be more meaningful 1298 1360 1361 cdef dict errors 1362 1299 1363 errors = { 1300 1364 1001 : "CPXERR_NO_MEMORY", 1301 1365 1002 : "CPXERR_NO_ENVIRONMENT", … … 1544 1608 6002 : "CPXERR_QCP_SENSE" 1545 1609 } 1546 1610 1611 cdef dict parameters 1612 parameters = { 1613 "CPX_PARAMTYPE_NONE" : 0, 1614 "CPX_PARAMTYPE_INT" : 1, 1615 "CPX_PARAMTYPE_DOUBLE" : 2, 1616 "CPX_PARAMTYPE_STRING" : 3, 1617 "CPX_PARAM_ADVIND" : 1001, 1618 "CPX_PARAM_AGGFILL" : 1002, 1619 "CPX_PARAM_AGGIND" : 1003, 1620 "CPX_PARAM_BASINTERVAL" : 1004, 1621 "CPX_PARAM_CFILEMUL" : 1005, 1622 "CPX_PARAM_CLOCKTYPE" : 1006, 1623 "CPX_PARAM_CRAIND" : 1007, 1624 "CPX_PARAM_DEPIND" : 1008, 1625 "CPX_PARAM_DPRIIND" : 1009, 1626 "CPX_PARAM_PRICELIM" : 1010, 1627 "CPX_PARAM_EPMRK" : 1013, 1628 "CPX_PARAM_EPOPT" : 1014, 1629 "CPX_PARAM_EPPER" : 1015, 1630 "CPX_PARAM_EPRHS" : 1016, 1631 "CPX_PARAM_FASTMIP" : 1017, 1632 "CPX_PARAM_SIMDISPLAY" : 1019, 1633 "CPX_PARAM_ITLIM" : 1020, 1634 "CPX_PARAM_ROWREADLIM" : 1021, 1635 "CPX_PARAM_NETFIND" : 1022, 1636 "CPX_PARAM_COLREADLIM" : 1023, 1637 "CPX_PARAM_NZREADLIM" : 1024, 1638 "CPX_PARAM_OBJLLIM" : 1025, 1639 "CPX_PARAM_OBJULIM" : 1026, 1640 "CPX_PARAM_PERIND" : 1027, 1641 "CPX_PARAM_PERLIM" : 1028, 1642 "CPX_PARAM_PPRIIND" : 1029, 1643 "CPX_PARAM_PREIND" : 1030, 1644 "CPX_PARAM_REINV" : 1031, 1645 "CPX_PARAM_REVERSEIND" : 1032, 1646 "CPX_PARAM_RFILEMUL" : 1033, 1647 "CPX_PARAM_SCAIND" : 1034, 1648 "CPX_PARAM_SCRIND" : 1035, 1649 "CPX_PARAM_SINGLIM" : 1037, 1650 "CPX_PARAM_SINGTOL" : 1038, 1651 "CPX_PARAM_TILIM" : 1039, 1652 "CPX_PARAM_XXXIND" : 1041, 1653 "CPX_PARAM_PREDUAL" : 1044, 1654 "CPX_PARAM_EPOPT_H" : 1049, 1655 "CPX_PARAM_EPRHS_H" : 1050, 1656 "CPX_PARAM_PREPASS" : 1052, 1657 "CPX_PARAM_DATACHECK" : 1056, 1658 "CPX_PARAM_REDUCE" : 1057, 1659 "CPX_PARAM_PRELINEAR" : 1058, 1660 "CPX_PARAM_LPMETHOD" : 1062, 1661 "CPX_PARAM_QPMETHOD" : 1063, 1662 "CPX_PARAM_WORKDIR" : 1064, 1663 "CPX_PARAM_WORKMEM" : 1065, 1664 "CPX_PARAM_THREADS" : 1067, 1665 "CPX_PARAM_CONFLICTDISPLAY" : 1074, 1666 "CPX_PARAM_SIFTDISPLAY" : 1076, 1667 "CPX_PARAM_SIFTALG" : 1077, 1668 "CPX_PARAM_SIFTITLIM" : 1078, 1669 "CPX_PARAM_MPSLONGNUM" : 1081, 1670 "CPX_PARAM_MEMORYEMPHASIS" : 1082, 1671 "CPX_PARAM_NUMERICALEMPHASIS" : 1083, 1672 "CPX_PARAM_FEASOPTMODE" : 1084, 1673 "CPX_PARAM_PARALLELMODE" : 1109, 1674 "CPX_PARAM_TUNINGMEASURE" : 1110, 1675 "CPX_PARAM_TUNINGREPEAT" : 1111, 1676 "CPX_PARAM_TUNINGTILIM" : 1112, 1677 "CPX_PARAM_TUNINGDISPLAY" : 1113, 1678 "CPX_PARAM_WRITELEVEL" : 1114, 1679 "CPX_PARAM_ALL_MIN" : 1000, 1680 "CPX_PARAM_ALL_MAX" : 6000, 1681 "CPX_PARAM_BARDSTART" : 3001, 1682 "CPX_PARAM_BAREPCOMP" : 3002, 1683 "CPX_PARAM_BARGROWTH" : 3003, 1684 "CPX_PARAM_BAROBJRNG" : 3004, 1685 "CPX_PARAM_BARPSTART" : 3005, 1686 "CPX_PARAM_BARALG" : 3007, 1687 "CPX_PARAM_BARCOLNZ" : 3009, 1688 "CPX_PARAM_BARDISPLAY" : 3010, 1689 "CPX_PARAM_BARITLIM" : 3012, 1690 "CPX_PARAM_BARMAXCOR" : 3013, 1691 "CPX_PARAM_BARORDER" : 3014, 1692 "CPX_PARAM_BARSTARTALG" : 3017, 1693 "CPX_PARAM_BARCROSSALG" : 3018, 1694 "CPX_PARAM_BARQCPEPCOMP" : 3020, 1695 "CPX_PARAM_BRDIR" : 2001, 1696 "CPX_PARAM_BTTOL" : 2002, 1697 "CPX_PARAM_CLIQUES" : 2003, 1698 "CPX_PARAM_COEREDIND" : 2004, 1699 "CPX_PARAM_COVERS" : 2005, 1700 "CPX_PARAM_CUTLO" : 2006, 1701 "CPX_PARAM_CUTUP" : 2007, 1702 "CPX_PARAM_EPAGAP" : 2008, 1703 "CPX_PARAM_EPGAP" : 2009, 1704 "CPX_PARAM_EPINT" : 2010, 1705 "CPX_PARAM_MIPDISPLAY" : 2012, 1706 "CPX_PARAM_MIPINTERVAL" : 2013, 1707 "CPX_PARAM_INTSOLLIM" : 2015, 1708 "CPX_PARAM_NODEFILEIND" : 2016, 1709 "CPX_PARAM_NODELIM" : 2017, 1710 "CPX_PARAM_NODESEL" : 2018, 1711 "CPX_PARAM_OBJDIF" : 2019, 1712 "CPX_PARAM_MIPORDIND" : 2020, 1713 "CPX_PARAM_RELOBJDIF" : 2022, 1714 "CPX_PARAM_STARTALG" : 2025, 1715 "CPX_PARAM_SUBALG" : 2026, 1716 "CPX_PARAM_TRELIM" : 2027, 1717 "CPX_PARAM_VARSEL" : 2028, 1718 "CPX_PARAM_BNDSTRENIND" : 2029, 1719 "CPX_PARAM_HEURFREQ" : 2031, 1720 "CPX_PARAM_MIPORDTYPE" : 2032, 1721 "CPX_PARAM_CUTSFACTOR" : 2033, 1722 "CPX_PARAM_RELAXPREIND" : 2034, 1723 "CPX_PARAM_PRESLVND" : 2037, 1724 "CPX_PARAM_BBINTERVAL" : 2039, 1725 "CPX_PARAM_FLOWCOVERS" : 2040, 1726 "CPX_PARAM_IMPLBD" : 2041, 1727 "CPX_PARAM_PROBE" : 2042, 1728 "CPX_PARAM_GUBCOVERS" : 2044, 1729 "CPX_PARAM_STRONGCANDLIM" : 2045, 1730 "CPX_PARAM_STRONGITLIM" : 2046, 1731 "CPX_PARAM_FRACCAND" : 2048, 1732 "CPX_PARAM_FRACCUTS" : 2049, 1733 "CPX_PARAM_FRACPASS" : 2050, 1734 "CPX_PARAM_FLOWPATHS" : 2051, 1735 "CPX_PARAM_MIRCUTS" : 2052, 1736 "CPX_PARAM_DISJCUTS" : 2053, 1737 "CPX_PARAM_AGGCUTLIM" : 2054, 1738 "CPX_PARAM_MIPCBREDLP" : 2055 , 1739 "CPX_PARAM_CUTPASS" : 2056, 1740 "CPX_PARAM_MIPEMPHASIS" : 2058, 1741 "CPX_PARAM_SYMMETRY" : 2059, 1742 "CPX_PARAM_DIVETYPE" : 2060, 1743 "CPX_PARAM_RINSHEUR" : 2061, 1744 "CPX_PARAM_SUBMIPNODELIM" : 2062, 1745 "CPX_PARAM_LBHEUR" : 2063, 1746 "CPX_PARAM_REPEATPRESOLVE" : 2064, 1747 "CPX_PARAM_PROBETIME" : 2065, 1748 "CPX_PARAM_POLISHTIME" : 2066, 1749 "CPX_PARAM_REPAIRTRIES" : 2067, 1750 "CPX_PARAM_EPLIN" : 2068, 1751 "CPX_PARAM_EPRELAX" : 2073, 1752 "CPX_PARAM_FPHEUR" : 2098, 1753 "CPX_PARAM_EACHCUTLIM" : 2102, 1754 "CPX_PARAM_SOLNPOOLCAPACITY" : 2103 , 1755 "CPX_PARAM_SOLNPOOLREPLACE" : 2104 , 1756 "CPX_PARAM_SOLNPOOLGAP" : 2105 , 1757 "CPX_PARAM_SOLNPOOLAGAP" : 2106 , 1758 "CPX_PARAM_SOLNPOOLINTENSITY" : 2107, 1759 "CPX_PARAM_POPULATELIM" : 2108, 1760 "CPX_PARAM_MIPSEARCH" : 2109, 1761 "CPX_PARAM_MIQCPSTRAT" : 2110, 1762 "CPX_PARAM_ZEROHALFCUTS" : 2111, 1763 "CPX_PARAM_POLISHAFTEREPAGAP" : 2126, 1764 "CPX_PARAM_POLISHAFTEREPGAP" : 2127, 1765 "CPX_PARAM_POLISHAFTERNODE" : 2128, 1766 "CPX_PARAM_POLISHAFTERINTSOL" : 2129, 1767 "CPX_PARAM_POLISHAFTERTIME" : 2130, 1768 "CPX_PARAM_MCFCUTS" : 2134, 1769 "CPX_PARAM_NETITLIM" : 5001, 1770 "CPX_PARAM_NETEPOPT" : 5002, 1771 "CPX_PARAM_NETEPRHS" : 5003, 1772 "CPX_PARAM_NETPPRIIND" : 5004, 1773 "CPX_PARAM_NETDISPLAY" : 5005, 1774 "CPX_PARAM_QPNZREADLIM" : 4001, 1775 "CPX_PARAM_QPMAKEPSDIND" : 4010, 1776 } -
sage/numerical/backends/generic_backend.pxd
diff --git a/sage/numerical/backends/generic_backend.pxd b/sage/numerical/backends/generic_backend.pxd
a b 35 35 cpdef col_name(self, int index) 36 36 cpdef variable_upper_bound(self, int index, value = *) 37 37 cpdef variable_lower_bound(self, int index, value = *) 38 cpdef solver_parameter(self, name, value=*) 38 39 39 40 cpdef GenericBackend get_solver(constraint_generation = ?, solver = ?) -
sage/numerical/backends/generic_backend.pyx
diff --git a/sage/numerical/backends/generic_backend.pyx b/sage/numerical/backends/generic_backend.pyx
a b 772 772 """ 773 773 raise NotImplementedError() 774 774 775 cpdef solver_parameter(self, name, value = None): 776 """ 777 Return or define a solver parameter 778 779 INPUT: 780 781 - ``name`` (string) -- the parameter 782 783 - ``value`` -- the parameter's value if it is to be defined, 784 or ``None`` (default) to obtain its current value. 785 786 .. NOTE:: 787 788 The list of available parameters is available at 789 :meth:`sage.numerical.mip.MixedIntegerlinearProgram.solver_parameter` 790 791 EXAMPLE:: 792 793 sage: from sage.numerical.backends.generic_backend import get_solver 794 sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver 795 sage: p.solver_parameter("timelimit") # optional - Nonexistent_LP_solver 796 sage: p.solver_parameter("timelimit", 60) # optional - Nonexistent_LP_solver 797 sage: p.solver_parameter("timelimit") # optional - Nonexistent_LP_solver 798 """ 799 raise NotImplementedError() 800 801 775 802 default_solver = None 776 803 777 804 def default_mip_solver(solver = None): -
sage/numerical/backends/glpk_backend.pxd
diff --git a/sage/numerical/backends/glpk_backend.pxd b/sage/numerical/backends/glpk_backend.pxd
a b 25 25 int gmi_cuts 26 26 int fp_heur 27 27 int mir_cuts 28 int tm_lim 28 29 c_glp_iocp * new_c_glp_iocp "new glp_iocp" () 29 30 #void del_c_glp_iocp "del glp_iocp" () 30 31 void glp_init_iocp(c_glp_iocp *) -
sage/numerical/backends/glpk_backend.pyx
diff --git a/sage/numerical/backends/glpk_backend.pyx b/sage/numerical/backends/glpk_backend.pyx
a b 1067 1067 return p 1068 1068 1069 1069 1070 cpdef solver_parameter(self, name, value = None): 1071 """ 1072 Return or define a solver parameter 1073 1074 INPUT: 1075 1076 - ``name`` (string) -- the parameter 1077 1078 - ``value`` -- the parameter's value if it is to be defined, 1079 or ``None`` (default) to obtain its current value. 1080 1081 .. NOTE:: 1082 1083 The list of available parameters is available at 1084 :meth:`sage.numerical.mip.MixedIntegerlinearProgram.solver_parameter` 1085 1086 EXAMPLE:: 1087 1088 sage: from sage.numerical.backends.generic_backend import get_solver 1089 sage: p = get_solver(solver = "GLPK") 1090 sage: p.solver_parameter("timelimit", 60) 1091 sage: p.solver_parameter("timelimit") 1092 60.0 1093 """ 1094 if name == "timelimit": 1095 if value == None: 1096 return self.iocp.tm_lim/1000.0 1097 else: 1098 self.iocp.tm_lim = 1000 * value 1099 1100 else: 1101 raise ValueError("This parameter is not available.") 1102 1070 1103 def __dealloc__(self): 1071 1104 """ 1072 1105 Destructor -
sage/numerical/mip.pyx
diff --git a/sage/numerical/mip.pyx b/sage/numerical/mip.pyx
a b 1350 1350 1351 1351 return self._backend.variable_upper_bound(self._variables[v]) 1352 1352 1353 def solver_parameter(self, name, value = None): 1354 """ 1355 Return or define a solver parameter 1356 1357 The solver parameters are by essence solver-specific, which 1358 means their meaning heavily depends on the solver used. 1359 1360 (If you do not know which solver you are using, then you are using GLPK) 1361 1362 Aliases: 1363 1364 Very common parameters have aliases making them 1365 solver-independent. For example, the following:: 1366 1367 sage: p = MixedIntegerLinearProgram() 1368 sage: p.solver_parameter("timelimit", 60) 1369 1370 Sets the solver to stop its computations after 60 seconds, and 1371 works both with GLPK and CPLEX. 1372 1373 - ``"timelimit"`` -- defines the maximum time spent on a 1374 computation. Measured in seconds. 1375 1376 Solver-specific parameters: 1377 1378 - GLPK : only "timelimit" is available at the moment. 1379 1380 .. NOTE:: 1381 1382 In the case of GLPK, It is very easy to expose more 1383 solver-specific parameters through this method, so if you need 1384 to set a parameter that is not already here complain and/or 1385 write the patch ! 1386 1387 - CPLEX's parameters are identified by a string. Their 1388 list is available `on ILOG's website 1389 <http://publib.boulder.ibm.com/infocenter/odmeinfo/v3r4/index.jsp?topic=/ilog.odms.ide.odme.help/Content/Optimization/Documentation/ODME/_pubskel/ODME_pubskels/startall_ODME34_Eclipse1590.html>`_. 1390 1391 The command :: 1392 1393 sage: p.solver_parameter("CPX_PARAM_TILIM", 60) # optional - CPLEX 1394 1395 works as intended. 1396 1397 INPUT: 1398 1399 - ``name`` (string) -- the parameter 1400 1401 - ``value`` -- the parameter's value if it is to be defined, 1402 or ``None`` (default) to obtain its current value. 1403 1404 EXAMPLE:: 1405 1406 sage: p = MixedIntegerLinearProgram() 1407 sage: p.solver_parameter("timelimit", 60) 1408 sage: p.solver_parameter("timelimit") 1409 60.0 1410 """ 1411 if value is None: 1412 return self._backend.solver_parameter(name) 1413 else: 1414 self._backend.solver_parameter(name, value) 1415 1353 1416 class MIPSolverException(Exception): 1354 1417 r""" 1355 1418 Exception raised when the solver fails.