Created
September 9, 2015 19:34
-
-
Save Alexander-Schiendorfer/5356c8b17dcec53f51ca to your computer and use it in GitHub Desktop.
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
% given an array of k subsets of numbers 1..n | |
% select a subset of 1..n such that at most one | |
% member of every subset is in it and the sum is maximized | |
int: n; % numbers from 1 to n | |
int: k; % number of subsets | |
set of int: OBJ = 1..n; | |
set of int: SET = 1..k; | |
int: u; | |
% copied from dzn file; setselect sample data | |
n = 10; | |
k = 7; | |
s = [{1,5,6}, {2,6,7,10}, {3,6,8}, {1,2,3}, {2,9,10}, {5,8,10}, {7,8,10}]; | |
u = 3; | |
array[SET] of set of OBJ: s; | |
% HERE is the error: should be set of OBJ | |
var set of int: x; | |
% must contain at must one shared element | |
constraint forall(j in 1..k) ( card( x intersect s[j] ) <= 1 ); | |
constraint card(x) = u; | |
solve maximize sum(i in x) (i); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment