Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
partition-problem/minizinc/partition.mzn
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
48 lines (34 sloc)
1.13 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
array[int] of int: durations; | |
int: n = length(durations); % number of tracks | |
set of int: TRACKS = 1..n; | |
int: k; % number of groups | |
set of int: GROUPS = 1..k; | |
array[TRACKS] of var GROUPS: groups; | |
% each group sums its durations | |
int: MIN_SUM = min(durations); | |
int: MAX_SUM = sum(durations); | |
set of int: SUM = MIN_SUM..MAX_SUM; | |
array[GROUPS] of var SUM: sums; % no group sums to zero | |
% the goal | |
var int: obj; | |
%------------------------------------------------- | |
include "globals.mzn"; | |
% splits are increasing, at least one apart | |
constraint increasing(groups); | |
% collects durations into group sums | |
constraint forall(i in GROUPS) ( | |
sums[i] = sum([durations[j] * bool2int(groups[j] == i) | j in TRACKS]) | |
); | |
% only max | |
%constraint obj = max(sums); | |
% both max and min | |
constraint obj = max(sums) - min(sums); | |
%------------------------------------------------- | |
solve :: int_search(groups, dom_w_deg, indomain_median, complete) | |
minimize obj; | |
output [ | |
"durations = ", show(durations), "\n", | |
"groups = ", show(groups), "\n", | |
"sums = ", show(sums), " -- ", show(min(sums)), "-", show(max(sums)), "\n", | |
"obj = ", show(obj), "\n" | |
]; | |