-
-
Notifications
You must be signed in to change notification settings - Fork 491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Knapsack algorithm #6749
Comments
comment:1
This needs a really detailed example, worked out so that a non-expert (like myself) can understand it. This of the first example you would try to teach an undergraduate. That would be perfect. |
comment:2
Replying to @wdjoyner:
For example, there seems to be a simple knapsack problems solved here: http://sites.google.com/site/mikescoderama/Home/0-1-knapsack-problem-in-p |
comment:3
I just added documentation and the example you required. I guess the docstrings took me 10 times what the function requires, but I learned a lot about sage's documentation, the Reference manual, Sphinx, and the fact that you should NEVER, for ANY REASON, delete a branch of Sage. It gets angry if you do. And I uploaded a new knapsack.patch replacing the old one ;-) Nathann |
comment:4
A small mistake when uploading the patch... Well, now the two of them are good ;-) |
comment:5
This patch (after the dependencies are applied) applies fine to 4.1.1.rc2 on an intel macbook running 10.4.11. It passes sage -testall except for (apparently unrelated) errors with
However, I will ask someone at work (an expert in OR) to check the code before posting a positive review. |
comment:6
I've had a talk with my OR colleague. I don't think "A list of pairs (weight,value) where each pair is repeated the number of times it is taken into the solution. " is the proper English grammar for what is meant. I think "A list of pairs (w_i, u_i), for each object i occurring in the solution. " is better. Do you agree? Also, he suggested that the "objective value" (or maximal useful value, in your terminology) be included in the solution. Perhaps you could include this as an optional keyword, leaving the current behaviour as the default? If you also agree to this, please add a corresponding example to the docstring. |
comment:8
Excellent suggestion ! So :
But : Besides, this syntax makes knapsack consistant with the other optimization functions I wrote for graphs, and I hope will all the LP functions we will write in the future ;-) To avoid mistakes, I updated both patches ( they were identical ), and the new version obviously contains the old one, plus the update I just wrote ! Thank you for your review ! Nathann |
comment:9
There was this failure:
|
comment:11
I always forget the LP solvers are non-deterministic algorithms, and because of this the values they return sometimes change, which causes trouble with docstrings ;-) Sorry ! ( Fixed, as usual the two patches are updated ) |
comment:13
This last patch (and its dependency) installed fine as before (same system, and version) with the following failures:
I think these are unrelated, so this gets a positive review from me. Thanks for implementing it! |
comment:14
This will have to wait until #6502 is resolved. Which patch is to be merged? Most likely, I think some if not all doctests would have to be flagged with "# optional" if they require the optional GLPK spkg. |
Attachment: knapsack.patch.gz |
comment:15
Attachment: knapsack.2.patch.gz Updated. And you can apply any one of them, they're both the same ( I uploaded two by mistake the first time, then updated both ) |
comment:16
This patch (on top of the updated 6502) did not apply for me (4.1.1.rc2, intel macbook 10.4.11). |
comment:17
I am using 4.1.1, perhaps it explains ? I just tried it again with only 6502 and this one, and noticed nothing wrong O_o |
comment:18
Could you please try it again on a 4.1.1 ? |
comment:19
Replying to @nathanncohen:
I created a new clone and re-tried this. This time it worked! Passed tests as before (same Sage version, same machine ....). |
comment:20
As the functions dealing with LP have not been reviewed, I prefer to rewrite the MIP class for Sage to make it easier to use. I will post a new version of the MIP patch as soon as possible, along with all the patches for functions using it. Sorry for the trouble, I'll try to make it quick ! Nathann |
comment:21
Here is the new version, slightly modified to use the symbolics from #6869 ( the new version of MIP you need to try this code ! ) |
Attachment: knapsack-symbolics.patch.gz |
comment:23
This applies fine to 4.1.2.a0 and passes testall without any other packages installed (no glpk, etc). Running more tests... |
comment:24
This applies fine to 4.1.2.a0 and passes testall with glpk package installed. |
comment:25
Merged With
See #6916 for a follow-up to this ticket. |
Author: Nathann Cohen |
Reviewer: David Joyner |
Merged: Sage 4.1.2.alpha2 |
A general knapsack algorithm using Linear programming ( check you have #6502 installed ! ) to patiently wait for more efficient versions :-)
Component: numerical
Author: Nathann Cohen
Reviewer: David Joyner
Merged: Sage 4.1.2.alpha2
Issue created by migration from https://trac.sagemath.org/ticket/6749
The text was updated successfully, but these errors were encountered: