Skip to content
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 related issues #12

Open
Mathemalsky opened this issue Jul 9, 2021 · 3 comments
Open

knapsack related issues #12

Mathemalsky opened this issue Jul 9, 2021 · 3 comments
Labels
AAL Approximation Algorithm Library

Comments

@Mathemalsky
Copy link
Collaborator

I thought and read a bit about the knapsack problem.

  • performance: In my opinion we should go for the performance improved version of the exact algorithm because it avoids a big amount of memory copies. See here: https://www.cplusplus.com/reference/vector/vector/
    The argument that the exact knapsack will perform bad anyway should be discarded due to the fact that the FPTAS version will invoke the exact knapsack problem on the rounded data.
  • rounding: The book assumes sizes, values and capacity to be integers. Since our algorithm operates on floats some difficulties concerning rounding occur. The approximation algorithm draws it's polynomial runtime from the fact that the subsets can only take on a finite number of values, namely multiplicities of \mu. Using floats we lose that property.
    We could treat float as equal if they are within an epsilon environment of each other, but this way comparison loses transitivity which destroys any guarantees in the approximation factor.
    Do you have any ideas how to deal with that?
@Mathemalsky Mathemalsky added the AAL Approximation Algorithm Library label Jul 9, 2021
@MilchRatchet
Copy link
Owner

  • Ok, then I guess we should look into improving performance there. I suggest we start by making a very large test example and measure time on that one.
  • If I am not mistaken this multiplicities of \mu is not an issue regarding float exact comparison. But I will have to think about that again, especially regarding what we do with the values. We can do the epsilon approach where epsilon is at most half of \mu. Alternatively we could implement knapsack for ints. Since C++ has templates we could have one templated implementation which is exposed through a float and int helper function, i.e.
[...] AAL_KNAPSACK_EXACT([something with ints]);
[...] AAL_KNAPSACK_EXACTF([something with floats]);
static [...] AAL_KNAPSACK_EXACT_([something with templates]);

@Mathemalsky
Copy link
Collaborator Author

You can now have a look at the performance comparison. As suspected the pointer version is considerably faster than the initial version. In my test it took about 1.3 s in contrast to the older version, which consumed > 6 s.
So if you agree to that point than merge the performance improved version into master.
Do we need the performance test any more and should also merge into master?

@MilchRatchet
Copy link
Owner

Ok, the performance difference is indeed quite massive.

I merged the improved version now. I don't think we should merge the performance test right now. Maybe we could later do a performance test which compares every algorithm for a given problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AAL Approximation Algorithm Library
Projects
None yet
Development

No branches or pull requests

2 participants