" /> My Constraint Programming Blog: January 2011 Archives

« December 2010 | Main | February 2011 »

January 27, 2011

FlatZinc solver fzn2smt 2.0 released

One of the new contestants in MiniZinc Challenge 2010 was fzn2smt and it did quite well:
  • Silver medal in the Free search category
  • Tied gold medal (with Gecode) in the Parallel search category
(For more details about the challenge, see the CP2010 presentation.)

From the fzn2smt page:
fzn2smt is a compiler from the FlatZinc language to the standard SMT-LIB language version 1.2. SMT stands for Satisfiability Modulo Theories: the problem of deciding the satisfiability of a formula with respect to background theories --such as linear arithmetic, arrays, etc-- for which specialized decision procedures do exist.

fzn2smt was designed with the idea in mind of help testing the adequacy of SMT technology outside the field of verification, where it has its roots. It aims at solving CSP instances with state-of-the art SMT solvers, by taking profit of recent advances in this tools and other already well-established and powerful implementation features of SAT technology such as non-chronological backtracking, learning and restarts, which seem to be rarely exploited in the context of Constraint Programming.

fzn2smt supports all standard data types and constraints of FlatZinc. The logic required for solving each instance is determined automatically during the translation, and the translation is done in a straightforward way at the current stage of development. Search annotations are ignored, as they do not make sense in the context of SMT. Only the alldifferent and cumulative MiniZinc global constraints are supported (encoding them into SMT).

The fzn2smt compiler is written in Java, and uses the ANTLR runtime for parsing. Working in cooperation with an SMT solver, fzn2smt is able to solve decision problems as well as optimization problems. However, since most SMT solvers do no support optimization, we have currently implemented it by means of iterative calls performing a binary search on the domain of the variable to optimize.

The output of fzn2smt could be fed into any SMT solver supporting the standard SMT-LIB language. By default works in conjunction with Yices 2 with the authorization of their authors, and was intended to be used only in the MiniZinc Challenge 2010, where the tool made good results.
See the fzn2smt page for installation instructions.

Some comments

fzn2smt can sometimes solve problems fast where other more "traditional" CP solvers takes longer time. However, since fzn2smt can only generate a single solution it is less useful for problems when all solutions are required, or for checking if a problem has a unique solution (e.g. for debugging a model). Since I use fzn2smt mostly for harder/larger problem I allow Java 4Gb of use: java -Xmx4096M fzn2smt -ce "yices -f" -i file.fzn

It's great that we now have yet another powerful tool for solving MiniZinc/FlatZinc problems.

January 16, 2011

Some new Answer Set Programming Programs

Here are some new Answer Set Programming (ASP) programs not mentioned before. They are in about the order they where implemented. All of them are also at my Answer Set Programming page.

Other implementations: Almost all of these problem have been implemented earlier in a couple of CP systems, but instead of linking to all of these individually, I have linked to the problem entry at my Common constraint programming problems. That page contains all of the problems that have been implemented in at least two different CP systems (242 as of writing), and now also contains my ASP programs (83 right now). There are 59 problems which has been been implemented in at least 6 systems. (4 problems has been implemented in all 12 systems:(Survo Puzzle, Seseman, Quasigroup Completion, and Coins Grid).

Finding celebrities

Encoding: finding_celebrities.lp

From Uwe Hoffmann's Finding celebrities at a party (PDF):
Problem: Given a list of people at a party and for each person the list of people they know at the party, we want to find the celebrities at the party. A celebrity is a person that everybody at the party knows but that only knows other celebrities. At least one celebrity is present at the party.
(The paper includes an implementation in Scala.)

In summary: Find some distinct clique where everyone known a celebrity, and all celebrities only know all other celebrities.

Here's the code:

knows(adam, dan;alice;peter;eva).
knows(dan, adam;alice;peter).
knows(eva, alice;peter).
knows(alice, peter).
knows(peter, alice).

person(X) :- knows(X, _).
num_p(N) :- N = #sum [person(P) ].

% 1) a person is a celebrity if everyone
% knows P
celebrity(C) :-
N-1 { knows(P, C) : person(P) } N-1.

% 2) and the celebrities only know other
% celebrities, i.e.
% C is not a celebrity if he/she
% knows anyone that is not a celebrity)
:- celebrity(C), person(C), not celebrity(P), knows(C, P).

celebrity(alice) celebrity(peter)
See other implementations

Building blocks

Encodings: building_blocks.lp
building_blocks2.lp: faster version

From Brown Buffalo logic puzzle collection (with implementations in Prolog): BuildingBlocksClues:
Each of four alphabet blocks has a single letter of the alphabet on each of its six sides. In all, the four blocks contain every letter but Q and Z. By arranging the blocks in various ways, you can spell all of the words listed below. Can you figure out how the letters are arranged on the four blocks?



This was quite easy to implement. However, here - as well as in some other ASP encodings - I really miss the global constraint alldifferent that is so convenient in constraint programming systems. Here is my first version of ensuring that the letters of a word (L1, L2, L3, L4) should be on a different die. The words are represented as word(b,a,k,e)..
% the letters of each word must be on
% difference dice
diff(L1,L2,L3,L4) :-
    % explicitly state the diffs
    D1 != D2, 
    D1 != D3,
    D1 != D4,
    D2 != D3,
    D2 != D4,
    D3 != D4.
:- not diff(L1,L2,L3,L4), 
Performance: It takes 1 minute and 10 seconds for gringo/clasp to generate all 24 solutions. The grounding takes much of this time: 30 seconds.

The second version, building_blocks2.lp, use another representation, where the words instead are defined as

word(1, b).
word(1, a).
word(1, k).
word(1, e).
% ...

Or shorter as word(1, b;a;k;e)..

Now we can encode the problem as:


1 { letter(Letter, Dice) : d(Dice) } 1 :- letters(Letter).
6 { letter(Letter, Dice) : letters(Letter) } 6 :- d(Dice).

:- words(W),
word(W, L1),
word(W, L2),
L1 < L2,

Performance: This version is much faster than the first approach. Generating all 24 solution now takes 10 seconds (which essentially is the grounding time).
But it's still slow: all the CP implementations generates all solutions well under one second.

See other implementations

Labeled dice

Encoding: labeled_dice.lp

From Jim Orlin's Colored letters, labeled dice: a logic puzzle:
My daughter Jenn bough a puzzle book, and showed me a cute puzzle. There are 13 words as follows: BUOY, CAVE, CELT, FLUB, FORK, HEMP, JUDY, JUNK, LIMN, QUIP, SWAG, VISA, WISH.

There are 24 different letters that appear in the 13 words. The question is: can one assign the 24 letters to 4 different cubes so that the four letters of each word appears on different cubes. (There is one letter from each word on each cube.) It might be fun for you to try it. I'll give a small hint at the end of this post. The puzzle was created by Humphrey Dudley.
The encoding is very similar to the building blocks problem (see above)

See other implementations

SEND+MORE=MONEY, variant with fixed M

Encoding: send_more_money_b.lp

In A first look at Answer Set Programming I complained that Clingo was very slow on these kind of alphametic puzzles (the reason was the grounding time). However, when M is fixed to the value 1 it takes just 5 seconds to solve it, in comparison to 45 seconds when M is "free" (i.e. just > 0).

Project Euler problem 1

Encoding: euler1.lp

Project Euler problem 1:
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.
Here is the complete model.

#const n=1000.
mod_test(N) :- number(N), N #mod 3 == 0.
mod_test(N) :- number(N), N #mod 5 == 0.

total(Sum) :- Sum = #sum [mod_test(N) : number(N) : N < n = N].

#show total(Sum).

Note that the two mod_test predicates are to be seend as or, i.e. either multiple of 3 or multiple of 5.

Project Euler problem 2

Encoding: euler2.lp

Project Euler problem 2 involving Fibonacci numbers.
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... Find the sum of all the even-valued terms in the sequence which do not exceed four million.
#const n=45. % max value of N
#const limit = 4000000.


fib(0, 1).
fib(1, 1).
fib(N, X1 + X2) :- number(N), N > 1, fib(N - 1, X1), fib(N - 2, X2).

total(Sum) :- Sum = #sum [fib(N, Res) : Res < limit : Res #mod 2 == 0 = Res].

The predicate total(Sum) contains the answer.

Prime numbers, small excursion in number theory

Encoding: prime_number.lp

This is small excursion in number theory. Unfortunately gringo don't support arbitrary precision, and the grounding takes long time so this is usable only for small(ish) numbers.

Some definition of primes:

A number N is a prime number if there is no number I: 2..N / 2 such that N % I == 0.

This translates quite well in ASP, where the set notation ({ ... } 0) mean that the set should be empty, i.e. the cardinality of the set is 0.

prime(N) :- number(N), N > 1, { number(I) : I > 1 : I < 1+(N #div 2) : N #mod I == 0} 0.

Another way of defining prime numbers: A number N ( > 1) is a prime number if it has no divisors.

divisor(N, I) :- number(I), I > 1, I < 1+(N #div 2), N #mod I == 0, number(N), N > 1.
prime2(N) :- number(N), N > 1, {divisor(N,I) : number(I) } 0.

A Coin problem

Encoding: coins3.lp

From "The ECLiPSe Book" pages 99f and 234 ff (the ECLiPSe encoding is at page 236.).
What is the minimum number of coins that allows one to pay _exactly_ any amount smaller than one Euro? Recall that there are six different euro cents, of denomination 1, 2, 5, 10, 20, 50
This was harder than I first thought, and was on the wrong track at first. The solution I settled on was to define x(Coin, N) so that N is the maximum value for the N in y (the "matrix" for all combinations of values).

#const max_val = 99.
#const max_amount = 5.
val(1..max_val). % total
amount(0..max_amount). % max amount per coin

% ensure that all number 1..max_val
% are summed in some way
Value #sum [y(Value, Coin, N) : coins(Coin) : N*Coin <= Value : amount(N) = N*Coin] Value :- val(Value).

% x(Coin, N):
% for each coins Coin, N is the maximum value
% in all y's for this Coin
x(Coin, N) :-
N = #max[y(Value, Coin, N2) : val(Value) : amount(N2) = N2].

total(Total) :- Total = #sum [x(Coin, N) = N].

% Object: Minimize the total number of coins.
#minimize [x(Value, N) = N].

See other implementations

Set Covering Deployment

Encoding: set_covering_deployment.lp

From Math World SetCoveringDeployment:
Set covering deployment (sometimes written "set-covering deployment" and abbreviated SCDP for "set covering deployment problem") seeks an optimal stationing of troops in a set of regions so that a relatively small number of troop units can control a large geographic region. ReVelle and Rosing (2000) first described this in a study of Emperor Constantine the Great's mobile field army placements to secure the Roman Empire.
Here is my encoding, except for the matrix of neighbour regions (in matrix(Region1, Region2):

#const n=8. % number of cities

% unique indices of the cities
1 { x(City, Army1, Army2) : army(Army1;Army2) } 1 :- cities(City).

% Constraint 1: There is always an army in a city (+ maybe a backup)
% Or rather: Is there is a backup, there must be an an army
:- x(City, Army1, Army2), Army1 < Army2.

% Constraint 2: There should always be an backup army near every city
:- x(City, Army11, Army12), S = #sum[ x(City2, Army21, Army22) : matrix(City, City2) = Army22], Army11 + S < 1.

% show the selected cities with name
selected(City, Name, Army1, Army2) :- x(City, Army1, Army2), Army1 > 0, name(City, Name).

#minimize [x(City, Army1, Army2) = Army1 + Army2].

The solution found is the following:
selected(3,britain,1,1) selected(1,alexandria,1,1)
which means that we should place one army and one reserv in each britain and alexandria.

(There are 6 optimal solutions of this problem.)

See other implementations

Sicherman Dice

Encoding: sicherman_dice.lp

From Wikipedia Sicherman_dice:
Sicherman dice are the only pair of 6-sided dice which are not normal dice, bear only positive integers, and have the same probability distribution for the sum as normal dice.

The faces on the dice are numbered 1, 2, 2, 3, 3, 4 and 1, 3, 4, 5, 6, 8.
#const n = 6. % number of side per die
#const m = 10. % max integer on a die
#const start = 1. % start value (set to 0 for the extra two solutions)

% standard distribution of 2 dice
dist(2, 1). dist(3, 2). dist(4, 3).
dist(5, 4). dist(6, 5). dist(7, 6).
dist(8, 5). dist(9, 4). dist(10,3).
dist(11,2). dist(12,1).

dist_sums(S) :- dist(_, S).

1 { d1(Side, Value) : values(Value) } 1 :- sides(Side).
1 { d2(Side, Value) : values(Value) } 1 :- sides(Side).

% combine the dice so we can #sum over them
comb(S1,V1,S2,V2) :- d1(S1,V1), d2(S2,V2).
1 { comb(S1,V1,S2,V2) : values(V1;V2) } 1 :- sides(S1;S2).

% symmetry breaking
:- d1(S1a,V1a), d1(S1b,V1b), S1a < S1b, V1a > V1b.
:- d2(S2a,V2a), d2(S2b,V2b), S2a < S2b, V2a > V2b.
:- d1(S,V1),d2(S,V2), V1 > V2.

Sum #sum [ comb(S1, V1, S2, V2) : sides(S1;S2) : values(V1;V2) : V1+V2 == K] Sum :- dist(K, Sum).

#show d1(Side, Value).
#show d2(Side, Value).

And it shows the two solutions mentioned above.

See other implementations

Set Partition

Encoding: set_partition.lp

Problem formulation taken from Koalog (could not find the exact page now)
This is a partition problem.
Given the set S = {1, 2, ..., n},
it consists in finding two sets A and B such that:
- A U B = S
- |A| = |B|
- sum(A) = sum(B)
- sum_squares(A) = sum_squares(B)
See other implementations

Averbach problem 1.4

Encoding: averbach_1.4.lp

Problem 1.4 from the book "Problem Solving Through Recreational Mathematics" by Averbach and Chein.
Messr Baker, Dyer, Farmer, Glover, and Hosier are seated around a circular table, playing poker. Each gentleman is the namesake of the profession of one of the others.

The dyer is seated two places to the left of Mr Hosier.
The baker sits two places to Mr Baker's right.
The farmer is seated to the left of Mr Farmer.
Mr Dyer is on the glover's right.

What is the name of the dyer?
This is one of my standard problem for testing the modulo operator (#mod in Clingo). The constraint The dyer is seated two places to the left of Mr Hosier. (which may be stated as dyer = (Hosier - 2) mod 5 in, say, MiniZinc) is translated into:

:- x(_, p_dyer, P1), x(n_hosier, _, P2), P1 != (P2 - 2) #mod 5.

The integrity constraint means that we remove all the solutions that contains the stated condition (hence the !=). Sometimes it's confusing to state the constraint in this manner; on the other hand sometimes it's very convenient.

See other implementations

Scheduling speakers

Encoding: scheduling_speakers.lp

Scheduling of 6 speakers in 6 slots. From Rina Dechter, Constraint Processing, page 72.

See other implementations

Traffic lights problem, CSPLib #16

Encoding: traffic_lights.lp

This is a small problem from the CSPLib where the object is to find different combinations of lights for cars and pedestrians.

See other implementations

Daily schedule, small scheduling problem

Encoding: daily_schedule.lp

This is a small problem I found the other day at the site for the logic programming system Hansei (in ML):
Solving the logical puzzle (scheduling problem) posed by Mikael More on October 25, 2010:

For the daily schedule for Monday to Wednesday:
One of the days I'll shop.
One of the days I'll take a walk.
One of the days I'll go to the barber.
One of the days I'll go to the supermarket.
The same day as I go to the supermarket, I'll shop.
The same day as I take a walk I'll go to the barber.
I'll go to the supermarket the day before the day I'll take a walk.
I'll take a walk Tuesday.

Which are all possible daily schedules, regarding those four events?

That is, on Monday I go to the supermarket and shop, on Tuesday I walk and take a haircut. There is only one schedule satisfying the constraints.
It is as direct as possible:

% an action is done exactly once
1 { x(Day, Action) : days(Day) } 1 :- actions(Action).
% The same day as I go to the supermarket, I'll shop.
:- x(Day1, supermarket), x(Day2, shop), Day1 != Day2.
% The same day as I take a walk I'll go to the barber.
:- x(Day1, walk), x(Day2, barber), Day1 != Day2.
% I'll go to the supermarket the day before the day I'll take a walk.
:- x(Day1, supermarket), x(Day2, walk), Day1 >= Day2.
% I'll take a walk Tuesday.
x(tuesday, walk).

Zebra problem

Encoding: zebra.lp

From Wikipedia: Zebra_Puzzle
1. There are five houses.
2. The Englishman lives in the red house.
3. The Spaniard owns the dog.
4. Coffee is drunk in the green house.
5. The Ukrainian drinks tea.
6. The green house is immediately to the right of the ivory house.
7. The Old Gold smoker owns snails.
8. Kools are smoked in the yellow house.
9. Milk is drunk in the middle house.
10. The Norwegian lives in the first house.
11. The man who smokes Chesterfields lives in the house next to the man with the fox.
12. Kools are smoked in the house next to the house where the horse
is kept. (should be ".. a house ...", see Discussion section)
13. The Lucky Strike smoker drinks orange juice.
14. The Japanese smokes Parliaments.
15. The Norwegian lives next to the blue house.

Now, who drinks water? Who owns the zebra? In the interest of clarity, it must be added that each of the five houses is painted a different color, and their inhabitants are of different national extractions, own different pets, drink different beverages and smoke different brands of American cigarets [sic]. One other thing: in statement 6, right means your right.
The complete code:

% domains

% 1. There are five houses.

% alldifferents
1 { color(House, Color) : colors(Color) } 1 :- houses(House).
1 { color(House, Color) : houses(House) } 1 :- colors(Color).

1 { nationality(House, Nationality) : nationalities(Nationality) } 1 :- houses(House).
1 { nationality(House, Nationality) : houses(House) } 1 :- nationalities(Nationality).

1 { animal(House, Animal) : animals(Animal) } 1 :- houses(House).
1 { animal(House, Animal) : houses(House) } 1 :- animals(Animal).

1 { drink(House, Drink) : drinks(Drink) } 1 :- houses(House).
1 { drink(House, Drink) : houses(House) } 1 :- drinks(Drink).

1 { smoke(House, Cigarette) : cigarettes(Cigarette) } 1 :- houses(House).
1 { smoke(House, Cigarette) : houses(House) } 1 :- cigarettes(Cigarette).

next_to(H1,H2) :- houses(H1;H2), |H1-H2| == 1.

% 2. The Englishman lives in the red house.
:- color(H1, red), nationality(H2, english), H1 != H2.

% 3. The Spaniard owns the dog.
:- nationality(H1, spaniard), animal(H2,dog), H1 != H2.

% 4. Coffee is drunk in the green house.
:- color(H1, green), drink(H2, coffee), H1 != H2.

% 5. The Ukrainian drinks tea.
:- nationality(H1, ukrainian), drink(H2, tea), H1 != H2.

% 6. The green house is immediately to the right of the ivory house.
:- color(H1, green), color(H2, ivory), H1 != H2 + 1.

% 7. The Old Gold smoker owns snails.
:- smoke(H1,old_gold), animal(H2, snails), H1 != H2.

% 8. Kools are smoked in the yellow house.
:- smoke(H1, kools), color(H2, yellow), H1 != H2
% 9. Milk is drunk in the middle house.
:- not drink(3, milk).

% 10. The Norwegian lives in the first house.
:- not nationality(1,norwegian).

% 11. The man who smokes Chesterfields lives in the house next to the man with the fox.
:- smoke(H1, chesterfields), animal(H2, fox), not next_to(H1,H2).

% 12. Kools are smoked in the house next to the house where the horse
% is kept. (should be ".. a house ...", see Discussion section)
:- smoke(H1, kools), animal(H2, horse), not next_to(H1,H2).

% 13. The Lucky Strike smoker drinks orange juice.
:- smoke(H1, lucky_strike), drink(H2, orange_juice), H1 != H2.

% 14. The Japanese smokes Parliaments.
:- nationality(H1, japanese), smoke(H2, parliaments), H1 != H2.

% 15. The Norwegian lives next to the blue house.
:- nationality(H1, norwegian), color(H2, blue), not next_to(H1, H2).

has_zebra(Nationality) :- nationality(House, Nationality), animal(House, zebra).
drinks_water(Nationality) :- nationality(House, Nationality), drink(House,water).

% for output:
house(House, Color, Nationality, Animal, Drink, Cigarette) :-
color(House, Color),
nationality(House, Nationality),
animal(House, Animal),
drink(House, Drink),
smoke(House, Cigarette).

See other implementations


Encoding: kenken2.lp

Wikipedia: KenKen
KenKen or KEN-KEN is a style of arithmetic and logical puzzle sharing several characteristics with sudoku. The name comes from Japanese and is translated as "square wisdom" or "cleverness squared".
The objective is to fill the grid in with the digits 1 through 6 such that:

* Each row contains exactly one of each digit
* Each column contains exactly one of each digit
* Each bold-outlined group of cells is a cage containing digits which
achieve the specified result using the specified mathematical operation:
addition (+),
subtraction (-),
multiplication (x),
and division (/).
(Unlike in Killer sudoku, digits may repeat within a group.)

More complex KenKen problems are formed using the principles described above but omitting the symbols +, -, x and/, thus leaving them as yet another unknown to be determined.
It took a while to get both principal representation and then the conditions correct. The hints are represented with the operators explicitly stated:

p("+", 11, 1,1, 2,1).
p("/", 2, 1,2, 1,3).

Here are some of constraints for handling 2 parameter hints. % 2 arguments
:- p("+", Res, X1,X2, Y1,Y2), x(X1,X2, A), x(Y1,Y2, B), A+B != Res.
:- p("*", Res, X1,X2, Y1,Y2), x(X1,X2, A), x(Y1,Y2, B), A*B != Res.

See other implementations

17x17 grid problem

Encoding: 17.lp

I wrote about this grid problem last August in Nontransitive dice, Ormat game, 17x17 challenge.

This ASP encoding solves 14x14 quite fast (< 1 second) using the following parameters:

clingo -c num_rows=14 -c num_cols=14 --stat --heuristic=Vsids --restarts=2000,1.5 --shuffle=1,1 17.lp

with these statistics:
Time        : 0.470
  Prepare   : 0.220
  Prepro.   : 0.050
  Solving   : 0.200
Choices     : 5276
Conflicts   : 3881
Restarts    : 1
However, for larger values (n = 15..16) and experimenting with different solve parameters, I have had no luck.


Encoding: kakuro.lp

Kakuro is yet another grid puzzle. From Wikipedia: Kakuro:
The object of the puzzle is to insert a digit from 1 to 9 inclusive into each white cell such that the sum of the numbers in each entry matches the clue associated with it and that no digit is duplicated in any entry. It is that lack of duplication that makes creating Kakuro puzzles with unique solutions possible, and which means solving a Kakuro puzzle involves investigating combinations more, compared to Sudoku in which the focus is on permutations. There is an unwritten rule for making Kakuro puzzles that each clue must have at least two numbers that add up to it. This is because including one number is mathematically trivial when solving Kakuro puzzles; one can simply disregard the number entirely and subtract it from the clue it indicates.
The encoding is quite fast, solves the problem instance in 0.090s. However, it isn't very general since it only supports clues of length 2..5. Also, it's a tedious job stating the alldifferent constraint for the different arguments.

See other implementations

Young Tableaux and partition

Encoding: young_tableaux.lp

See Wikipedia: Young_tableau:
A Young diagram (also called Ferrers diagram, particularly when represented using dots) is a finite collection of boxes, or cells, arranged in left-justified rows, with the row lengths weakly decreasing (each row has the same or shorter length than its predecessor).
Also see MathWorld: YoungTableau.

The five partitions of 4 are

{4}, {3,1}, {2,2}, {2,1,1}, {1,1,1,1}

The corresponding standard Young tableaux are:
1.   1 2 3 4

2.   1 2 3         1 2 4    1 3 4
     4             3        2

3.   1 2           1 3
     3 4           2 4

4    1 2           1 3      1 4 
     3             2        2 
     4             4        3

5.   1
I thought this should be quite complicated to implement my standard approach of this in ASP. But actually it was quite easy to translate from the MiniZinc model:

See other implementations

Airline crew allocation

Encoding: crew.lp

From the Gecode example crew:
Example: Airline crew allocation Assign 20 flight attendants to 10 flights. Each flight needs a certain number of cabin crew, and they have to speak certain languages. Every cabin crew member has two flights off after an attended flight.
This encoding solves the problem very fast for a schedule all 20 flight attendants, which is the object. However, if we regard it as an optimization problem where the object is to minimize the number of person filling the schedule (i.e. 19), it takes "forever". It finds 19 very fast, but to prove it takes very long (as do many CP system).

See other implementations

Pi Day Sudoku 2009

Encodings: sudoku_pi.lp
sudoku_pi_gcc.lp: with "occurrence count"

Via 360's: Pi Day Sudoku 2009:
Each row, column, and region contains the digits 1-9 exactly once plus three [Pi] symbols. There's a printable .pdf file here
Also see BrainFrees Puzzles: Pi Day 2009.
This was quite easy to encode but very time consuming to convert all the 12 regions to predicates. The cardinality constraints ("exact 3 occurrences of Pi") is encoded quite directly in ASP.

#const n=12.

% domains
regions(Region) :- region(Region, _, _).

% unique index
1 { x(Row, Col, Val) : val(Val) } 1 :- rows(Row), cols(Col).

% assign hints
x(Row, Col, Val) :- hint(Row, Col, Val).

% all different 1..9
1 { x(Row, Col, Val) : rows(Row) } 1 :- val1_9(Val), cols(Col).
1 { x(Row, Col, Val) : cols(Col) } 1 :- val1_9(Val), rows(Row).

% 3 occurrences of pi per row and column
3 { x(Row, Col, p) : cols(Col) } 3 :- rows(Row).
3 { x(Row, Col, p) : rows(Row) } 3 :- cols(Col).

% handle the regions
% all different for 1..9 in regions
1 { x(Row, Col, Val) : region(Region, Row, Col) } 1 :- regions(Region), val1_9(Val).

% 3 occurrences of pi in the regions
3 { x(Row, Col, p) : region(Region, Row, Col) } 3 :- regions(Region).

However, I miss the generality of the global constraint global cardinality count, and did implement (in sudoku_pi_gcc.lp) some sort of ersatz which handles both the 1 and 3 counts (by the value Occ for each value occ(Val, Occ) instead of stating them separately:

% occ(Number, Occurrences).
occ(1;2;3;4;5;6;7;8;9, 1).
occ(p, 3).

% ..
% rows and columns
Occ { x(Row, Col, Val) : rows(Row) } Occ :- val1_9(Val), cols(Col), occ(Val, Occ).
Occ { x(Row, Col, Val) : cols(Col) } Occ :- val1_9(Val), rows(Row), occ(Val, Occ).
% handle the regions
Occ { x(Row, Col, Val) : region(Region, Row, Col) } Occ :- regions(Region), val1_9(Val), occ(Val, Occ).

Both versions solve the problem in about 0.04 seconds but have slightly different number of choices and conflicts:

sudoku_pi.lp: 7 choices, 2 conflicts, 0 restarts
sudoku_pi_gcc.lp: 39 choices, 12 conflicts, 0 restarts

Steiner triplets

Encoding: steiner.lp

This implements the Steiner triplet problem. Formulation from BProlog
The ternary Steiner problem of order n is to find n(n-1)/6 sets of elements in {1,2,...,n} such that each set contains three elements and any two sets have at most one element in common.

For example, the following shows a solution for size n=7:

{1,2,3}, {1,4,5}, {1,6,7}, {2,4,6}, {2,5,7}, {3,4,7}, {3,5,6}

Problem taken from:
C. Gervet: Interval Propagation to Reason about Sets: Definition and Implementation of a PracticalLanguage, Constraints, An International Journal, vol.1, pp.191-246, 1997.
Also see MathWorld SteinerTripleSystem.

I'm not really happy with this encoding. It could probably be done in a more neater way since modeling set constraints is quite natural in ASP. Also, I have not found a way of encode a good symmetry breaking to ensure that the sets are in increasing order.

#const n = 7.
#const nb = n * (n-1) #div 6.
% domain

0 { x(Set, Val) } 1 :- sets(Set), val(Val).

% 3 values of each set
3 { x(Set, Val) : val(Val) } 3 :- sets(Set).

% count the number of common occurrences of each pair of Sets
check(Set1, Set2, Val, N) :-
Set1 < Set2,
N = #count { x(Set1,Val), x(Set2,Val) }.

% ensure that there are at most 1 occurrence
% with the same value (i.e. N=2) for any two sets.
:- sets(Set1;Set2), Set1 < Set2, 2 #sum[check(Set1, Set2, Val, N) : N == 2 ].

Here are some statistics for clingo for generating 1 solution with default parameters:
n    time   Choices Conflicts Restarts
 7    0.01s    183     116      1
 9    0.02s    412     136      1
13    0.33s   6269    2385      6
15    2.35s  22801   13755     10
19    > 2h
With --restarts=10,2.5 it's a bit faster, but not much.
 7    0.01s     57     20      1
 9    0.03s    833    329      4
13    0.32s   6516    2387     6
15    0.46s   6744    1134     5
19    ?

See other implementations

January 09, 2011

Rogo grid puzzle in Answer Set Programming (Clingo) and MiniZinc

ASP (Clingo): rogo.lp, rogo2.lp
MiniZinc: rogo.mzn, rogo2.mzn
(See below for some problem instances.)

Later update: I have now also implemented versions with symmetry breaking constraints in the two encodings: rogo2.lp and rogo2.mzn. See below for more into

In Operations Research, Sudoko, Rogo, and Puzzles Mike Trick presented the Rogo puzzle, a grid puzzle where the object is to find a loop of a number of steps and get as many points as possible. He writes
The loop must be a real loop: it must return where it started and can’t cross itself or double back. Steps can be either horizontal or vertical: they cannot be diagonal. The loop cannot include any of the black squares. ... Rogo was created by two faculty members (Nicola Petty and Shane Dye)  at the University of Canterbury in Christchurch, New Zealand.  Not surprisingly, Nicola and Shane teach management science there:  the problem has a very strong operations research flavor.
From Creative Heuristics Ltd (the Rogo puzzle site): Rogo is an entirely new type of puzzle. The object is to collect the biggest score possible using a given number of steps in a loop around a grid. The best possible score for a puzzle is given with it, so you can easily check that you have solved the puzzle. Rogo puzzles can also include forbidden squares, which must be avoided in your loop..

Below I have assumed that the path must be in exactly the given number of steps and the programs are written with this assumption in mind (and further reading of the problem descriptions support this interpretation). However, my first approach - probably caused by sloppy reading - was that the optimal path could possible be in lesser steps. It took several hours trying to implement a program supporting this, but was abandoned after re-reading of the problem descriptions. This seems to be a harder problem; maybe it could be used as a variant of the original problem?

I was inspired to solve these puzzle in part because of Mike's last words: Creating a solver would make a nice undergraduate project (and I suspect there are at least a few master's theses and perhaps a doctoral dissertation on algorithmic aspects of creating and solving these). One other reason was to see how to do this with Answer Set Programming - here using Clingo (a Potassco tool) and to compare it with a Constraint Programming system, MiniZinc.

Some more links about Rogo:
  • Instructions
  • Rogo blog
  • YouTube clip.
  • Nicola Petty, Shane Dye: Determining Degree Of Difficulty In Rogo, A TSP-based Paper Puzzle (PDF)
    From the Conclusions: The Rogo puzzle format has a number of aspects that can be controlled to potentially affect degree of difficulty of solving. As a pilot, this study showed that there are many aspects of puzzle-solving related to the nature of the puzzle that can be explored, and there appear to be some general effects, though there are still marked individual differences between people solving the puzzles. This research has the potential to provide interesting insights into both human behaviour, and the nature of puzzles.

    Note: I didn't noticed this until I was almost finished with this blog post (and have just glanced through it).


Here is the Rogo example from Mike Trick's site (pictures borrowed from his site; click on them for larger versions).


Rogo puzzle, problem.

One solution:

Rogo puzzle, solution

Note that there is not an unique solution to these puzzles. All three problem instances I tested have more than one solution. For example, the Mike Trick problem has 48 solutions including path symmetries. Since there are 12 steps there are (removing the path symmetry) 48 / 12 = 4 distinct different paths. These different paths are shown below as MiniZinc solutions, where the first step have been fixed to (2,2), i.e. x[1]=2 and y[1]=2<, and it has 3 points (points[1]):

points = array1d(1..12, [3, 0, 0, 2, 0, 0, 2, 0, 0, 1, 0, 0]);
x = array1d(1..12, [2, 3, 4, 4, 5, 5, 5, 4, 3, 2, 2, 2]);
y = array1d(1..12, [2, 2, 2, 3, 3, 4, 5, 5, 5, 5, 4, 3]);
points = array1d(1..12, [3, 0, 0, 2, 0, 0, 2, 0, 0, 1, 0, 0]);
sum_points = 8;
x = array1d(1..12, [2, 3, 3, 4, 5, 5, 5, 4, 3, 2, 2, 2]);
y = array1d(1..12, [2, 2, 3, 3, 3, 4, 5, 5, 5, 5, 4, 3]);
points = array1d(1..12, [3, 0, 0, 1, 0, 0, 2, 0, 0, 2, 0, 0]);
sum_points = 8;
x = array1d(1..12, [2, 2, 2, 2, 3, 4, 5, 5, 5, 4, 3, 3]);
y = array1d(1..12, [2, 3, 4, 5, 5, 5, 5, 4, 3, 3, 3, 2]);
points = array1d(1..12, [3, 0, 0, 1, 0, 0, 2, 0, 0, 2, 0, 0]);
sum_points = 8;
x = array1d(1..12, [2, 2, 2, 2, 3, 4, 5, 5, 5, 4, 4, 3]);
y = array1d(1..12, [2, 3, 4, 5, 5, 5, 5, 4, 3, 3, 2, 2]);

Answer Set Programming, Clingo

Here is the full ASP (Clingo) encoding, without the data:

% domains

% max number of steps

% define adjacency between cells
adj(R,C, R1,C1) :- rows(R;R1), cols(C;C1), |R-R1| + |C-C1|==1.

% the path: unique index
0 { path(I, Row, Col) : steps(I) } 1 :- rows(Row), cols(Col).
1 { path(I, Row, Col) : rows(Row) : cols(Col) } 1 :- steps(I).

% close the circuit: ensure that the first and last cells
% in the path are connected.
:- path(1, R1, C1), path(max_steps, R2, C2), not adj(R1,C1,R2,C2).

% remove bad paths
:- path(I-1,R1,C1), path(I,R2,C2), not adj(R1,C1, R2,C2).

% no black cells in the path
:- path(I, R,C), black(R,C).

% total points, needed since
% "Optimization:" don't show the proper value.
total(Total) :- Total = #sum[got_points(R,C,Value) = Value].

% list the cells in path with points
got_points(R,C, Value) :- point(R,C,Value), path(I, R, C).

% maximize the number of points
% #maximize [ path(I,R,C) : steps(I) : point(R,C,P) = P ].

% alternative: we can add an second objective to
% start with the cell with lowest indices
#maximize [ path(I,R,C) : steps(I) : point(R,C,P) = P@2 ].
#minimize [ path(1,R,C) = R*c+C@1].

#show path(I, Row, Col).
#show total(Total).
#show got_points(R,C,Value).

Here is the encoding for Mike Trick's problem instance:
#const max_steps = 12.
#const r = 5.
#const c = 9.

% the point cells

% black cells (to avoid)
The solution of Mike Trick's problem (edited), using the following command line:
clingo --heuristic=Vmtf --stat rogo_data_mike_trick.lp rogo.lp
total: 8

Statistics for this solution:
Models      : 1     
  Enumerated: 6
  Optimum   : yes
Optimization: 184 20 
Time        : 0.960
  Prepare   : 0.060
  Prepro.   : 0.020
  Solving   : 0.880
Choices     : 19826
Conflicts   : 16539
Restarts    : 1

Atoms       : 912   
Bodies      : 22839 
Tight       : Yes

  Deleted   : 10406 
Update With the following symmetry breaking added, the problem is solved in 0.58 seconds.

% symmetry breaking: the cell with the lowest coordinates
% should be in the first step
:- path(1, R, C), steps(Step), Step > 1, path(Step, R2, C2),
R*c+C > R2*c+C2.

The statistics for this variant:

Time        : 0.580
  Prepare   : 0.080
  Prepro.   : 0.030
  Solving   : 0.470
Choices     : 8727
Conflicts   : 6914
Restarts    : 2
End of update

Some notes:
One nice feature in Clingo (and lparse) is that it is possible to have many optimization objective. Here we we first maximize the number of points (#maximize [ path(I,R,C) : steps(I) : point(R,C,P) = P@2 ] , and as a second objective (with lower priority @1) we minimize the start cell to start with the cell with the lowest coordinate: #minimize [ path(1,R,C) = R*c+C@1].. Sometimes this is faster than the plain #maximize objective, sometimes not.

The size of "core" of the encoding is quite small. Here is the code with the comments and the helper predicates (for outputs) removed.

adj(R,C, R1,C1) :- rows(R;R1), cols(C;C1), |R-R1| + |C-C1|==1.
0 { path(I, Row, Col) : steps(I) } 1 :- rows(Row), cols(Col).
1 { path(I, Row, Col) : rows(Row) : cols(Col) } 1 :- steps(I).
:- path(1, R1, C1), path(max_steps, R2, C2), not adj(R1,C1,R2,C2).
:- path(I-1,R1,C1), path(I,R2,C2), not adj(R1,C1, R2,C2).
:- path(I, R,C), black(R,C).
#maximize [ path(I,R,C) : steps(I) : point(R,C,P) = P ].

The corresponding "core" of the MiniZinc program (see below for the full code) is larger.

Constraint Programming, MiniZinc

Here is the full MiniZinc code (without data). Compared with the ASP approach, the decision variables are represented in another way: the paths is represented by two arrays x and y, and the points are collected in a separate array (points) so we can simply sum over it for the optimization.

include "globals.mzn";

int: W = 0; % white (empty) cells
int: B = -1; % black cells
int: max_val = max([problem[i,j] | i in 1..rows, j in 1..cols]);

% define the problem
int: rows;
int: cols;
int: max_steps; % max length of the loop
array[1..rows, 1..cols] of int: problem;

% the coordinates in the path
array[1..max_steps] of var 1..rows: x :: is_output;
array[1..max_steps] of var 1..cols: y :: is_output;

% the collected points
int: max_point = max([problem[i,j] | i in 1..rows, j in 1..cols]);
array[1..max_steps] of var 0..max_point : points :: is_output;

% objective: sum of points in the path
int: max_sum = sum([problem[i,j] | i in 1..rows, j in 1..cols where problem[i,j] > 0]);
var 0..max_sum: sum_points :: is_output;

% solve satisfy;
solve maximize sum_points;
% solve :: int_search(x ++ y, first_fail, indomain_min, complete) maximize sum_points;

% all coordinates must be unique
constraint forall(s in 1..max_steps, t in s+1..max_steps) (
x[s] != x[t] \/ y[s] != y[t]

% calculate the points (to maximize)
constraint forall(s in 1..max_steps) (
points[s] = problem[x[s], y[s]]
sum_points = sum(points);

% ensure that there are no black cells
% in the path
constraint forall(s in 1..max_steps) (
problem[x[s],y[s]] != B

% get the path
constraint forall(s in 1..max_steps-1) (
abs(x[s] - x[s+1]) + abs(y[s] - y[s+1]) = 1
/\ % close the path around the corner
abs(x[max_steps] - x[1]) + abs(y[max_steps] - y[1]) = 1;

Except for more declaration of the arrays and decision variables, this code don't have more logic than the ASP encoding. However it is more verbose.

The solution for Mike Trick's problem, using LazyFD, takes 1.1 second, slightly slower than using Clingo (see below for more comparison of times):

points = array1d(1..12, [0, 0, 3, 0, 0, 2, 0, 0, 2, 0, 0, 1]);
sum_points = 8;
x = array1d(1..12, [2, 2, 2, 3, 3, 4, 5, 5, 5, 4, 3, 2]);
y = array1d(1..12, [4, 3, 2, 2, 3, 3, 3, 4, 5, 5, 5, 5]);

After some thoughts I decided to try the same symmetry breaking that was an option the ASP encoding. It is implemented in rogo2.mzn and use the following extra constraint that ensure that the cell with the lowest coordinate is in the first step. % symmetry breaking: the cell with lowest coordinates % should be in the first step. constraint forall(i in 2..max_steps) ( x[1]*cols+y[1] < x[i]*cols+y[i] );

With this model, LazyFD solves Mike Trick's problem in 0.627 seconds. Also see under "Comparison" below.

End of update


I was curious how well the systems should do so here is a "recreational" comparison. Please don't read too much into it:
  • it is just 3 problems.
  • there is probably better heuristics for both Clingo and Gecode/fz
The following 3 problem instances was used in the test. Unfortunately, I have not found any direct links for the two latter instances (see below for links to my encodings). Instead a variant of the coding used in MiniZinc is shown, where "_" ("W" in the MiniZinc code) is white/blank, "B" is a black cell to avoid, and a number represent a point of the cell.
  • Mike Trick's example. 5 rows, 9 column, 12 steps; good: 6, best: 8.
    %1 2 3 4 5 6 7 8 9  
     2,_,_,_,_,_,_,_,_, % 1
     _,3,_,_,1,_,_,2,_, % 2
     _,_,_,_,_,_,B,_,2, % 3
     _,_,2,B,_,_,_,_,_, % 4
     _,_,_,_,2,_,_,1,_, % 5
  • The Paper Rogo puzzle from Creative Heuristics Ltd for 20110106. 9 rows, 7 columns, 16 steps; good: 28, best: 31 points.
     %1 2 3 4 5 6 7
      B,_,6,_,_,3,B, % 1
      2,_,3,_,_,6,_, % 2
      6,_,_,2,_,_,2, % 3
      _,3,_,_,B,B,B, % 4
      _,_,_,2,_,2,B, % 5
      _,_,_,3,_,_,_, % 6
      6,_,6,B,_,_,3, % 7
      3,_,_,_,_,_,6, % 8
      B,2,_,6,_,2,B, % 9
  • The Paper Rogo puzzle from Creative Heuristics Ltd for 20110107. 12 rows, 7 columns, 16 steps; good: 34 points, best: 36 points.
     %1 2 3 4 5 6 7
      4,7,_,_,_,_,3, % 1
      _,_,_,_,3,_,4, % 2
      _,_,4,_,7,_,_, % 3
      7,_,3,_,_,_,_, % 4
      B,B,B,_,3,_,_, % 5
      B,B,_,7,_,_,7, % 6
      B,B,_,_,_,4,B, % 7
      B,4,4,_,_,_,B, % 8
      B,_,_,_,_,3,B, % 9
      _,_,3,_,4,B,B, % 10
      3,_,_,_,_,B,B, % 11
      7,_,7,4,B,B,B  % 12
For the ASP encoding I used clingo (a combined grounder and solver) and the parameter --heuristi=Vmtf after some minimal testing with different parameters. For MiniZinc, both solvers LazyFD and Gecode/fz where used and I settled with the search heuristic solve minimize sum_points which seems to be fast enough for this experiment. Note that LazyFD tend to behave best without any explicit search heuristics . (Also: there is always a better search heuristics that the one you settle with.)

The time reported is the total time, i.e. including the grounding time/convert to FlatZinc.

Update I have added the second version of the MiniZinc model with the added symmetry breaking constraint as a separate entry: End of update

Mike Trick problem

Clingo: 0.96 seconds, 19826 choices, 16539 conflicts, 1 restart.
Clingo with symmetry breaking: 58 seconds, 8727 choices, 6914 conflicts, 2 restarts.
LazyFD: 1.1 second. (failure is not reported)
LazyFD with symmetry breaking: 0.6 seconds (failure is not reported)
Gecode/fz: 2.62s, 92113 failures2577853 failures
Gecode/fz: with symmetry breaking: 0.4 seconds, 9418 failures

20110106 problem

Clingo: 1:57.07 minutes, 1155290 choices, 1044814 conflicts, 1 restart
Clingo with symmetry breaking: 20.4 seconds, 157146 choices, 135178 conflicts, 3 restarts
LazyFD: 2:58 minutes
LazyFD with symmetry breaking: 19.9 seconds (failure is not reported)
Gecode/fz: 58.6 seconds, 1380512 failures
Gecode/fz with symmetry breaking: 7.8 seconds, failures

20110107 problem

Clingo: 3:13.72 1541808 choices, 1389396 conflicts, 1 restart
Clingo with symmetry breaking: 31.6 seconds 178301 choices, 151439 conflicts, 1 restart
LazyFD: 2:55.18 minutes
LazyFD with symmetry breaking: 44.5 seconds (failure is not reported)
Gecode/fz: 1:54.50 minutes 2577853 failures
Gecode/fz with symmetry breaking: 11.3 seconds, failures

Here we see that Gecode/fz without (symmetry breaking) is the fastest for the two larger problems (but the slowest on the first), and both Clingo and LazyFD was each placed second in the harder problems. So, I'm not really sure we can draw any real conclusions from this small test.

Update With symmetry breaking added the result is more unanimous. All three solvers benefit much from this. Gecode/fz is faster on all three problems, and the other two still one second place each. We also see how much symmetry breaking can do. End of update

Some comments/conclusions

Here are some general comments about the problem and the coding.


As mentioned above, my initial assumption of the problem was that the given number of steps was not always the best path length, and trying to code this was not easy. After a long time sitting with this approach (say 6 hours coding time?), I re-read the description and couldn't find any real support for this assumption, so I skipped it in favor for the "fixed length" approach.

To get to the final version it took several hours, say 9-10 hours total coding (in smaller sessions over several days). This includes time for coding the initial assumption/interpretation. It also includes the time trying to get the first assumption approach to work with the incremental solver iclingo which - I hoped - should first try the longest length and if that gave no solution it should try at the the lengths in decrement of 1; but I didn't get this to work.

As usual I realized that several of the predicates I first thought was needed could just be thrown away. An example is this snipped to ensure "positive" that there is a path between the cell R1,C1 and the cell R2,C2.

{ x(I-1, R1, C1) : adj(R1,C1, R2,C2) : rows(R1;R2) : cols(C1;C2) : not black(R1,C1) : not black(R2,C2) } max_steps :- x(I, R2, C2), steps(I).

Instead it could be replaced with :- x(I, R,C), black(R,C).
:- x(I-1,R1,C1), x(I,R2,C2), not adj(R1,C1, R2,C2).

Well, I hope that with time I'll recognize these things faster.


It took about 30 minutes to code the MiniZinc model (after a unnecessarily long detour of debugging bad thinking and a bug in the data). The reason for this much shorter time is two-fold:
  • It's much easier to code something when the general strategy (approach) of the problem is known and has been coded in another system. All the (de)tours when writing the ASP version made much more comfortable with the given problem.
  • I'm much more comfortable coding in MiniZinc than in ASP for two reasons: 1) I have programmed in MiniZinc much longer than in ASP. 2) I am also more used with the high-level CP approach of stating the requirements/constraints with traditional loops and using arrays/matrices.
Programs and data files Here are all the files used, both program and data files for the two systems. ASP (Clingo)

January 05, 2011

INFORMS’ first Blog Challenge Results: OR and the Holidays

All 14 entries in INFORMS' December Blog Challenge: O.R. and the Holidays are now available at INFORMS’ first Blog Challenge Results.
INFORMS’ first Blog Challenge was a hit! We received 14 entries on the topic of O.R. and the Holidays. As you might suspect, the travelling salesman problem was noted, with Santa needing to make his marathon delivery to all of the good little girls and boys of O.R. However, the O.R. suggestions for holiday success were not limited to Santa, with the elves receiving tips on inventory optimization, making the most of the family vacation with revenue management, maximizing baking production, a mixing model for picking the teams for the office bowling party, and finding the “perfect” parking spot at the mall. Rounding out the bunch was an interview with “Dr. O.R. Field” about her New Year’s Resolutions. Thanks to everyone who contributed, and a Happy New Year to all.
My own entry was Christmas Company Competition Problem: Mixing teams.

The topic for January 2011 INFORMS Blog Challenge: O.R. and Politics.

January 04, 2011

Antoni Niederliński: A Quick and Gentle Guide to Constraint Logic Programming via ECLiPSe

In March last year I wrote about Antoni Niederliński's book about Constraint Programming in ECLiPSe: New book: Antoni Niederliński: Programowanie w logice z ograniczeniami ("Programming in Logic with Constraints"). Since the book was in Polish I could not read more than very small excerpts.

Now he has published an English translation of this book: A Quick and Gentle Guide to Constraint Logic Programming via ECLiPSe, and is downloadable as PDF from the site (there is also a way of order a paper version):
The book is an introductory and down-to-earth presentation of Constraint Logic Programming (CLP), an exciting software paradigm, more and more popular for solving combinatorial as well as continuous constraint satisfaction problems and constraint optimization problems. It is based on the popular, intensively supported and documented ECLiPSe platform, freely available under Cisco-style Mozilla Public License. The Author aims at teaching modeling i.e. translating verbal problem statements into Prolog or CLP programs. This has been dealt with by a series of problems of increasing complexity, translated into Prolog or CLP programs and running under ECLiPSe. The theoretical background has been minimized while stressing intuitive understanding. Presented constraint satisfaction problems deal with finding feasible/optimal states, and feasible/optimal state-space trajectories, starting with simple puzzles and proceeding to advanced ones, like graph coloring problems, scheduling problems with particular attention to job-shop problems (including the famous MT10 benchmark), and Traveling Salesman Problems. The last chapter is concerned with Continuous Constraints Satisfaction and Constraint Optimization Problems.
I read a draft of this book some month ago and really like the approach of the book of presenting a lot of fun examples/puzzles which are first translated to rather "plain" Prolog and then later to CLP together with many explanations of what is done. I especially like Chapter 6, CLP with global constraints for optimal solutions, where some global constraints (disjunctive cumulative) are discussed. Great work Antoni!