Pigeonhole problem
Table of contents
Problem and Encoding
Wikipedia In mathematics, the pigeonhole principle states that if n items are put into m containers, with n > m, then at least one container must contain more than one item.
The Pigeonhole Problem is a common benchmark example for symmetry breaking. Here we present the encoding and how to run the it with symba.
Consider an instance of n holes and n+1 pigeons, given as a list of facts in the instance.lp file:
hole(1).
...
hole(n).
pigeon(1).
...
pigeon(n).
pigeon(n+1).
The problem is encoded with the following two rules: first, stating that exactly one hole is assigned per pigeon, and second that two pigeons can not be in the same hole. Files encoding.lp:
1 { place(P,H) : hole(H) } 1 :- pigeon(P).
:- place(Pa,H), place(Pb,H), Pa != Pb.
Program analysis
Using symba, we can begin analyzing the instance and its encoding. For the purpose of the example, we use the instance of size 10. The following command will print the details about the program.
symba -e instance_10.lp encoding.lp -p
The most important part of the outputs is the connectively closed sets of argument positions, and it looks like:
{pigeon|1, place|1}
{hole|1, place|2}
Additionally, the domain was extracted:
Constants: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
Domain Permutation Graph
Next, symba constructs the Domain Permutation Graphs (DPG) for each set of connectively closed argument positions. We can run the following command to print the domain permutation graphs for this instance in dot format:
symba -e instance.lp encoding.lp -d
The following are the visualizations of the resulting graphs:
The weights of edges in these graphs indicate to which argument position of the atom the object is connected to (here always 1). Colors are chosen to represent the objects of the same kind that can be swapped.
Additional options
If you wish to print the graph data structure, use:
symba -e instance.lp encoding.lp -g
For printing the graph preprocessed for dejavu use (in dot format):
symba -e instance.lp encoding.lp -i
Transformations
In the next step, symba relies on dejavu for computing the refinements of the colors of the DPGs, and produces the transformations based on the assumed order on domain objects. To print the transformations use:
symba -e instance.lp encoding.lp -t
The result is:
Transformation 1
Argument positions: {place|1, pigeon|1}
Domain permutation generators: [(1 2), (2 3), (3 4), (4 5), (5 6), (6 7), (7 8), (8 9), (9 10), (10 11)]
Transformation 2
Argument positions: {hole|1, place|2}
Domain permutation generators: [(1 2), (2 3), (3 4), (4 5), (5 6), (6 7), (7 8), (8 9), (9 10)]
Symmetry breaking
Using the generators from the previous step, symba generates lex leader symmetry breakers. To print those use:
symba -e instance.lp encoding.lp -l
Which will result in:
y00.
:- y00, place(1, 1), not place(2, 1).
y01 :- y00, place(1, 1).
y01 :- y00, not place(2, 1).
:- y01, place(1, 2), not place(2, 2).
y02 :- y01, place(1, 2).
y02 :- y01, not place(2, 2).
:- y02, place(1, 3), not place(2, 3).
y03 :- y02, place(1, 3).
y03 :- y02, not place(2, 3).
:- y03, place(1, 4), not place(2, 4).
y04 :- y03, place(1, 4).
y04 :- y03, not place(2, 4).
:- y04, place(1, 5), not place(2, 5).
y05 :- y04, place(1, 5).
y05 :- y04, not place(2, 5).
:- y05, place(1, 6), not place(2, 6).
y06 :- y05, place(1, 6).
y06 :- y05, not place(2, 6).
:- y06, place(1, 7), not place(2, 7).
y07 :- y06, place(1, 7).
y07 :- y06, not place(2, 7).
:- y07, place(1, 8), not place(2, 8).
y08 :- y07, place(1, 8).
y08 :- y07, not place(2, 8).
:- y08, place(1, 9), not place(2, 9).
y09 :- y08, place(1, 9).
y09 :- y08, not place(2, 9).
:- y09, place(1, 10), not place(2, 10).
y010 :- y09, place(1, 10).
y010 :- y09, not place(2, 10).
...
Measurements
To see the time measurements use:
symba -e instance.lp encoding.lp -m
The result:
Time: 0.0006s (DPGraph: 0.0001s Symmetry: 0.0002s LexLeader: 0.0003s)
Solving
To run the clingo solver on the program with symmetry breakers, use:
symba -e instance.lp encoding.lp -r | clingo
Comparison
Following is the comparison of the solving times without symmetry breaking (clingo column), and after symmetry breaking with different tools (other columns). This is a comparison only of the solving after breaking (time to compute breakers is not included), with a timeout of 10s. Timeout is indicated with “T”.
| n | Clingo | Symba | Sbass | BreakID |
|---|---|---|---|---|
| 10 | 10.499s | 0.055s | 0.011s | 0.002s |
| 15 | T | 0.058s | 0.043s | 0.004s |
| 20 | T | 0.073s | 0.152s | 0.010s |
| 25 | T | 0.085s | 0.410s | 0.011s |
| 30 | T | 0.110s | 0.977s | 0.019s |
| 50 | T | 0.274s | T | 0.065s |
| 100 | T | 1.844s | T | 0.813s |
The following are the times by different tools needed to create symmetry breakers (with a timeout of 90s):
| n | Symba | Sbass | BreakID |
|---|---|---|---|
| 10 | 0.0007s | 0.014s | 0.026s |
| 15 | 0.0012s | 0.047s | 0.029s |
| 20 | 0.0019s | 0.177s | 0.065s |
| 25 | 0.0028s | 0.419s | 0.141s |
| 30 | 0.0039s | 0.972s | 0.259s |
| 50 | 0.0102s | 11.679s | 2.035s |
| 100 | 0.0420s | T | 64.536s |
Cumulative times:
| n | Symba | Sbass | BreakID |
|---|---|---|---|
| 10 | 0.0557s | 0.025s | 0.028s |
| 15 | 0.0592s | 0.090s | 0.033s |
| 20 | 0.0749s | 0.329s | 0.075s |
| 25 | 0.0878s | 0.829s | 0.152s |
| 30 | 0.1139s | 1.949s | 0.278s |
| 50 | 0.2842s | T | 2.100s |
| 100 | 1.8860s | T | 65.349s |
Note: The pigeonhole problem is well-suited for the symmetry breaking on the first-order level.