1

I'm given a question where I'm supposed to create a set of teams, with just a simple constraint where there are two arrays of sets on which two members must be together and which shouldn't. I'm new to Minizinc so I'm having a tough time working with the decision variable with an array of sets. Teams must be of size n too.

For example:

GroupsThatMustBePaired = [{1,3},{4,5}]
GroupsThatShouldNot = [{2,3}]

Output = [{1,3},{4,5},{2,6}..etc]

Any help?

1 Answer 1

2

Using set variables can be a bit tricky at first, but if you can get back to when you learned about sets in mathematics, then the concepts should be very familiar.

The following is an example of how you could write you model. It has a few extra constraints to make sure that the "teams" contain everyone, nobody twice, and have a maximum capacity include "all_disjoint.mzn";

set of int: MEMBERS = 1..6;
set of int: GROUPS = 1..3;
array[int] of set of MEMBERS: GroupsThatMustBePaired = [{1,3},{4,5}];
array[int] of set of MEMBERS: GroupsThatShouldNot = [{2,3}];

array[GROUPS] of var set of MEMBERS: teams;

% Team members can only be part of one team
constraint all_disjoint(teams);
% Everyone must be part of a team
constraint array_union(teams) = MEMBERS;
% Maximal number of people per group
constraint forall(g in GROUPS) ( card(teams[g]) <= 2 );

% Eliminate bad groups
constraint forall(g in GROUPS, i in index_set(GroupsThatShouldNot)) (
  not (GroupsThatShouldNot[i] subset teams[g])
);

% Enforce good groups
constraint forall(i in index_set(GroupsThatMustBePaired)) (
  exists(g in GROUPS) (
    GroupsThatMustBePaired[i] subset teams[g]
  )
);

Some notes if you want to change this model: Most solvers do not support set variables directly but translate this model to use boolean variables instead. This is not necessarily worse, but is something to keep in mind if you feel that the problem could be easier expressed using boolean variables.

In this particular case, you might want to consider using integer variables. This problem can be seen as an assignment problem, where members are assigned to teams. This considers the viewpoint from the team-members instead of the team. Although this will probably make the subset constraint harder to write, this structure would remove the need for the all_disjoint and the array_union constraints, because we know everyone will be in a team and nobody will be in multiple teams. In this case the card (Cardinality) set constraint could be replace with a global_cardinality_low_up integer constraint.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks so much! This was a big help. Do you know any resources I could use to practice this more? Particularly working with set variables.
You can have a look at the Set examples in the MiniZinc tutorial: minizinc.org/doc-2.4.3/en/modelling2.html#set-constraints. Generally practice in MiniZinc comes from actually making models. I think it's wise to focus on modelling well instead of a particular aspect of MiniZinc. The three MiniZinc courses on Coursera are a great starting point if you don't have much experience in MiniZinc
Hey, thanks so much! I also had one more quick question. I'm calculating the total competition of the tournament one player teams up with another who complement each other really well. So we have effectivenessGroup = {[4,5], [6]}. Competition is calculated by how many people in effectiveness group pair up. So if player 1 (row i corresponds to player i) gets teamed up with 4 and 5 then the score is 2. I wanted to do intersect but I'm having trouble how I should iterate it. Any ideas?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.