Search code examples
minizinc

how to coercion from type string to enum


Thanks for help . I have define a enum ,and then define record with this enum . pls refer to the code .

enum tasks ;

int : recordNumberOfTaskData ;

type taskDataType = record(int: id, tasks:task , int:data);

array[1..recordNumberOfTaskData] of taskDataType : taskDataList ;
 
solve satisfy;

output
["tasks=" ++ show(tasks)++"\n"]
++
["taskData=" ++ show(taskDataList)++"\n"]

and give the data with json file

{"taskDataList":[{"data":1,"id":1,"task":"a1"},{"data":2,"id":2,"task":"a2"}]
,"tasks":["a1","a2"]}

but it is not work . the error message is

MiniZinc: type error: cannot determine coercion from type string to type tasks

how can i coercion from string to enum

how to provide taskDataList with json


Solution

  • This is a current problem in MiniZinc's JSON parser. It assumes that there is type information about the variables being assigned when parsing JSON. However, the type-inst alias obfuscates this information until after type-checking.

    The workaround is thus to not use the alias. The following model would work with your json file.

    enum tasks ::output;
    array[_] of record(int: id, tasks: task , int: data): taskDataList ::output;
    

    Hopefully we'll be able to resolve this problem in the MiniZinc compiler soon.