'Referring to decision variable arrays in MiniZinc functions
I'd like to find the permutation steps that lead from the initial state to a required state. The decision variable array Steps
is intended to record the permutation steps, encoded as integers. My approach is to constrain the values of Steps
so that "replaying" the permutations identified by them on the initial state yields the
arranged state, represented by State
. In order to select from various permutations, I'd have to refer to the items of Steps
in a conditional expression, which results in a type error.
int : nrItems;
int : nrMaxSteps;
nrItems = 3;
nrMaxSteps = 10;
array [1..nrItems] of int : State;
State = [2,1,3];
array [1..nrMaxSteps] of var 0..4 : Steps;
% 0 - empty step for solutions shorter than nrMaxSteps
%**********************************************
% permute the initial state
function array [1..nrItems] of int: permute() =
% apply permutations on the initial state
% depending on the values of Steps
if(Steps[1] == 1) ... select permutation1
%**********************************************
predicate arranged() =
let { array [1..nrItems] of int : permuted = permute(); }
in permuted[1] == State[1] /\ permuted[2] == State[2] /\ permuted[3] == State[3];
constraint
arranged();
solve satisfy;
What would be the right approach here?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|