Skip to content

Differing outputs when FlatZinc code is passed via stdin vs. file #655

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

Closed
chillja opened this issue Mar 28, 2023 · 4 comments
Closed

Differing outputs when FlatZinc code is passed via stdin vs. file #655

chillja opened this issue Mar 28, 2023 · 4 comments

Comments

@chillja
Copy link

chillja commented Mar 28, 2023

When running the following FlatZinc file minimal.fzn:

var 1..2:X_INTRODUCED_0_:: output_var;
var 1..2:X_INTRODUCED_1_:: output_var;
array[1..2] of var int:foobar:: output_array([1..2]) = [X_INTRODUCED_0_, X_INTRODUCED_1_];
constraint int_ne(X_INTRODUCED_0_, X_INTRODUCED_1_);
solve  satisfy;

with cat minimal.fzn | minizinc --input-from-stdin --solver Chuffed (or gecode) the output only prints the int vars:

X_INTRODUCED_0_ = 1;
X_INTRODUCED_1_ = 2;
----------

but when running minizinc --solver Chuffed minimal.fzn (or gecode) the output also correctly outputs the variable array:

X_INTRODUCED_0_ = 1;
X_INTRODUCED_1_ = 2;
foobar = array1d(1..2,[1, 2]);
----------

I am not (yet) familiar enough with the libminizinc code base to make any educated guess, where this might come from, or whether this is user error, but I think both should output the array.

@Dekker1
Copy link
Member

Dekker1 commented Mar 28, 2023

The difference between the two commands is that when using --input-from-stdin the MiniZinc compiler will expect the input to be a MiniZinc model (.mzn).

In a MiniZinc model, FlatZinc annotations (output_var and output_array) are ignored. The default rules are then used to determine the output. In this case the variable are added, because they are decisions, but the array is not because it has a definition in its declaration.

As far as I know, there is currently no input from stdin that would allow you to pass in FlatZinc (as FlatZinc) to the compiler. However, some solvers do allow this.

@cyderize
Copy link
Member

cyderize commented Mar 28, 2023

I believe there is an argument --input-is-flatzinc which can be used to inform MiniZinc that the input is FlatZinc (it seems to be currently undocumented however). Combining it with the --input-from-stdin flag should give the correct results.

@Dekker1 Dekker1 closed this as completed Mar 28, 2023
@chillja
Copy link
Author

chillja commented Mar 29, 2023

Thanks a lot! If appreciated I'd like to add --input-is-flatzinc to the reference manual, as a remark on the --input-from-stdin option.

@Dekker1
Copy link
Member

Dekker1 commented Mar 29, 2023

Feel free to send a pull request. The --help information is printed using the printHelp function found in flattener.cpp

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