-
Notifications
You must be signed in to change notification settings - Fork 0
/
Magic_Sequence.mzn
33 lines (30 loc) · 983 Bytes
/
Magic_Sequence.mzn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
include "count.mzn";
%%%%%%%%%%%%%%
% PARAMETERS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Length of the sequence
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
int: n;
set of int: Indexes = 0..n-1;
%%%%%%%%%%%%%%
% VARIABLES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The sequence itself
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
array[Indexes] of var int: magic;
%%%%%%%%%%%%%%%
% Constraints
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Tips:
% - sum(array) return sum of the array's elements
% - you can use bool's like integers
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%constraint forall(i in Indexes) (magic[i] = (sum(j in Indexes)(bool2int(magic[j]=i))));
constraint forall(i in Indexes)(count(magic, i, magic[i]));
solve satisfy;
%%%%%%%%%%%%%%%%%%%%%%%%
% EXAMPLE OUTPUT
%%%%%%%%%%%%%%%%%%%%%%%%
% - magic - magic sequence
%%%%%%%%%%%%%%%%%%%%%%%%
output [ "magic sequence = ", show(magic),";\n"];