Annotation causes error when running compile and solve separately
With this simple model:
annotation tag(string: label);
var 0..10: x;
var 0..10: y;
var 0..10: z;
constraint ( x = y + z ) :: tag("mytag");
solve maximize x;
We get an error when running compile and solver separately.
> minizinc -c bug-ann.mzn && minizinc bug-ann.fzn
/Users/jcarciofi/Projects/tromp/git-work/grains/Scenarios/bug-ann.fzn:5.52-63:
MiniZinc: type error: no function or predicate with this signature found: `tag(string)'
Works fine when compile and solver are run in one minizinc invocation.
> minizinc bug-ann.mzn
x = 10;
y = 10;
z = 0;
----------
==========
Hi Jim,
This is a limitation in the FlatZinc format. The definitions of custom predicates are stored in the FlatZinc files, but custom annotations are not. This means that when the MiniZinc compiler gets a FlatZinc model with a custom annotation it is unable to find the definition of that annotation and will mark it as a type error. The simple solution would be to include custom annotations in the FlatZinc format, but because this would conflict with the current FlatZinc specifications we are reluctant to do so.
The reason I am running compile and solver separately is that I need to get access to the solution (from cbc) with respect to the flattened representation, including introduced variables. I could not find a way to do this. I tried --output-raw, but that does not work for hard-linked solvers. Is there some other way I can get access to the raw cbc solution?
Hi,
currently you can compile with --writeModel model.mps.gz and solve the mps by cbc executable and print the raw solution.
For the FZN issue, you can copy the predicate into FZN, might work if typechecker is lax.
P.S. you can also remove the tag either from the model or FZN, Cbc interface does not use it.
Cheers,
On Tue, 1 Sep 2020 at 09:11, jim-carciofini [email protected] wrote:
The reason I am running compile and solver separately is that I need to get access to the solution (from cbc) with respect to the flattened representation, including introduced variables. I could not find a way to do this. I tried --output-raw, but that does not work for hard-linked solvers. Is there some other way I can get access to the raw cbc solution?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/MiniZinc/libminizinc/issues/406#issuecomment-684090020, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEEBOZXDMBMK2OIJDKCKVYLSDQU3VANCNFSM4QQWZFWQ .
-- Dr Gleb Belov Monash University +61 3 9903 1622
Thanks for the suggestions. The simplest approach that works for me is to just strip the tags from the fzn. Longer term, it seems like not supporting annotation declarations in the flatzinc language limits the utility of user declared annotations.