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

fix integer check #48

Merged
merged 2 commits into from
Apr 7, 2023
Merged

fix integer check #48

merged 2 commits into from
Apr 7, 2023

Conversation

yascho
Copy link
Contributor

@yascho yascho commented Apr 3, 2023

Hi, calling check_all_int [1] with floating-point numbers < 1, e.g.

check_all_int([0.5])

results in

ZeroDivisionError: float modulo

Reason is mainly that int(0.5)=0 and then i % int(i) is undefined.

This happens for example when solving 0-1-knapsack with profits, weights or capacity < 1 (method="mt1r") [2]. Note that we don't have to check if the values are integers if the method is already "mt1r", so changing check_all_int is just a quick-fix and not a code refactoring.

Hope it helps, thank you!

[1] https://github.com/jmyrberg/mknapsack/blob/master/mknapsack/_utils.py#L21
[2] https://github.com/jmyrberg/mknapsack/blob/master/mknapsack/_single.py#L95

@jmyrberg
Copy link
Owner

jmyrberg commented Apr 6, 2023

Hi, and thanks for the PR! Could you still add a test case for this, i.e. single 0-1 problem that doesn’t pass the old way, but would pass with the new code?

@jmyrberg jmyrberg merged commit c1cb903 into jmyrberg:master Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants