Terminal clauses¶
It is possible to extend the Defining new concepts and the Constraints propositions with TERMINAL_CLAUSES.
TERMINAL_CLAUSES -> (WHENEVER_CLAUSE | "where" WHERE_CLAUSE | WHEN_CLAUSE)+
where:
WHENEVER_CLAUSE adds a condition to the rule, and is the same presented in Defining new concepts;
WHERE_CLAUSE is a construction used to add a condition or substitute variables;
WHEN_CLAUSE again adds a condition.
WHERE_CLAUSE¶
where_clause -> COMPARISON ("and" COMPARISON)*
| VARIABLE "is one of" STRING_LIST
| VARIABLE "is respectively one of" STRING_LIST
| WHERE_CLAUSE "and" WHERE_CLAUSE
This clause allows you to add a list of comparisons, substitute a variable with a list of values (this leads to the creation of multiple rules) or concatenate different WHERE_CLAUSE.
The difference between “one of” and “respectively one of” is explained starting from the following example:
It is prohibited that the number of days where a nurse works in shift S is more than M, where S is one of morning, afternoon, night and M is respectively one of maxDay, maxDay, maxNight.
The first substitution of S creates 3 rules, one for each value “morning”, “afternoon”, “night”. Then, if you want to substitute another variable, M in the example, if you use “one of”, it leads to 3 more rules for each rule that is a sort of cartesian product of each value of S with each value of M. However, in case you want, for each value of S, to give a corresponding value of M you can use the keyword “respectively”.
Corresponding ASP:¶
Considering that minNurseMorning, minNurseAfternoon, minNurseNight are some defined constants. The previous proposition is translated into:
:- #count{D1: work_in(D,D1,S), shift(S,_,_), day(D)} < M, S = "morning", M = minNurseMorning.
:- #count{D1: work_in(D,D1,S), shift(S,_,_), day(D)} < M, S = "afternoon", M = minNurseAfternoon.
:- #count{D1: work_in(D,D1,S), shift(S,_,_), day(D)} < M, S = "night", M = minNurseNight.
WHEN_CLAUSE¶
WHEN_CLASUE -> "when" SIMPLE_CLAUSE_LIST
This clause adds a condition. It is made of a terminal symbol “when” and a list of SIMPLE_CLAUSE that is a simple proposition made of:
a subject (ENTITY),
an AUXILIARY_VERB,
a verb (an ENTITY),
a list of objects (LIST_OF_ENTITIES)
Example:
Waiter W is working when waiter W serves a drink.
Corresponding ASP:¶
working(W) :- serve(W,DRNK_D), drink(DRNK_D), waiter(W).