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

0th subset disappearing problem when getting all solutions #86

Open
lsjbh45 opened this issue Apr 6, 2024 · 4 comments
Open

0th subset disappearing problem when getting all solutions #86

lsjbh45 opened this issue Apr 6, 2024 · 4 comments

Comments

@lsjbh45
Copy link

lsjbh45 commented Apr 6, 2024

Hello, while testing randomly generated test cases, I came across a strange test case that seems to be a bug.
The test case found is as follow:

import numpy as np
import exact_cover as ec

tc = ((1, 1, 0,), (1, 0, 1,), (1, 0, 1,), (1, 1, 0,), (1, 1, 0,), (0, 0, 0,),
      (0, 0, 0,), (0, 0, 1,), (1, 1, 0,), (1, 0, 1,), (0, 1, 0,), (1, 0, 0,),)

S = np.array(tc, dtype=bool)
sols = ec.get_all_solutions(S)
print(sols)
# result: {(9, 10), (7, 4), (2, 10), (7, 11, 10), (7, 3), (7,), (1, 10), (7, 8)}
# expected: {(9, 10), (7, 4), (2, 10), (7, 11, 10), (7, 3), (7, 0), (1, 10), (7, 8)}

Additional information:

  • If the 0th subset is chosen as the "last" subset of S* to form an exact cover (�i.e. selected at last, while selecting subsets to cover from the preceding elements of X), this problem is presumed to occur.
  • It has been confirmed that this problem does not occur in the get_exact_cover method, but only for the get_all_solutions method.
import numpy as np
import exact_cover as ec

tc = ((0, 0, 0, 1, 0), (1, 1, 0, 0, 0), (0, 0, 1, 0, 1))

S = np.array(tc, dtype=bool)
sols = ec.get_all_solutions(S)
print(sols)
# result: {(1, 2)}
# expected: {(1, 2, 0)}

sol = ec.get_exact_cover(S)
print(sol)
# result: [1 2 0], as expected

Thanks for reading!

@kmohanram
Copy link

kmohanram commented Jun 10, 2024

looks like i opened a new issue that is similar to (or at least overlaps) this one ...

@kmohanram
Copy link

one way to temporarily address this issue/bug is to add a dummy first row that is all zeros to the input ... it will never show up in the cover and one just has to adjust indexing from the returned results. it looks like the encoding of the results and the trunc step in _solutions_array_to_set in wrapper.py will have to be reconciled to fix this subtle issue/bug.

@lsjbh45
Copy link
Author

lsjbh45 commented Jun 11, 2024

@kmohanram Thanks for additional confirmation on this issue! :)
The way you temporarily resolved the problem was exactly in line with the action I took; i.e. use 1-based indexing instead of 0-based indexing.
I hope that the underlying cause of this problem will be resolved soon.

@jwg4
Copy link
Owner

jwg4 commented Nov 30, 2024

looking at this

@jwg4 jwg4 mentioned this issue Nov 30, 2024
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

No branches or pull requests

3 participants