1
0
This repository has been archived on 2025-03-06. You can view files and clone it, but cannot push or open issues or pull requests.
Jip J. Dekker b5f0d64642 Squashed 'prototype/' content from commit 91f7db00
git-subtree-dir: prototype
git-subtree-split: 91f7db00d45e7f991b5587ee07f09977ae311ee7
2021-07-29 14:28:24 +10:00

40 lines
974 B
MiniZinc

% RUNS ON mzn20_fd
% RUNS ON mzn-fzn_fd
% RUNS ON mzn20_mip
% vim: ft=zinc ts=4 sw=4 et
% Ralph Becket <rafe@csse.unimelb.edu.au>
% Wed Feb 25 16:43:52 EST 2009
%
% Langford's problem (see e.g., http://www.lclark.edu/~miller/langford.html)
% ------------------
%
% Arrange k sets of 1..n such that successive occurrences of any number, k,
% are separated by k other numbers.
% There should be 26 solutions to this problem.
int: k = 2;
int: n = 7;
int: nk = n * k;
array [1..nk] of var 1..n: a; % The sequence.
array [1..n] of var 1..nk: Fst; % Fst[k] is position of first k.
% Break some symmetry.
%
constraint a[1] <= a[nk];
% Prune some domains.
%
constraint
forall ( i in 1..n ) ( Fst[i] <= nk - (k - 1) * (i + 1) );
% The nitty gritty.
%
constraint
forall ( i in 1..n, j in 0..(k - 1) ) ( a[Fst[i] + j * (i + 1)] = i );
solve :: int_search(Fst, first_fail, indomain_min, complete) satisfy;
output ["a = ", show(a), ";\n"];