# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1287677507 -7200
# Node ID fd8eb315d84bb87da5fe93b1d29283157855ee7e
# Parent ea607bb451e79c364ea90f6000d5ba3676341ed4
trac 10150 - Change add_constraint to add_linear_constraint in the new LP interfaces
diff -r ea607bb451e7 -r fd8eb315d84b sage/numerical/backends/coin_backend.pyx
a
|
b
|
|
211 | 211 | msg = model.messageHandler() |
212 | 212 | msg.setLogLevel(level) |
213 | 213 | |
214 | | cpdef add_constraints(self, int number, int direction, double bound): |
| 214 | cpdef add_linear_constraints(self, int number, int direction, double bound): |
215 | 215 | r""" |
216 | 216 | Adds constraints. |
217 | 217 | |
… |
… |
|
235 | 235 | sage: p = get_solver(solver = "Coin") # optional - Coin |
236 | 236 | sage: p.add_variables(5) # optional - Coin |
237 | 237 | 5 |
238 | | sage: p.add_constraints(5, +1, 2) # optional - Coin |
| 238 | sage: p.add_linear_constraints(5, +1, 2) # optional - Coin |
239 | 239 | sage: p.row(4) # optional - Coin |
240 | 240 | ([], []) |
241 | 241 | sage: p.row_bounds(4) # optional - Coin |
… |
… |
|
244 | 244 | |
245 | 245 | cdef int i |
246 | 246 | for 0<= i<number: |
247 | | self.add_constraint([],[],direction, bound) |
| 247 | self.add_linear_constraint([],[],direction, bound) |
248 | 248 | |
249 | | cpdef add_constraint(self, list indices, list coeffs, int direction, double bound): |
| 249 | cpdef add_linear_constraint(self, list indices, list coeffs, int direction, double bound): |
250 | 250 | r""" |
251 | 251 | Adds a linear constraint. |
252 | 252 | |
… |
… |
|
282 | 282 | sage: p = get_solver(solver = "Coin") # optional - Coin |
283 | 283 | sage: p.add_variables(5) # optional - Coin |
284 | 284 | 5 |
285 | | sage: p.add_constraint(range(5), range(5), 0, 2) # optional - Coin |
| 285 | sage: p.add_linear_constraint(range(5), range(5), 0, 2) # optional - Coin |
286 | 286 | sage: p.row(0) # optional - Coin |
287 | 287 | ([0, 1, 2, 3, 4], [0.0, 1.0, 2.0, 3.0, 4.0]) |
288 | 288 | sage: p.row_bounds(0) # optional - Coin |
… |
… |
|
315 | 315 | A pair ``(indices, coeffs)`` where ``indices`` lists the |
316 | 316 | entries whose coefficient is nonzero, and to which ``coeffs`` |
317 | 317 | associates their coefficient on the model of the |
318 | | ``add_constraint`` method. |
| 318 | ``add_linear_constraint`` method. |
319 | 319 | |
320 | 320 | EXAMPLE:: |
321 | 321 | |
… |
… |
|
323 | 323 | sage: p = get_solver(solver = "Coin") # optional - Coin |
324 | 324 | sage: p.add_variables(5) # optional - Coin |
325 | 325 | 5 |
326 | | sage: p.add_constraint(range(5), range(5), 0, 2) # optional - Coin |
| 326 | sage: p.add_linear_constraint(range(5), range(5), 0, 2) # optional - Coin |
327 | 327 | sage: p.row(0) # optional - Coin |
328 | 328 | ([0, 1, 2, 3, 4], [0.0, 1.0, 2.0, 3.0, 4.0]) |
329 | 329 | sage: p.row_bounds(0) # optional - Coin |
… |
… |
|
368 | 368 | sage: p = get_solver(solver = "Coin") # optional - Coin |
369 | 369 | sage: p.add_variables(5) # optional - Coin |
370 | 370 | 5 |
371 | | sage: p.add_constraint(range(5), range(5), 0, 2) # optional - Coin |
| 371 | sage: p.add_linear_constraint(range(5), range(5), 0, 2) # optional - Coin |
372 | 372 | sage: p.row(0) # optional - Coin |
373 | 373 | ([0, 1, 2, 3, 4], [0.0, 1.0, 2.0, 3.0, 4.0]) |
374 | 374 | sage: p.row_bounds(0) # optional - Coin |
… |
… |
|
434 | 434 | sage: p = get_solver(solver = "Coin") # optional - Coin |
435 | 435 | sage: p.add_variables(2) # optional - Coin |
436 | 436 | 2 |
437 | | sage: p.add_constraint([0, 1], [1, 2], +1, 3) # optional - Coin |
| 437 | sage: p.add_linear_constraint([0, 1], [1, 2], +1, 3) # optional - Coin |
438 | 438 | sage: p.set_objective([2, 5]) # optional - Coin |
439 | 439 | sage: p.solve() # optional - Coin |
440 | 440 | 0 |
… |
… |
|
476 | 476 | 0 |
477 | 477 | sage: p.nrows() # optional - Coin |
478 | 478 | 0 |
479 | | sage: p.add_constraints(5, -1, 0) # optional - Coin |
| 479 | sage: p.add_linear_constraints(5, -1, 0) # optional - Coin |
480 | 480 | sage: p.add_col(range(5), range(5)) # optional - Coin |
481 | 481 | sage: p.nrows() # optional - Coin |
482 | 482 | 5 |
… |
… |
|
508 | 508 | |
509 | 509 | sage: from sage.numerical.backends.generic_backend import get_solver |
510 | 510 | sage: p = get_solver(solver = "Coin") # optional - Coin |
511 | | sage: p.add_constraints(5, -1, 0) # optional - Coin |
| 511 | sage: p.add_linear_constraints(5, -1, 0) # optional - Coin |
512 | 512 | sage: p.add_col(range(5), [1,2,3,4,5]) # optional - Coin |
513 | 513 | sage: p.solve() # optional - Coin |
514 | 514 | 0 |
… |
… |
|
519 | 519 | sage: p = get_solver(solver = "Coin") # optional - Coin |
520 | 520 | sage: p.add_variable() # optional - Coin |
521 | 521 | 1 |
522 | | sage: p.add_constraint([0], [1], +1, 4) # optional - Coin |
523 | | sage: p.add_constraint([0], [1], -1, 6) # optional - Coin |
| 522 | sage: p.add_linear_constraint([0], [1], +1, 4) # optional - Coin |
| 523 | sage: p.add_linear_constraint([0], [1], -1, 6) # optional - Coin |
524 | 524 | sage: p.set_objective_coefficient(0,1) # optional - Coin |
525 | 525 | sage: p.solve() # optional - Coin |
526 | 526 | Traceback (most recent call last): |
… |
… |
|
561 | 561 | sage: p = get_solver(solver = "Coin") # optional - Coin |
562 | 562 | sage: p.add_variables(2) # optional - Coin |
563 | 563 | 2 |
564 | | sage: p.add_constraint([0, 1], [1, 2], +1, 3) # optional - Coin |
| 564 | sage: p.add_linear_constraint([0, 1], [1, 2], +1, 3) # optional - Coin |
565 | 565 | sage: p.set_objective([2, 5]) # optional - Coin |
566 | 566 | sage: p.solve() # optional - Coin |
567 | 567 | 0 |
… |
… |
|
589 | 589 | sage: p = get_solver(solver = "Coin") # optional - Coin |
590 | 590 | sage: p.add_variables(2) # optional - Coin |
591 | 591 | 2 |
592 | | sage: p.add_constraint([0, 1], [1, 2], +1, 3) # optional - Coin |
| 592 | sage: p.add_linear_constraint([0, 1], [1, 2], +1, 3) # optional - Coin |
593 | 593 | sage: p.set_objective([2, 5]) # optional - Coin |
594 | 594 | sage: p.solve() # optional - Coin |
595 | 595 | 0 |
… |
… |
|
633 | 633 | sage: p = get_solver(solver = "Coin") # optional - Coin |
634 | 634 | sage: p.nrows() # optional - Coin |
635 | 635 | 0 |
636 | | sage: p.add_constraints(2, -1, 2) # optional - Coin |
| 636 | sage: p.add_linear_constraints(2, -1, 2) # optional - Coin |
637 | 637 | sage: p.nrows() # optional - Coin |
638 | 638 | 2 |
639 | 639 | """ |
… |
… |
|
811 | 811 | sage: p = get_solver(solver = "Coin") # optional - Coin |
812 | 812 | sage: p.add_variables(2) # optional - Coin |
813 | 813 | 2 |
814 | | sage: p.add_constraint([0, 1], [1, 2], +1, 3) # optional - Coin |
| 814 | sage: p.add_linear_constraint([0, 1], [1, 2], +1, 3) # optional - Coin |
815 | 815 | sage: p.set_objective([2, 5]) # optional - Coin |
816 | 816 | sage: p.write_mps(SAGE_TMP+"/lp_problem.mps", 0) # optional - Coin |
817 | 817 | """ |
… |
… |
|
856 | 856 | |
857 | 857 | sage: from sage.numerical.backends.generic_backend import get_solver |
858 | 858 | sage: p = get_solver(solver = "Coin") # optional - Coin |
859 | | sage: p.add_constraints(1, -1, 2) # optional - Coin |
| 859 | sage: p.add_linear_constraints(1, -1, 2) # optional - Coin |
860 | 860 | sage: p.row_name(0, "Empty constraint 1") # optional - Coin |
861 | 861 | sage: print p.row_name(0) # optional - Coin |
862 | 862 | <BLANKLINE> |
diff -r ea607bb451e7 -r fd8eb315d84b sage/numerical/backends/cplex_backend.pyx
a
|
b
|
|
266 | 266 | status = CPXsetintparam (self.env, CPX_PARAM_SCRIND, CPX_ON) |
267 | 267 | check(status) |
268 | 268 | |
269 | | cpdef add_constraints(self, int number, int direction, double bound): |
| 269 | cpdef add_linear_constraints(self, int number, int direction, double bound): |
270 | 270 | r""" |
271 | 271 | Adds constraints. |
272 | 272 | |
… |
… |
|
290 | 290 | sage: p = get_solver(solver = "CPLEX") # optional - CPLEX |
291 | 291 | sage: p.add_variables(5) # optional - CPLEX |
292 | 292 | 5 |
293 | | sage: p.add_constraints(5, +1, 2) # optional - CPLEX |
| 293 | sage: p.add_linear_constraints(5, +1, 2) # optional - CPLEX |
294 | 294 | sage: p.row(4) # optional - CPLEX |
295 | 295 | ([], []) |
296 | 296 | sage: p.row_bounds(4) # optional - CPLEX |
… |
… |
|
319 | 319 | status = CPXnewrows(self.env, self.lp, number, c_bounds, c_types, NULL, NULL) |
320 | 320 | check(status) |
321 | 321 | |
322 | | cpdef add_constraint(self, list indices, list coeffs, int direction, double bound): |
| 322 | cpdef add_linear_constraint(self, list indices, list coeffs, int direction, double bound): |
323 | 323 | r""" |
324 | 324 | Adds a linear constraint. |
325 | 325 | |
… |
… |
|
355 | 355 | sage: p = get_solver(solver = "CPLEX") # optional - CPLEX |
356 | 356 | sage: p.add_variables(5) # optional - CPLEX |
357 | 357 | 5 |
358 | | sage: p.add_constraint(range(5), range(5), 0, 2) # optional - CPLEX |
| 358 | sage: p.add_linear_constraint(range(5), range(5), 0, 2) # optional - CPLEX |
359 | 359 | sage: p.row(0) # optional - CPLEX |
360 | 360 | ([1, 2, 3, 4], [1.0, 2.0, 3.0, 4.0]) |
361 | 361 | sage: p.row_bounds(0) # optional - CPLEX |
… |
… |
|
404 | 404 | A pair ``(indices, coeffs)`` where ``indices`` lists the |
405 | 405 | entries whose coefficient is nonzero, and to which ``coeffs`` |
406 | 406 | associates their coefficient on the model of the |
407 | | ``add_constraint`` method. |
| 407 | ``add_linear_constraint`` method. |
408 | 408 | |
409 | 409 | EXAMPLE:: |
410 | 410 | |
… |
… |
|
412 | 412 | sage: p = get_solver(solver = "CPLEX") # optional - CPLEX |
413 | 413 | sage: p.add_variables(5) # optional - CPLEX |
414 | 414 | 5 |
415 | | sage: p.add_constraint(range(5), range(5), 0, 2) # optional - CPLEX |
| 415 | sage: p.add_linear_constraint(range(5), range(5), 0, 2) # optional - CPLEX |
416 | 416 | sage: p.row(0) # optional - CPLEX |
417 | 417 | ([1, 2, 3, 4], [1.0, 2.0, 3.0, 4.0]) |
418 | 418 | sage: p.row_bounds(0) # optional - CPLEX |
… |
… |
|
461 | 461 | sage: p = get_solver(solver = "CPLEX") # optional - CPLEX |
462 | 462 | sage: p.add_variables(5) # optional - CPLEX |
463 | 463 | 5 |
464 | | sage: p.add_constraint(range(5), range(5), 0, 2) # optional - CPLEX |
| 464 | sage: p.add_linear_constraint(range(5), range(5), 0, 2) # optional - CPLEX |
465 | 465 | sage: p.row(0) # optional - CPLEX |
466 | 466 | ([1, 2, 3, 4], [1.0, 2.0, 3.0, 4.0]) |
467 | 467 | sage: p.row_bounds(0) # optional - CPLEX |
… |
… |
|
583 | 583 | 0 |
584 | 584 | sage: p.nrows() # optional - CPLEX |
585 | 585 | 0 |
586 | | sage: p.add_constraints(5, -1, 0) # optional - CPLEX |
| 586 | sage: p.add_linear_constraints(5, -1, 0) # optional - CPLEX |
587 | 587 | sage: p.add_col(range(5), range(5)) # optional - CPLEX |
588 | 588 | sage: p.nrows() # optional - CPLEX |
589 | 589 | 5 |
… |
… |
|
626 | 626 | |
627 | 627 | sage: from sage.numerical.backends.generic_backend import get_solver |
628 | 628 | sage: p = get_solver(solver = "CPLEX") # optional - CPLEX |
629 | | sage: p.add_constraints(5, -1, 0) # optional - CPLEX |
| 629 | sage: p.add_linear_constraints(5, -1, 0) # optional - CPLEX |
630 | 630 | sage: p.add_col(range(5), range(5)) # optional - CPLEX |
631 | 631 | sage: p.solve() # optional - CPLEX |
632 | 632 | 0 |
… |
… |
|
678 | 678 | sage: p = get_solver(solver = "CPLEX") # optional - CPLEX |
679 | 679 | sage: p.add_variables(2) # optional - CPLEX |
680 | 680 | 2 |
681 | | sage: p.add_constraint([0, 1], [1, 2], +1, 3) # optional - CPLEX |
| 681 | sage: p.add_linear_constraint([0, 1], [1, 2], +1, 3) # optional - CPLEX |
682 | 682 | sage: p.set_objective([2, 5]) # optional - CPLEX |
683 | 683 | sage: p.solve() # optional - CPLEX |
684 | 684 | 0 |
… |
… |
|
712 | 712 | sage: p = get_solver(solver = "CPLEX") # optional - CPLEX |
713 | 713 | sage: p.add_variables(2) # optional - CPLEX |
714 | 714 | 2 |
715 | | sage: p.add_constraint([0, 1], [1, 2], +1, 3) # optional - CPLEX |
| 715 | sage: p.add_linear_constraint([0, 1], [1, 2], +1, 3) # optional - CPLEX |
716 | 716 | sage: p.set_objective([2, 5]) # optional - CPLEX |
717 | 717 | sage: p.solve() # optional - CPLEX |
718 | 718 | 0 |
… |
… |
|
761 | 761 | sage: p = get_solver(solver = "CPLEX") # optional - CPLEX |
762 | 762 | sage: p.nrows() # optional - CPLEX |
763 | 763 | 0 |
764 | | sage: p.add_constraints(2, -1, 2) # optional - CPLEX |
| 764 | sage: p.add_linear_constraints(2, -1, 2) # optional - CPLEX |
765 | 765 | sage: p.nrows() # optional - CPLEX |
766 | 766 | 2 |
767 | 767 | """ |
… |
… |
|
783 | 783 | |
784 | 784 | sage: from sage.numerical.backends.generic_backend import get_solver |
785 | 785 | sage: p = get_solver(solver = "CPLEX") # optional - CPLEX |
786 | | sage: p.add_constraints(1, -1, 2) # optional - CPLEX |
| 786 | sage: p.add_linear_constraints(1, -1, 2) # optional - CPLEX |
787 | 787 | sage: p.row_name(0, "Empty constraint 1") # optional - CPLEX |
788 | 788 | sage: p.row_name(0) # optional - CPLEX |
789 | 789 | 'Empty constraint 1' |
… |
… |
|
1080 | 1080 | sage: p = get_solver(solver = "CPLEX") # optional - CPLEX |
1081 | 1081 | sage: p.add_variables(2) # optional - CPLEX |
1082 | 1082 | 2 |
1083 | | sage: p.add_constraint([0, 1], [1, 2], +1, 3) # optional - CPLEX |
| 1083 | sage: p.add_linear_constraint([0, 1], [1, 2], +1, 3) # optional - CPLEX |
1084 | 1084 | sage: p.set_objective([2, 5]) # optional - CPLEX |
1085 | 1085 | sage: p.write_lp(SAGE_TMP+"/lp_problem.lp") # optional - CPLEX |
1086 | 1086 | """ |
… |
… |
|
1104 | 1104 | sage: p = get_solver(solver = "CPLEX") # optional - CPLEX |
1105 | 1105 | sage: p.add_variables(2) # optional - CPLEX |
1106 | 1106 | 2 |
1107 | | sage: p.add_constraint([0, 1], [1, 2], +1, 3) # optional - CPLEX |
| 1107 | sage: p.add_linear_constraint([0, 1], [1, 2], +1, 3) # optional - CPLEX |
1108 | 1108 | sage: p.set_objective([2, 5]) # optional - CPLEX |
1109 | 1109 | sage: p.write_lp(SAGE_TMP+"/lp_problem.lp") # optional - CPLEX |
1110 | 1110 | """ |
diff -r ea607bb451e7 -r fd8eb315d84b sage/numerical/backends/generic_backend.pxd
a
|
b
|
|
13 | 13 | cpdef set_objective_coefficient(self, int variable, double coeff) |
14 | 14 | cpdef set_objective(self, list coeff) |
15 | 15 | cpdef set_verbosity(self, int level) |
16 | | cpdef add_constraint(self, list indices, list coeffs, int direction, double bound) |
| 16 | cpdef add_linear_constraint(self, list indices, list coeffs, int direction, double bound) |
17 | 17 | cpdef add_col(self, list indices, list coeffs) |
18 | | cpdef add_constraints(self, int number, int direction, double bound) |
| 18 | cpdef add_linear_constraints(self, int number, int direction, double bound) |
19 | 19 | cpdef int solve(self) except -1 |
20 | 20 | cpdef double get_objective_value(self) |
21 | 21 | cpdef double get_variable_value(self, int variable) |
diff -r ea607bb451e7 -r fd8eb315d84b sage/numerical/backends/generic_backend.pyx
a
|
b
|
|
186 | 186 | |
187 | 187 | raise NotImplementedError() |
188 | 188 | |
189 | | cpdef add_constraint(self, list indices, list coeffs, int direction, double bound): |
| 189 | cpdef add_linear_constraint(self, list indices, list coeffs, int direction, double bound): |
190 | 190 | r""" |
191 | 191 | Adds a linear constraint. |
192 | 192 | |
… |
… |
|
222 | 222 | sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver |
223 | 223 | sage: p.add_variables(5) # optional - Nonexistent_LP_solver |
224 | 224 | 5 |
225 | | sage: p.add_constraint(range(5), range(5), 0, 2) # optional - Nonexistent_LP_solver |
| 225 | sage: p.add_linear_constraint(range(5), range(5), 0, 2) # optional - Nonexistent_LP_solver |
226 | 226 | sage: p.row(0) # optional - Nonexistent_LP_solver |
227 | 227 | ([4, 3, 2, 1], [4.0, 3.0, 2.0, 1.0]) |
228 | 228 | sage: p.row_bounds(0) # optional - Nonexistent_LP_solver |
… |
… |
|
259 | 259 | 0 |
260 | 260 | sage: p.nrows() # optional - Nonexistent_LP_solver |
261 | 261 | 0 |
262 | | sage: p.add_constraints(5, -1, 0) # optional - Nonexistent_LP_solver |
| 262 | sage: p.add_linear_constraints(5, -1, 0) # optional - Nonexistent_LP_solver |
263 | 263 | sage: p.add_col(range(5), range(5)) # optional - Nonexistent_LP_solver |
264 | 264 | sage: p.nrows() # optional - Nonexistent_LP_solver |
265 | 265 | 5 |
… |
… |
|
267 | 267 | |
268 | 268 | raise NotImplementedError() |
269 | 269 | |
270 | | cpdef add_constraints(self, int number, int direction, double bound): |
| 270 | cpdef add_linear_constraints(self, int number, int direction, double bound): |
271 | 271 | r""" |
272 | 272 | Adds constraints. |
273 | 273 | |
… |
… |
|
291 | 291 | sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver |
292 | 292 | sage: p.add_variables(5) # optional - Nonexistent_LP_solver |
293 | 293 | 5 |
294 | | sage: p.add_constraints(5, +1, 2) # optional - Nonexistent_LP_solver |
| 294 | sage: p.add_linear_constraints(5, +1, 2) # optional - Nonexistent_LP_solver |
295 | 295 | sage: p.row(4) # optional - Nonexistent_LP_solver |
296 | 296 | ([], []) |
297 | 297 | sage: p.row_bounds(4) # optional - Nonexistent_LP_solver |
… |
… |
|
314 | 314 | |
315 | 315 | sage: from sage.numerical.backends.generic_backend import get_solver |
316 | 316 | sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver |
317 | | sage: p.add_constraints(5, -1, 0) # optional - Nonexistent_LP_solver |
| 317 | sage: p.add_linear_constraints(5, -1, 0) # optional - Nonexistent_LP_solver |
318 | 318 | sage: p.add_col(range(5), range(5)) # optional - Nonexistent_LP_solver |
319 | 319 | sage: p.solve() # optional - Nonexistent_LP_solver |
320 | 320 | 0 |
… |
… |
|
340 | 340 | sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver |
341 | 341 | sage: p.add_variables(2) # optional - Nonexistent_LP_solver |
342 | 342 | 2 |
343 | | sage: p.add_constraint([0, 1], [1, 2], +1, 3) # optional - Nonexistent_LP_solver |
| 343 | sage: p.add_linear_constraint([0, 1], [1, 2], +1, 3) # optional - Nonexistent_LP_solver |
344 | 344 | sage: p.set_objective([2, 5]) # optional - Nonexistent_LP_solver |
345 | 345 | sage: p.solve() # optional - Nonexistent_LP_solver |
346 | 346 | 0 |
… |
… |
|
368 | 368 | sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver |
369 | 369 | sage: p.add_variables(2) # optional - Nonexistent_LP_solver |
370 | 370 | 2 |
371 | | sage: p.add_constraint([0, 1], [1, 2], +1, 3) # optional - Nonexistent_LP_solver |
| 371 | sage: p.add_linear_constraint([0, 1], [1, 2], +1, 3) # optional - Nonexistent_LP_solver |
372 | 372 | sage: p.set_objective([2, 5]) # optional - Nonexistent_LP_solver |
373 | 373 | sage: p.solve() # optional - Nonexistent_LP_solver |
374 | 374 | 0 |
… |
… |
|
410 | 410 | sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver |
411 | 411 | sage: p.nrows() # optional - Nonexistent_LP_solver |
412 | 412 | 0 |
413 | | sage: p.add_constraints(2, -1, 2) # optional - Nonexistent_LP_solver |
| 413 | sage: p.add_linear_constraints(2, -1, 2) # optional - Nonexistent_LP_solver |
414 | 414 | sage: p.nrows() # optional - Nonexistent_LP_solver |
415 | 415 | 2 |
416 | 416 | """ |
… |
… |
|
470 | 470 | sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver |
471 | 471 | sage: p.add_variables(2) # optional - Nonexistent_LP_solver |
472 | 472 | 2 |
473 | | sage: p.add_constraint([0, 1], [1, 2], +1, 3) # optional - Nonexistent_LP_solver |
| 473 | sage: p.add_linear_constraint([0, 1], [1, 2], +1, 3) # optional - Nonexistent_LP_solver |
474 | 474 | sage: p.set_objective([2, 5]) # optional - Nonexistent_LP_solver |
475 | 475 | sage: p.write_lp(SAGE_TMP+"/lp_problem.lp") # optional - Nonexistent_LP_solver |
476 | 476 | """ |
… |
… |
|
490 | 490 | sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver |
491 | 491 | sage: p.add_variables(2) # optional - Nonexistent_LP_solver |
492 | 492 | 2 |
493 | | sage: p.add_constraint([0, 1], [1, 2], +1, 3) # optional - Nonexistent_LP_solver |
| 493 | sage: p.add_linear_constraint([0, 1], [1, 2], +1, 3) # optional - Nonexistent_LP_solver |
494 | 494 | sage: p.set_objective([2, 5]) # optional - Nonexistent_LP_solver |
495 | 495 | sage: p.write_lp(SAGE_TMP+"/lp_problem.lp") # optional - Nonexistent_LP_solver |
496 | 496 | """ |
… |
… |
|
509 | 509 | A pair ``(indices, coeffs)`` where ``indices`` lists the |
510 | 510 | entries whose coefficient is nonzero, and to which ``coeffs`` |
511 | 511 | associates their coefficient on the model of the |
512 | | ``add_constraint`` method. |
| 512 | ``add_linear_constraint`` method. |
513 | 513 | |
514 | 514 | EXAMPLE:: |
515 | 515 | |
… |
… |
|
517 | 517 | sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver |
518 | 518 | sage: p.add_variables(5) # optional - Nonexistent_LP_solver |
519 | 519 | 5 |
520 | | sage: p.add_constraint(range(5), range(5), 0, 2) # optional - Nonexistent_LP_solver |
| 520 | sage: p.add_linear_constraint(range(5), range(5), 0, 2) # optional - Nonexistent_LP_solver |
521 | 521 | sage: p.row(0) # optional - Nonexistent_LP_solver |
522 | 522 | ([4, 3, 2, 1], [4.0, 3.0, 2.0, 1.0]) |
523 | 523 | sage: p.row_bounds(0) # optional - Nonexistent_LP_solver |
… |
… |
|
571 | 571 | sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver |
572 | 572 | sage: p.add_variables(5) # optional - Nonexistent_LP_solver |
573 | 573 | 5 |
574 | | sage: p.add_constraint(range(5), range(5), 0, 2) # optional - Nonexistent_LP_solver |
| 574 | sage: p.add_linear_constraint(range(5), range(5), 0, 2) # optional - Nonexistent_LP_solver |
575 | 575 | sage: p.row(0) # optional - Nonexistent_LP_solver |
576 | 576 | ([4, 3, 2, 1], [4.0, 3.0, 2.0, 1.0]) |
577 | 577 | sage: p.row_bounds(0) # optional - Nonexistent_LP_solver |
… |
… |
|
696 | 696 | |
697 | 697 | sage: from sage.numerical.backends.generic_backend import get_solver |
698 | 698 | sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver |
699 | | sage: p.add_constraints(1, -1, 2) # optional - Nonexistent_LP_solver |
| 699 | sage: p.add_linear_constraints(1, -1, 2) # optional - Nonexistent_LP_solver |
700 | 700 | sage: p.row_name(0, "Empty constraint 1") # optional - Nonexistent_LP_solver |
701 | 701 | sage: p.row_name(0) # optional - Nonexistent_LP_solver |
702 | 702 | 'Empty constraint 1' |
diff -r ea607bb451e7 -r fd8eb315d84b sage/numerical/backends/glpk_backend.pyx
a
|
b
|
|
266 | 266 | else: |
267 | 267 | self.iocp.msg_lev = GLP_MSG_ALL |
268 | 268 | |
269 | | cpdef add_constraints(self, int number, int direction, double bound): |
| 269 | cpdef add_linear_constraints(self, int number, int direction, double bound): |
270 | 270 | r""" |
271 | 271 | Adds constraints. |
272 | 272 | |
… |
… |
|
290 | 290 | sage: p = get_solver(solver = "GLPK") |
291 | 291 | sage: p.add_variables(5) |
292 | 292 | 5 |
293 | | sage: p.add_constraints(5, +1, 2) |
| 293 | sage: p.add_linear_constraints(5, +1, 2) |
294 | 294 | sage: p.row(4) |
295 | 295 | ([], []) |
296 | 296 | sage: p.row_bounds(4) |
… |
… |
|
311 | 311 | for 0<= i < number: |
312 | 312 | glp_set_row_bnds(self.lp, n-i, direction, bound, bound) |
313 | 313 | |
314 | | cpdef add_constraint(self, list indices, list coeffs, int direction, double bound): |
| 314 | cpdef add_linear_constraint(self, list indices, list coeffs, int direction, double bound): |
315 | 315 | r""" |
316 | 316 | Adds a linear constraint. |
317 | 317 | |
… |
… |
|
347 | 347 | sage: p = get_solver(solver = "GLPK") |
348 | 348 | sage: p.add_variables(5) |
349 | 349 | 5 |
350 | | sage: p.add_constraint(range(5), range(5), 0, 2) |
| 350 | sage: p.add_linear_constraint(range(5), range(5), 0, 2) |
351 | 351 | sage: p.row(0) |
352 | 352 | ([4, 3, 2, 1], [4.0, 3.0, 2.0, 1.0]) |
353 | 353 | sage: p.row_bounds(0) |
… |
… |
|
391 | 391 | A pair ``(indices, coeffs)`` where ``indices`` lists the |
392 | 392 | entries whose coefficient is nonzero, and to which ``coeffs`` |
393 | 393 | associates their coefficient on the model of the |
394 | | ``add_constraint`` method. |
| 394 | ``add_linear_constraint`` method. |
395 | 395 | |
396 | 396 | EXAMPLE:: |
397 | 397 | |
… |
… |
|
399 | 399 | sage: p = get_solver(solver = "GLPK") |
400 | 400 | sage: p.add_variables(5) |
401 | 401 | 5 |
402 | | sage: p.add_constraint(range(5), range(5), 0, 2) |
| 402 | sage: p.add_linear_constraint(range(5), range(5), 0, 2) |
403 | 403 | sage: p.row(0) |
404 | 404 | ([4, 3, 2, 1], [4.0, 3.0, 2.0, 1.0]) |
405 | 405 | sage: p.row_bounds(0) |
… |
… |
|
442 | 442 | sage: p = get_solver(solver = "GLPK") |
443 | 443 | sage: p.add_variables(5) |
444 | 444 | 5 |
445 | | sage: p.add_constraint(range(5), range(5), 0, 2) |
| 445 | sage: p.add_linear_constraint(range(5), range(5), 0, 2) |
446 | 446 | sage: p.row(0) |
447 | 447 | ([4, 3, 2, 1], [4.0, 3.0, 2.0, 1.0]) |
448 | 448 | sage: p.row_bounds(0) |
… |
… |
|
550 | 550 | 0 |
551 | 551 | sage: p.nrows() |
552 | 552 | 0 |
553 | | sage: p.add_constraints(5, -1, 0) |
| 553 | sage: p.add_linear_constraints(5, -1, 0) |
554 | 554 | sage: p.add_col(range(5), range(5)) |
555 | 555 | sage: p.nrows() |
556 | 556 | 5 |
… |
… |
|
588 | 588 | |
589 | 589 | sage: from sage.numerical.backends.generic_backend import get_solver |
590 | 590 | sage: p = get_solver(solver = "GLPK") |
591 | | sage: p.add_constraints(5, -1, 0) |
| 591 | sage: p.add_linear_constraints(5, -1, 0) |
592 | 592 | sage: p.add_col(range(5), range(5)) |
593 | 593 | sage: p.solve() |
594 | 594 | 0 |
… |
… |
|
627 | 627 | sage: p = get_solver(solver = "GLPK") |
628 | 628 | sage: p.add_variables(2) |
629 | 629 | 2 |
630 | | sage: p.add_constraint([0, 1], [1, 2], +1, 3) |
| 630 | sage: p.add_linear_constraint([0, 1], [1, 2], +1, 3) |
631 | 631 | sage: p.set_objective([2, 5]) |
632 | 632 | sage: p.solve() |
633 | 633 | 0 |
… |
… |
|
654 | 654 | sage: p = get_solver(solver = "GLPK") |
655 | 655 | sage: p.add_variables(2) |
656 | 656 | 2 |
657 | | sage: p.add_constraint([0, 1], [1, 2], +1, 3) |
| 657 | sage: p.add_linear_constraint([0, 1], [1, 2], +1, 3) |
658 | 658 | sage: p.set_objective([2, 5]) |
659 | 659 | sage: p.solve() |
660 | 660 | 0 |
… |
… |
|
694 | 694 | sage: p = get_solver(solver = "GLPK") |
695 | 695 | sage: p.nrows() |
696 | 696 | 0 |
697 | | sage: p.add_constraints(2, -1, 2) |
| 697 | sage: p.add_linear_constraints(2, -1, 2) |
698 | 698 | sage: p.nrows() |
699 | 699 | 2 |
700 | 700 | """ |
… |
… |
|
750 | 750 | |
751 | 751 | sage: from sage.numerical.backends.generic_backend import get_solver |
752 | 752 | sage: p = get_solver(solver = "GLPK") |
753 | | sage: p.add_constraints(1, -1, 2) |
| 753 | sage: p.add_linear_constraints(1, -1, 2) |
754 | 754 | sage: p.row_name(0, "Empty constraint 1") |
755 | 755 | sage: p.row_name(0) |
756 | 756 | 'Empty constraint 1' |
… |
… |
|
974 | 974 | sage: p = get_solver(solver = "GLPK") |
975 | 975 | sage: p.add_variables(2) |
976 | 976 | 2 |
977 | | sage: p.add_constraint([0, 1], [1, 2], +1, 3) |
| 977 | sage: p.add_linear_constraint([0, 1], [1, 2], +1, 3) |
978 | 978 | sage: p.set_objective([2, 5]) |
979 | 979 | sage: p.write_lp(SAGE_TMP+"/lp_problem.lp") |
980 | 980 | """ |
… |
… |
|
994 | 994 | sage: p = get_solver(solver = "GLPK") |
995 | 995 | sage: p.add_variables(2) |
996 | 996 | 2 |
997 | | sage: p.add_constraint([0, 1], [1, 2], +1, 3) |
| 997 | sage: p.add_linear_constraint([0, 1], [1, 2], +1, 3) |
998 | 998 | sage: p.set_objective([2, 5]) |
999 | 999 | sage: p.write_lp(SAGE_TMP+"/lp_problem.lp") |
1000 | 1000 | """ |
diff -r ea607bb451e7 -r fd8eb315d84b sage/numerical/mip.pyx
a
|
b
|
|
753 | 753 | if min == None and max == None: |
754 | 754 | raise ValueError("Both max and min are set to None ? Weird !") |
755 | 755 | elif min == max: |
756 | | self._backend.add_constraint(indices, values, 0, min) |
| 756 | self._backend.add_linear_constraint(indices, values, 0, min) |
757 | 757 | elif min != None: |
758 | | self._backend.add_constraint(indices, values, -1, min) |
| 758 | self._backend.add_linear_constraint(indices, values, -1, min) |
759 | 759 | elif max != None: |
760 | | self._backend.add_constraint(indices, values, +1, max) |
| 760 | self._backend.add_linear_constraint(indices, values, +1, max) |
761 | 761 | |
762 | 762 | if name != None: |
763 | 763 | self._backend.row_name(self._backend.nrows()-1,name) |