#12823: Allow constants for objective function & deletion of rows in
MixedIntegerLinearProgram
--------------------------------------+-------------------------------------
Reporter: john_perry | Owner: ncohen
Type: defect | Status: needs_info
Priority: major | Milestone: sage-5.0
Component: linear programming | Resolution:
Keywords: solver objective | Work issues: failing doctests
Report Upstream: N/A | Reviewers:
Authors: john_perry, ncohen | Merged in:
Dependencies: 12833 | Stopgaps:
--------------------------------------+-------------------------------------
Comment (by dcoudert):
Hello,
Nathann asks me to pass some tests. So I tried the patchs with
sage-5.0-beta13
First, I don't understand the install messages.
{{{
compote:~/path-to-sage/devel/sage-myclone> hg qimport ~/Recherche/sage-
patchs/trac_12823_const_for_obj_funs.patch
adding trac_12823_const_for_obj_funs.patch to series file
compote:~/path-to-sage/devel/sage-myclone> hg qpush
applying trac_12823_const_for_obj_funs.patch
now at: trac_12823_const_for_obj_funs.patch
compote:~/path-to-sage/devel/sage-myclone> hg qimport ~/Recherche/sage-
patchs/trac_12823-cplex_gurobi.patch
adding trac_12823-cplex_gurobi.patch to series file
compote:~/Soft/sage-5.0.beta13/devel/sage-myclone> hg qpush
applying trac_12823-cplex_gurobi.patch
patching file sage/numerical/backends/gurobi_backend.pyx
Hunk #2 succeeded at 410 with fuzz 2 (offset -13 lines).
Hunk #3 succeeded at 418 with fuzz 1 (offset -13 lines).
Hunk #4 succeeded at 431 with fuzz 2 (offset -13 lines).
Hunk #7 succeeded at 785 with fuzz 1 (offset -12 lines).
now at: trac_12823-cplex_gurobi.patch
}}}
I don't have coin or gurobi, so I tried only glpk and cplex
{{{
~/path-to-sage/devel/sage-myclone>../../sage -t optional
sage/numerical/backends/cplex_backend.pyx
sage -t -optional "devel/sage-
myclone/sage/numerical/backends/cplex_backend.pyx"
[1.2 s]
----------------------------------------------------------------------
All tests passed!
Total time for all tests: 1.2 seconds
~/path-to-sage/devel/sage-myclone>../../sage -t optional
sage/numerical/backends/glpk_backend.pyx
sage -t -optional "devel/sage-
myclone/sage/numerical/backends/glpk_backend.pyx"
[1.1 s]
----------------------------------------------------------------------
All tests passed!
Total time for all tests: 1.1 seconds
}}}
Then I tried the alternate patch but it fails to apply
{{{
compote:~/path-to-sage/devel/sage-myclone> hg qapplied
compote:~/path-to-sage/devel/sage-myclone> hg qimport ~/path-to-
patchs/trac_12823_alternate_removal.patch
adding trac_12823_alternate_removal.patch to series file
compote:~/path-to-sage/devel/sage-myclone> hg qpush
applying trac_12823_alternate_removal.patch
patching file sage/numerical/backends/generic_backend.pyx
Hunk #1 FAILED at 251
1 out of 1 hunks FAILED -- saving rejects to file
sage/numerical/backends/generic_backend.pyx.rej
patching file sage/numerical/mip.pyx
Hunk #1 FAILED at 1037
1 out of 5 hunks FAILED -- saving rejects to file
sage/numerical/mip.pyx.rej
patch failed, unable to continue (try -v)
patch failed, rejects left in working dir
errors during apply, please fix and refresh
trac_12823_alternate_removal.patch
compote:~/path-to-sage/devel/sage-myclone> hg qapplied
trac_12823_alternate_removal.patch
}}}
generic_backend.pyx.rej is
{{{
--- generic_backend.pyx
+++ generic_backend.pyx
@@ -252,7 +252,15 @@
- ``constraints`` -- an iterable containing the indices of the rows
to remove.
"""
- raise NotImplementedError()
+ if type(constraints) == int: self.remove_constraint(constraints)
+
+ cdef int c
+ cdef int last = self.nrows() + 1
+
+ for c in sorted(constraints, reverse=True):
+ if c != last:
+ self.remove_constraint(c)
+ last = c
cpdef add_linear_constraint(self, coefficients, lower_bound,
upper_bound, name=None):
"""
}}}
and mip.pyx.rej is
{{{
--- mip.pyx
+++ mip.pyx
@@ -1038,45 +1038,6 @@
self.add_constraint(functions[0] - functions[1], max=0,
name=name)
self.add_constraint(functions[1] - functions[2], max=0,
name=name)
- def remove_constraint(self, int i):
- r"""
- Removes a constraint from self.
-
- INPUT:
-
- - ``i`` -- Index of the constraint to remove.
-
- EXAMPLE::
-
- sage: p = MixedIntegerLinearProgram()
- sage: x, y = p[0], p[1]
- sage: p.add_constraint(x + y, max = 10)
- sage: p.add_constraint(x - y, max = 0)
- sage: p.add_constraint(x - y, max = 0)
- sage: p.add_constraint(x, max = 4)
- sage: p.remove_constraint(2)
- sage: p.show()
- Maximization:
- <BLANKLINE>
- Constraints:
- x_0 + x_1 <= 10.0
- x_0 - x_1 <= 0.0
- x_0 <= 4.0
- ...
- sage: p.number_of_constraints()
- 3
-
- WARN::
-
- Whether the first constraint is numbered 0 or 1 depends on
the backend.
- For GLPK, the first constraint has index 1; for Coin, it has
index 0.
- This is why the example above adds the same constraint twice,
- and tries to remove on of its copies. Whether it removes the
first
- or the second depends on the backend.
- Since supplying an invalid number WILL CAUSE A CRASH, please
be careful!
- """
- self._backend.remove_constraint(i)
-
def remove_constraints(self, constraints):
"""
Remove several constraints.
}}}
Hope it helps.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12823#comment:33>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.