Problem
The six following persons arrived first at the marathon of New York, but we do not know their rankings. However, we have the following additional information:

Mac, although he started last, was not last.

Jane, Bob and Ulf started first, but they had a problem after 30 kilometers, still they arrived before Alf and Mac.

Jane who was third last year has a better ranking this year.

Lala was last till kilometer 15, but then she catched up and and finally arrived in the first four.

Bob was not second nor third.

Ulf beated Alf by three positions.

Although Jane was a long time behind Bob, they both did not arrive fourth.
Find the ranking of the six runners. This problem is from [1], problem 14.3.
Modeling Steps
Introduce two sets n = {1…6} for the ranking and r for the six runners.

We define a Boolean proposition (a binary variable) x_{r,n} which is true (or = 1) if the runner r has ranking n otherwise it is false (or = 0).

Each runner has a single ranking and each ranking is attributed to each runner. Hence :

(I1) Mac was not last, is: ¬x_{Mac,6}. An equivalent mathematical form is: x_{Mac,6} = 0.

(I2) Jane, Bob and Ulf did not arrive fifth or sixth :
(I3) Jane arrived first or second :

(I4) Lala arrived in the first fourth :

(I5) Bob was neither second nor third :

(I6) Rank difference between Ulf and Alf is 3 :
(I7) Bob and Jane both are not fourth :
model logpuzz "The 6Runners Puzzle";
set
n := [1..6] "rank";
r := [Jane,Bob,Alf,Mac,Lala,Ulf] "runner";
binary variable x{r,n};
constraint
A{r}: sum{n} x = 1;
B{n}: sum{r} x = 1;
I1 : ~x['Mac',6];
I2 : nor{nn>4} (x['Jane',n] or x['Bob',n] or x['Ulf',n]);
I3 : x['Jane',1] or x['Jane',2];
I4 : or{nn<=4} x['Lala',n];
I5 : x['Bob',2] nor x['Bob',3];
I6 : or{nn>3} (x['Ulf',n3] and x['Alf',n]);
I7 : x['Bob',4] nor x['Jane',4];
solve;
Write{n}('rank %1d : %s' n', n, {rx} r);
end
Solution
The ranking is: 1. Bob, 2. Jane, 3. Ulf, 4. Lala, 5. Mac, 6. Alf
Further Comments
We gave here a purely Boolean formulation of the constraints I1 to I7. Certainly, it would be easier for certain conditions to formulated them directly in a mathematical way. For example I2 could be formulated as a sum :
The same is true for I4, it is :
Constraint I5 and I7 can be specified again as a variable fixing:
Some additional work is needed for I6. We introduce three additional binary variable y_{4}, y_{5}, and y_{6}. Then constraint I6 can be written as:
This formulation is produced by LPL automatically.
References
[1] Guéret Ch., Prins Ch., and M. Sevaux. Programmation linéaire, 65 problèmes d’optimisation modélisés et résolus avec Visual Xpress. Eyrolles, 2000.
[2] MatMod. Homepage for Learning Mathematical Modeling : https://matmod.ch.
[3] Hürlimann T. Reference Manual for the LPL Modeling Language, most recent version. https://matmod.ch/lpl/doc/manual.pdf.