Anyone with MiniZinc expertise

jdraw

Super Moderator
Staff member
Local time
Today, 11:26
Joined
Jan 23, 2006
Messages
15,499
I have an interesting scheduling requirement that includes constraints. This is more an academic issue, but I do have a colleague who has a similar real life assignment.
 
Hi Tony, I went around in circles with chatgpt. But I am new to MiniZinc.
Here is the issue my colleague is addressing.

The goal:
construct a program to do the following:

Assign a number of Teams to a number of
Activities over a number of Sessions.

Example: to overview the goal with a specific sample.
4 Sessions
4 Activities
8 Participants
2 Participants per Team
there are 28 unique combinations/pairs of 2 participants ( n Choose 2)
To illustrate:
The sessions are 9am, 10am, 11am, 12pm.
The activities are chess, snooker , bowling, darts
The participants are A, B, C, D, E, F, G, H
Each Team is a unique combination/pair of Participants
A Team can only do one activity and then is removed from further action.

The specifications, a participant can't be assigned to more
than one activity in the same session, and a participant can't be
assigned to the same activity more than once, and each Team is composed of
2 participants and each session activity involves a unique Team.



Ultimately, a template to allow for M activities in N Sessions by X participants where Teams can be of different sizes for different activities.
 
Tony,
I copied your minizinc code to TonySched.mzn. This was the result

Running TonySched.mzn
81msec​

TonySched:12-55.17-22:
MiniZinc: type error: cannot determine coercion from type array[int,int] of int to type array[int,int] of bool
Process finished with non-zero exit code 1.
Finished in 81msec.

Same sort of results I got when running minizinc suggestions from chatgpt.
jack
 
It's too early to tell David. I have had some clear, quick responses to some questions/subjects, but much less than stellar in others. I asked chatGPT some questions about furnace symptoms and also about car tires/noises and got direct, useful responses. However, I have had some confusing, circuitous responses when dealing with Access/vba/vbe. My experience says that the software (Ver 3.5 that I have used) often makes things up (hallucinations). Several times, different sessions, I get a code snippet response from chatGPT that include s properties that don't exist. I also tried Bing chat with a question I had posed to chatGPT-- similar responses and seemed to be going in a circle. Bing chat seems just another interface to chatGPT, but I haven't pursued it enough to comment one way or the other.

Using the miniZinc as reference, I don't know the syntax nor capabilities and am not familiar with the software. I watched some videos and will get to practising with some examples. I tried the scheduling problem with Access/vba and shortly found I was "in over my head". I sent a PM to one of our "math-oriented" posters who assured me this was not a simple problem and one which he felt got complex quickly. This was scheduling with constraints/ optimization/linear programming/complex search.... He advised posting on a different site. The reaction I got there was less than helpful---"we're not here to do your homework".... "you have all the info you need to solve the problem". So that's when I went to chatGPT --since the human interaction was dead in the water. I asked chatGPT what kind of problem/family I was dealing with and how to solve. A few long chat sessions suggested some vba, then python and the miniZinc (which had not heard of), then back to Python.... So, off to youtube -miniZinc... and that's where I am at the moment. But I did wander to Optaplanner, and a series of Constraint Optimization Problem/Program videos. It's more of a diversion than a problem. It is interesting in that I/you can see how these types of problems were fundamental to the creation of the various models underlying chatGPT, AI etc.

My gut feel is that AI is a journey, not an endpoint. There will be some twists and turns, and some commercialization as things improve. A lot of the models are built on digitized info (internet sites/forums/articles/opinions/social media) and we all have thoughts/experiences on the facts and verification on that "knowledgebase".

So, it's too early to tell how good/bad/relative chatGPT is. Depends on context, like most things. For a quick answer to a general problem/question, it is an excellent start. More focused than general search or youtube. But, for me, it loses its helpfulness when it suggests A, then B, then returns to A without a recognized change in parameters. It certainly has established a phenomenal following and acceptance in a relatively short period of time. Much like the growth and acceptance of Starlink and LEO satellites.
 
For anyone happening upon this thread.

I solved the puzzle with miniZinc IDE 2.8.1

The solution code;
Code:
%Dec -11-23   ----this is my working testing version % WORKING  
%output code to show teams vs True/False from Jip Dekker


% THE PROBLEM/PUZZLE TO BE SOLVED/SATISFIED


% 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.
% The Activities are  CHECKERS, HORSESHOES, DARTS, TABLE_TENNIS
% The Sessions are 9 AM, 10 AM, 11 Am, 12 Noon.


%----------miniZinc instructions/code follows-------------- 


include "globals.mzn";  %include minizinc globals library


%set up main factors of the puzzle
enum ACTIVITY = {CHECKERS, HORSESHOES, DARTS, TABLE_TENNIS}; %4 activities
enum PLAYER = {A, B, C, D, E, F, G, H};                      %8 Players
enum SESSION = Session(9..12);                               %4 Sessions


% Define the set of pairs of players for teams  8 choose 2
array [int] 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[index_set(TEAMS), ACTIVITY, SESSION] of var bool: x; 
% 3 dimensional array of booleans
% Each element of the array x is a boolean variable that can be either true or false. 
% The value of  x[t,a,s] indicates whether team t performs activity a in session s or not.  


% Define the constraints of the problem


% A team can only play one activity one time in one session and then that combination/team is excluded from further play 


constraint forall(t in index_set(TEAMS), a in ACTIVITY) ( 
   sum(s in SESSION) (x[t, a, s]) <= 1 );
constraint forall(t in index_set(TEAMS),s in SESSION ) ( 
    sum(a in ACTIVITY) (x[t, a, s]) <= 1); 
constraint forall(t in index_set(TEAMS) ) (                      
   sum(a in ACTIVITY,s in SESSION) (x[t, a, s]) <= 1);


% A player can only participate once in a specific activity, regardless of the team and the session  
constraint forall(p in PLAYER, a in ACTIVITY) (
   sum(t in index_set(TEAMS) where p in TEAMS[t], s in SESSION) (x[t, a, s]) <= 1);


% A player can only participate once in a session, regardless of the team and the activity 
constraint forall(p in PLAYER,s in SESSION ) (
   sum(t in index_set(TEAMS) where p in TEAMS[t],a in ACTIVITY ) (x[t, a, s]) <= 1);


% Each activity in each session has exactly one team assigned to it  
constraint forall(a in ACTIVITY, s in SESSION) (
    sum(t in index_set(TEAMS)) (x[t, a, s]) == 1);


solve satisfy;
% JED I switched Session and Actvity in line below to get  Activity columns, Session rows
% Got assistance from Jip Dekker to convert 3D array of booleans to 2D array showing Teams
% Define a 2D array y showing session and activity with values of players making up Teams
array[SESSION,ACTIVITY] 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 the 2D array showing session and activity with values of players making up Teams
output [show2d(y) ++ "\n"];
[\code]

----------------------------a few solutions ------------------------------

[|              CHECKERS: HORSESHOES:  DARTS: TABLE_TENNIS: 
 |  Session(9):   {B, F},     {A, H}, {D, E},       {C, G}
 | Session(10):   {A, G},     {B, E}, {C, H},       {D, F}
 | Session(11):   {C, E},     {D, G}, {A, F},       {B, H}
 | Session(12):   {D, H},     {C, F}, {B, G},       {A, E}
 |]
----------
[|              CHECKERS: HORSESHOES:  DARTS: TABLE_TENNIS: 
 |  Session(9):   {D, F},     {A, H}, {C, E},       {B, G}
 | Session(10):   {A, G},     {D, E}, {B, H},       {C, F}
 | Session(11):   {B, E},     {C, G}, {A, F},       {D, H}
 | Session(12):   {C, H},     {B, F}, {D, G},       {A, E}
 |]
----------
[|              CHECKERS: HORSESHOES:  DARTS: TABLE_TENNIS: 
 |  Session(9):   {C, F},     {A, H}, {D, E},       {B, G}
 | Session(10):   {A, G},     {C, E}, {B, H},       {D, F}
 | Session(11):   {B, E},     {D, G}, {A, F},       {C, H}
 | Session(12):   {D, H},     {B, F}, {C, G},       {A, E}
 |]
----------
[|              CHECKERS: HORSESHOES:  DARTS: TABLE_TENNIS: 
 |  Session(9):   {B, E},     {A, H}, {D, G},       {C, F}
 | Session(10):   {A, G},     {B, F}, {C, E},       {D, H}
 | Session(11):   {C, H},     {D, E}, {A, F},       {B, G}
 | Session(12):   {D, F},     {C, G}, {B, H},       {A, E}
 |]
----------
[|              CHECKERS: HORSESHOES:  DARTS: TABLE_TENNIS: 
 |  Session(9):   {B, E},     {A, H}, {C, G},       {D, F}
 | Session(10):   {A, G},     {B, F}, {D, E},       {C, H}
 | Session(11):   {D, H},     {C, E}, {A, F},       {B, G}
 | Session(12):   {C, F},     {D, G}, {B, H},       {A, E}
 |]
----------
 

Users who are viewing this thread

Back
Top Bottom