Skip to content

Usage of IntEnum in array model input #2

Open
@Dekker1

Description

@Dekker1

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions