, +1!
: , , . , , .
:
distribution(Starts, Ends, Machines) :-
pairs_keys_values(Pairs, Starts, Ends),
length(Ms0, 4),
maplist(=(0-[]), Ms0),
foldl(task_machines0_machines, Pairs, Ms0, Ms1),
pairs_values(Ms1, Machines0),
maplist(reverse, Machines0, Machines1),
msort(Machines1, Machines).
task_machines0_machines(Start-End, Ms0, [End-[Start|Starts]|Ms1]) :-
Start
select(OccupiedUntil-Starts, Ms0, Ms1),
L
length(Starts, L).
Machines , , .
.
:
?- shower(Starts, Ends, _, _), distribution(Starts, Ends, Machines).
Starts = [0, 0, 0, 1, 2, 3, 0],
Ends = [3, 3, 1, 2, 3, 4, 4],
Machines = [[0], [0], [0, 1, 2], [0, 3]] .
, 4, - :
?- setof(Ms, Starts^Ends^Ds^(shower(Starts, Ends, Ds, 4),
distribution(Starts, Ends, Ms)),
Mss),
length(Mss, L).
Mss = [[[0], [0, 1], [0, 3], [0, 3]], ...]
L = 14.
, , .
20 , , :
distributions([
[[1],[2,3],[4,5,6],[7]], [[1],[2,4],[3,5,6],[7]], [[1],[2,5],[3,4,6],[7]],
[[1],[2,6],[3,4,5],[7]], [[1,3],[2],[4,5,6],[7]], [[1,3],[2,4],[5,6],[7]],
[[1,3],[2,5],[4,6],[7]], [[1,3],[2,6],[4,5],[7]], [[1,4],[2],[3,5,6],[7]],
[[1,4],[2,3],[5,6],[7]], [[1,4],[2,5],[3,6],[7]], [[1,4],[2,6],[3,5],[7]],
[[1,5],[2],[3,4,6],[7]], [[1,5],[2,3],[4,6],[7]], [[1,5],[2,4],[3,6],[7]],
[[1,5],[2,6],[3,4],[7]], [[1,6],[2],[3,4,5],[7]], [[1,6],[2,3],[4,5],[7]],
[[1,6],[2,4],[3,5],[7]], [[1,6],[2,5],[3,4],[7]]
]).