Ticket #12823: trac_12823_alternate_removal.patch
File trac_12823_alternate_removal.patch, 34.7 KB (added by , 9 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 252 252 253 253 - ``constraints`` -- an iterable containing the indices of the rows to remove. 254 254 """ 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 256 264 257 265 cpdef add_linear_constraint(self, coefficients, lower_bound, upper_bound, name=None): 258 266 """ -
sage/numerical/backends/glpk_backend.pxd
diff --git a/sage/numerical/backends/glpk_backend.pxd b/sage/numerical/backends/glpk_backend.pxd
a b 20 20 ctypedef struct c_glp_prob "glp_prob": 21 21 pass 22 22 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 23 38 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 29 40 ctypedef struct c_glp_smcp "glp_smcp": 30 41 int msg_lev 31 42 int meth … … 41 52 int out_frq 42 53 int out_dly 43 54 int presolve 44 double foo_bar[36]45 55 c_glp_iocp * new_c_glp_iocp "new glp_iocp" () 46 56 #void del_c_glp_iocp "del glp_iocp" () 47 57 void glp_init_iocp(c_glp_iocp *) … … 106 116 int glp_get_obj_dir(c_glp_prob *lp) 107 117 void glp_copy_prob(c_glp_prob *dst, c_glp_prob *src, int names) 108 118 119 # constants 109 120 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 110 141 111 142 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 112 184 int GLP_MAX 113 185 int GLP_MIN 114 186 int GLP_UP … … 119 191 int GLP_CV 120 192 int GLP_IV 121 193 int GLP_BV 122 int GLP_MSG_OFF123 int GLP_MSG_ERR124 int GLP_MSG_ON125 int GLP_MSG_ALL126 194 int GLP_MPS_DECK 127 195 int GLP_MPS_FILE 128 196 129 int GLP_UNDEF130 int GLP_OPT131 int GLP_FEAS132 int GLP_NOFEAS133 134 197 int GLP_MSG_DBG 135 int GLP_PRIMAL136 int GLP_DUALP137 int GLP_DUAL138 int GLP_PT_STD139 int GLP_PT_PSE140 int GLP_RT_STD141 int GLP_RT_HAR142 198 143 199 cdef class GLPKBackend(GenericBackend): 144 200 cdef c_glp_prob * lp 145 201 cdef c_glp_iocp * iocp 146 202 cdef c_glp_smcp * smcp 147 cdef int preprocessing203 cdef int simplex_or_intopt 148 204 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 5 5 6 6 - Nathann Cohen (2010-10): initial implementation 7 7 - John Perry (2012-01): glp_simplex preprocessing 8 - John Perry and Raniere Gaia Silva (2012-03): solver parameters 8 9 """ 9 10 10 11 ############################################################################## … … 29 30 sage: p = MixedIntegerLinearProgram(solver="GLPK") 30 31 """ 31 32 self.lp = glp_create_prob() 32 self. preprocessing = 033 self.simplex_or_intopt = glp_intopt_only 33 34 self.smcp = <c_glp_smcp* > sage_malloc(sizeof(c_glp_smcp)) 34 35 glp_init_smcp(self.smcp) 35 36 self.iocp = <c_glp_iocp* > sage_malloc(sizeof(c_glp_iocp)) … … 773 774 Traceback (most recent call last): 774 775 ... 775 776 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") 777 778 sage: lp.solve() 778 779 Traceback (most recent call last): 779 780 ... 780 781 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] 781 806 """ 782 807 783 808 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: 785 810 status = glp_simplex(self.lp, self.smcp) 786 811 status = glp_get_prim_stat(self.lp) 787 812 if status == GLP_OPT or status == GLP_FEAS: … … 789 814 elif status == GLP_UNDEF or status == GLP_NOFEAS: 790 815 raise MIPSolverException("GLPK : Simplex cannot find a feasible solution") 791 816 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") 795 824 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") 805 838 806 839 return 0 807 840 … … 830 863 sage: p.get_variable_value(1) 831 864 1.5 832 865 """ 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) 834 870 835 871 cpdef double get_variable_value(self, int variable): 836 872 """ … … 856 892 0.0 857 893 sage: p.get_variable_value(1) 858 894 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) 861 900 862 901 cpdef int ncols(self): 863 902 """ … … 1192 1231 6.0 1193 1232 """ 1194 1233 cdef GLPKBackend p = GLPKBackend(maximization = (1 if self.is_maximization() else -1)) 1195 p. preprocessing = self.preprocessing1234 p.simplex_or_intopt = self.simplex_or_intopt 1196 1235 p.iocp.tm_lim = self.iocp.tm_lim 1197 1236 glp_copy_prob(p.lp, self.lp, 1) 1198 1237 return p … … 1209 1248 - ``value`` -- the parameter's value if it is to be defined, 1210 1249 or ``None`` (default) to obtain its current value. 1211 1250 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 1212 1380 .. NOTE:: 1213 1381 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. 1216 1386 1217 1387 EXAMPLE:: 1218 1388 … … 1221 1391 sage: p.solver_parameter("timelimit", 60) 1222 1392 sage: p.solver_parameter("timelimit") 1223 1393 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. 1224 1440 """ 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 1228 1455 else: 1229 self.iocp.tm_lim = 1000 * value 1456 self.iocp.tm_lim = value * 1000.0 1457 self.smcp.tm_lim = value * 1000.0 1230 1458 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 1234 1490 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 1238 1619 1239 1620 else: 1240 1621 raise ValueError("This parameter is not available.") … … 1246 1627 glp_delete_prob(self.lp) 1247 1628 sage_free(self.iocp) 1248 1629 sage_free(self.smcp) 1630 1631 # parameter names 1632 1633 cdef 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 1642 glp_tm_lim_simplex = timelimit_simplex 1643 glp_tm_lim_intopt = timelimit_intopt 1644 glp_simplex_or_intopt = simplex_or_intopt 1645 glp_msg_lev_intopt = glp_verbosity_intopt = msg_lev_intopt 1646 glp_msg_lev_simplex = glp_verbosity_simplex = msg_lev_simplex 1647 glp_br_tech = glp_branching = br_tech 1648 glp_bt_tech = glp_backtracking = bt_tech 1649 glp_pp_tech = glp_preprocessing = pp_tech 1650 glp_fp_heur = glp_feasibility_pump = fp_heur 1651 glp_gmi_cuts = glp_gomory_cuts = gmi_cuts 1652 glp_mir_cuts = glp_mixed_int_rounding_cuts = mir_cuts 1653 glp_cov_cuts = glp_mixed_cover_cuts = cov_cuts 1654 glp_clq_cuts = glp_clique_cuts = clq_cuts 1655 glp_tol_int = glp_absolute_tolerance = tol_int 1656 glp_tol_obj = glp_relative_tolerance = tol_obj 1657 glp_mip_gap = glp_mip_gap_tolerance = mip_gap 1658 glp_out_frq_intopt = glp_output_frequency_intopt = out_frq_intopt 1659 glp_out_dly_intopt = glp_output_delay_intopt = out_dly_intopt 1660 glp_presolve_intopt = presolve_intopt 1661 glp_binarize = binarize 1662 glp_meth = glp_primal_v_dual = meth 1663 glp_pricing = pricing 1664 glp_r_test = glp_ratio_test = r_test 1665 glp_tol_bnd = glp_tolerance_primal = tol_bnd 1666 glp_tol_dj = glp_tolerance_dual = tol_dj 1667 glp_tol_piv = glp_tolerance_pivot = tol_piv 1668 glp_obj_ll = glp_obj_lower_limit = obj_ll 1669 glp_obj_ul = glp_obj_upper_limit = obj_ul 1670 glp_it_lim = glp_iteration_limit = it_lim 1671 glp_out_frq_simplex = glp_output_frequency_intopt = out_frq_simplex 1672 glp_out_dly_simplex = glp_output_delay_simplex = out_dly_simplex 1673 glp_presolve_simplex = presolve_simplex 1674 1675 solver_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 1714 glp_msg_off = GLP_MSG_OFF 1715 glp_msg_on = GLP_MSG_ON 1716 glp_msg_err = GLP_MSG_ERR 1717 glp_msg_all = GLP_MSG_ALL 1718 glp_msg_dbg = GLP_MSG_DBG 1719 1720 glp_primal = GLP_PRIMAL 1721 glp_dual = GLP_DUAL 1722 glp_dualp = GLP_DUALP 1723 1724 glp_pt_std = GLP_PT_STD 1725 glp_pt_pse = GLP_PT_PSE 1726 1727 glp_rt_std = GLP_RT_STD 1728 glp_rt_har = GLP_RT_HAR 1729 1730 dbl_max = DBL_MAX 1731 int_max = INT_MAX 1732 1733 glp_on = GLP_ON 1734 glp_off = GLP_OFF 1735 1736 glp_br_ffv = GLP_BR_FFV 1737 glp_br_lfv = GLP_BR_LFV 1738 glp_br_mfv = GLP_BR_MFV 1739 glp_br_dth = GLP_BR_DTH 1740 glp_br_pch = GLP_BR_PCH 1741 1742 glp_bt_dfs = GLP_BT_DFS 1743 glp_bt_bfs = GLP_BT_BFS 1744 glp_bt_blb = GLP_BT_BLB 1745 glp_bt_bph = GLP_BT_BPH 1746 1747 glp_pp_none = GLP_PP_NONE 1748 glp_pp_root = GLP_PP_ROOT 1749 glp_pp_all = GLP_PP_ALL 1750 1751 glp_max = GLP_MAX 1752 glp_min = GLP_MIN 1753 glp_up = GLP_UP 1754 glp_fr = GLP_FR 1755 glp_db = GLP_DB 1756 glp_fx = GLP_FX 1757 glp_lo = GLP_LO 1758 glp_cv = GLP_CV 1759 glp_iv = GLP_IV 1760 glp_bv = GLP_BV 1761 glp_mps_deck = GLP_MPS_DECK 1762 glp_mps_file = GLP_MPS_FILE 1763 1764 glp_undef = GLP_UNDEF 1765 glp_opt = GLP_OPT 1766 glp_feas = GLP_FEAS 1767 glp_nofeas = GLP_NOFEAS 1768 1769 cdef enum more_parameter_values: 1770 simplex_only, simplex_then_intopt, intopt_only 1771 1772 glp_simplex_only = simplex_only 1773 glp_simplex_then_intopt = simplex_then_intopt 1774 glp_intopt_only = intopt_only 1775 1776 # dictionaries for those who prefer to use strings 1777 1778 solver_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 1038 1038 self.add_constraint(functions[0] - functions[1], max=0, name=name) 1039 1039 self.add_constraint(functions[1] - functions[2], max=0, name=name) 1040 1040 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.01063 x_0 - x_1 <= 0.01064 x_0 <= 4.01065 ...1066 sage: p.number_of_constraints()1067 31068 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 first1075 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 1080 1041 def remove_constraints(self, constraints): 1081 1042 """ 1082 1043 Remove several constraints. … … 1329 1290 1330 1291 return self._backend.is_variable_continuous(self._variables[e]) 1331 1292 1332 def solve(self, solver=None, log= 0, objective_only=False):1293 def solve(self, solver=None, log=None, objective_only=False): 1333 1294 r""" 1334 1295 Solves the ``MixedIntegerLinearProgram``. 1335 1296 … … 1406 1367 if solver != None: 1407 1368 raise ValueError("Solver argument deprecated. This parameter now has to be set when calling the class' constructor") 1408 1369 1409 self._backend.set_verbosity(log)1370 if log != None: self._backend.set_verbosity(log) 1410 1371 1411 1372 self._backend.solve() 1412 1373 … … 1543 1504 1544 1505 Solver-specific parameters: 1545 1506 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`. 1554 1511 1555 1512 - CPLEX's parameters are identified by a string. Their 1556 1513 list is available `on ILOG's website … … 2267 2224 2268 2225 self.constraints = other.constraints + self.constraints 2269 2226 return self 2227