Sergio
Sergio

Reputation: 57

Conditional output minizinc

I'm messing arround with minizinc and I'm trying to achieve a conditional output where, if an array element has value 'true', the program outputs information concerning these element's array indexes. This is what I have:

include "globals.mzn";
int: time=5;
int: n=3;
int: l=n*n;
array[1..4,0..time,1..l] of var bool: X;
constraint X[1,5,7]=true;
constraint X[2,5,3]=true;
constraint X[3,5,9]=true;
constraint X[4,5,7]=true;
solve satisfy;

I attempted to solve this problem using concat, like so:

output ["X_"++concat(["\(r)_\(t)_\(pos)" 
| pos in 1..l, r in 1..4, t in 0..time, where X[r,t,pos]==true])++"\n"];

However I am not allowed, "MiniZinc: type error: no function or predicate with this signature found: `concat(array[int] of var opt string)'"

What I want is something like,

for pos in 1..l, r in 1..4, t in 0..time
 if X[r,t,pos]==true
  output ["X_\(r)_\(pos)_\(t)"]

How can I achieve it?

Upvotes: 2

Views: 1488

Answers (1)

hakank
hakank

Reputation: 6854

Try using fix(...) around the decision variable in the where clause, e.g.

output ["X_"++concat(["\(r)_\(t)_\(pos)" 
| pos in 1..l, r in 1..4, t in 0..time, where fix(X[r,t,pos])==true])++"\n"];

fix is (often) needed when one use the actual values of decision variables, e.g. for comparing its values etc.

(The message about var opt string is perhaps misleading in this context.)

Upvotes: 3

Related Questions