Establish Constraints

Our program already has a few constraints of two types. Based on the structure of the program, the first constraint allows the program to only schedule two games per day, and the second constraint only allows one game per slot. We also have another constraint, one we call different_teams, that the same team can’t play twice in a day. Let’s take a deeper look at how our schedule predicate works and how we might generalize it to handle more sophisticated requirements.

Here’s the code we have in our program, this time in three chunks:

 schedule​(Acc, PotentialMatches, Scheduled, Day) :-
 member​(MatchA, PotentialMatches),
 member​(MatchB, PotentialMatches),
 
 different_teams​(MatchA, MatchB),
 subtract​(PotentialMatches, ...

Get Programmer Passport: Prolog now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.