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

Usage of IntEnum in array model input #2

Open
Dekker1 opened this issue Oct 22, 2020 · 1 comment
Open

Usage of IntEnum in array model input #2

Dekker1 opened this issue Oct 22, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@Dekker1
Copy link
Member

Dekker1 commented Oct 22, 2020

The standard JSONEncoder that is used to create the JSON input for a MiniZinc model ensures that an IntEnum is always represented using its integer representation: https://github.com/python/cpython/blob/3.9/Lib/json/encoder.py#L309-L313

Normally the JSON representation can be customised in the default member function of MZNJSONEncoder, but because IntEnum inherits from int, the representation is part of the base types of JSONEncoder that is directly implemented in the encoder library (and a C backend)

This is incorrect as an input for a MiniZinc enum, where a JSON object {"e": "some_name"} is expected and an integer will not be accepted.

workaround
A current workaround is to use an Enum in Python, or to use the actual matching integers in the MiniZinc model.

possible solutions
The following solutions could be considered:

The last solution seems more likely, as I'm currently unaware of a better JSON Encoder alternative and several attempts are the second method have failed.

@Dekker1 Dekker1 added the bug Something isn't working label Oct 22, 2020
@ofekkir
Copy link
Contributor

ofekkir commented Oct 22, 2020

Thank you so much for the help and the attention!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants