Syntax related issues --Having difficulty with and resolving syntax

87 views
Skip to first unread message

jack drawbridge

unread,
Nov 27, 2023, 6:32:42 PM11/27/23
to MiniZinc
I am new to minizinc. Been watching videos and reading Handbook and trying examples but must admit it's definitely not intuitive. Have moved from 2.7.6 to 2.8.1---still issues.
A colleague has identified this Constraint Satisfaction issue which I have attempted with minizinc.
Constraint Satisfaction using miniZINC: Consider 4 activities: checkers, horseshoes, darts, table tennis. There activities are to occur concurrently in 4 sessions 9Am,10AM,11AM and 12 noon. There are 8 players: A,B,C,D.E,F,G and H. The players are  divided into unique combinations of 2 players each using N(8) choose 2. So team A,B and team B,A are the same team. The constraints are: a team can only play  max 1 activity 1 time and then that combination/team is excluded from further play. A  team player  can only play in one activity in a session, and a team player can only participate once in a  specific activity . The objective is to assign teams to activities in sessions while abiding to the constraints, and to show satisfying results in matrix format with Activities as Columns and Sessions as Rows.

The latest attempt(below) results in an error

MiniZinc: syntax error: syntax error, unexpected set


Any help, advice or direction would be appreciated. Thanks in advance.


% Use this editor as a MiniZinc scratch book
% Define the enum types for activities and players enum ACTIVITY = {CHECKERS, HORSESHOES, DARTS, TABLE_TENNIS}; enum PLAYER = {A, B, C, D, E, F, G, H};
% Define the array of integers for sessions array[1..4] of int: SESSION = [9, 10, 11, 12];
% Define the set of pairs of players for teams set of set of PLAYER: TEAMS = {{A, B}, {A, C}, {A, D}, {A, E}, {A, F}, {A, G}, {A, H}, {B, C}, {B, D}, {B, E}, {B, F}, {B, G}, {B, H}, {C, D}, {C, E}, {C, F}, {C, G}, {C, H}, {D, E}, {D, F}, {D, G}, {D, H}, {E, F}, {E, G}, {E, H}, {F, G}, {F, H}, {G, H}};
% Define the decision variable for the assignment of teams to activities in sessions array[TEAMS, ACTIVITY, SESSION] of var bool: x;
% Define the constraints of the problem constraint forall(t in TEAMS, a in ACTIVITY) ( % A team can only play one activity one time and then that combination/team is excluded from further play sum(s in SESSION) (x[t, a, s]) <= 1 );
constraint forall(p in PLAYER, a in ACTIVITY) ( % A player can only participate once in a specific activity, regardless of the team and the session sum(t in TEAMS where p in t, s in SESSION) (x[t, a, s]) <= 1 );
constraint forall(a in ACTIVITY, s in SESSION) ( % Each activity in each session has exactly one team assigned to it sum(t in TEAMS) (x[t, a, s]) == 1 );
  solve satisfy;

Jip Dekker

unread,
Nov 27, 2023, 6:38:02 PM11/27/23
to MiniZinc
The problem is that "set of set of PLAYER" is not a valid MiniZinc type.

You have to model this in a slightly different way. You could for example use an "array[_] of set of PLAYER", "array[_,1..2] of PLAYER", or the last few versions of MiniZinc "array[_] of tuple(PLAYER, PLAYER)"

jack drawbridge

unread,
Nov 27, 2023, 7:41:34 PM11/27/23
to MiniZinc
thanks Dekker.
 I have tried various combinations of your suggestions and am getting variety of syntax issues. Mostly lack of knowledge and experience on my part.

MiniZinc: syntax error: syntax error, unexpected ';'

MiniZinc: syntax error: syntax error, unexpected ';', expecting ++ or ':'

Cyderize

unread,
Nov 27, 2023, 7:45:45 PM11/27/23
to MiniZinc
Hi,

Have a look at this playground model for a possible way to approach this.

In general, with syntax errors, if you can't see what's wrong at the location of the error, try to comment out as much as you can until you can isolate which specific thing is giving the error, then you can ask about that specific language construct. Without seeing the model, the unexpected ';' error just indicates a stray semicolon 'somewhere', and it's hard to say where this might have come from (but often these might be from accidentally putting one at the end of a line but in the middle of an expression).

jack drawbridge

unread,
Nov 27, 2023, 8:05:26 PM11/27/23
to MiniZinc
Thank you, Cyderize.

That certainly gives me something to review. It's the first time with this problem that I actually got an answer. I'll have to get the output into a more useful format.
I knew there was at least 1 solution, since this was done manually:
CHECKERS   HORSESHOES   DARTS   TABLE_TENNIS    
  9  {A, E}   {C, F}     {D, G}   {B, H}  
 10 {C, G}   {A, H}     {B, E}   {D, F}  
 11 {D, H}   {B, G}     {A, F}   {C, E}  
 12 {B, F}   {D, E}     {C, H}   {A, G} 

The next question of course, are there other solutions. And, then it will be can we have move activities and/or sessions with more players and  different team composition.

Thanks again, I'll study your refinements.

jack drawbridge

unread,
Nov 28, 2023, 5:19:45 PM11/28/23
to MiniZinc
Could someone give advice/direction on getting output  in the form of Activity by column, Session by Row and the team make-up ( A,C etc ) as the value in the cell. I appreciate the sample by Cyderize and have tried to get output in a format that can be easily checked. I have tried making a new array and outputting same. It would appear that my underlying constraints are not correct for the problem. 
This is the best I have done (which violates constraints OR doesn't reflect the array contents).
A team can only participate in 1 activity.
I find the syntax overwhelming (but admit to very limited knowledge of minizinc)

y =

[|                Session(9): Session(10): Session(11): Session(12):

| CHECKERS:   1, 14, 23, 28

| HORSESHOES: 1, 14, 23, 28

| DARTS: 1, 14, 23, 28

| TABLE_TENNIS: 1, 14, 23, 28

|];

Thanks in advance for any advice.

Jip Dekker

unread,
Nov 28, 2023, 5:28:57 PM11/28/23
to MiniZinc
I think adding the following output statement might give you the output you're looking for:

array[ACTIVITY, SESSION] of set of PLAYER: y ::output_only = [
  (s, a): {p | i in index_set(TEAMS) where fix(x[i,a,s]), p in TEAMS[i]}
  | s in SESSION, a in ACTIVITY
];
output [show2d(y) ++ "\n"];

Here you can find it with Jason's playground model: link

jack drawbridge

unread,
Nov 28, 2023, 6:35:00 PM11/28/23
to MiniZinc
Thank you again Jip Dekker. Your suggested code does provide more readable output in a format I was seeking. However, it now is clear that my constraints are not correct for the problem I am addressing. I gave the problem definition in the first post in this thread.
Teams are made up of 2 player unique combinations from 8 choose 2. (A,B,C,D,E,F,G,H)
A team can only participate in 1 activity in 1 session,  then Is removed from further play.
A Player, regardless of Team, can only play 1 activity 0 or 1 time.
A Player can only play in 1 activity per session.
Each Activity in each Session has exactly 1 Team assigned to it.

Here are some results from current code which illustrate constraint violation.
MiniZinc Result1 — Mozilla Firefox.png
Players (eg B playing Checkers multiple times; C  Horseshoes; E and G Darts.......)
-----------------------------------------------------------------------------------------------------------------------------------------

MiniZinc Result2 — Mozilla Firefox.png

Players in multiple Activities in same Session
-------------------------------------------------------------------------------------------------------------------------------------

I am new to minizinc, struggling with syntax, but it seems my constraint assignments are off-base as well.
Any advice or direction is appreciated.
Thanks again Jip Dekker for your response.
Jack
Reply all
Reply to author
Forward
0 new messages