**JBoss.org****Community Documentation**

- 2.1. Introduction
- 2.2. The n queens example
- 2.3. The Manners 2009 example
- 2.4. The Traveling Salesman Problem (TSP) example
- 2.5. The Traveling Tournament Problem (TTP) example
- 2.6. Cloud balancing
- 2.7. The ITC 2007 curriculum course example
- 2.8. The ITC 2007 examination example
- 2.9. The patient admission scheduling (PAS) example (hospital bed planning)
- 2.10. The INRC 2010 nurse rostering example

The *n queens puzzle* is a puzzle with the following constraints:

The above solution is wrong because queens `A1`

and `B0`

can attack each
other (as can queens `B0`

and `D0`

). Removing queen `B0`

would
respect the "no 2 queens can attack each other" constraint, but would break the "place n queens"
constraint.

These numbers might give you some insight on the size of this problem.

The Drools Planner implementation has not been optimized because it functions as a beginner example. Nevertheless, it can easily handle 64 queens.

public class Column { private int index; // ... getters and setters }

public class Row { private int index; // ... getters and setters }

public class Queen { private Column column; private Row row; public int getAscendingDiagonalIndex() {...} public int getDescendingDiagonalIndex() {...} // ... getters and setters }

public class NQueens implements Solution<SimpleScore> { private int n; private List<Column> columnList; private List<Row> rowList; private List<Queen> queenList; private SimpleScore score; // ... getters and setters }

When 2 queens share the same column, row or diagonal line, such as (*) and (**), they can attack each other.

A single `NQueens`

instance contains a list of all `Queen`

instances. It
is the `Solution`

implementation which will be supplied to, solved by and retrieved from the
Solver. Notice that in the 4 queens example, NQueens's `getN()`

method will always return
4.

In Manners 2009, miss Manners is throwing a party again.

This time she invited 144 guests and prepared 12 round tables with 12 seats each.

Every guest should sit next to someone (left and right) of the opposite gender.

And that neighbour should have at least one hobby in common with the guest.

And the 2 politicians, 2 doctors, 2 sports stars and 2 programmers shouldn't be the same kind.

Given a list of cities, find the shortest tour for a salesman that visits each city exactly once. See the wikipedia definition of the traveling Salesman Problem.

It is one of the most intensively studied problems in computational mathematics. Yet, in the real world, it's often only part of a planning problem, along with other constraints, such as employee shift time constraints.

Schedule matches between N teams with the following hard constraints:

and the following soft constraint:

The problem is defined on this webpage (which contains several world records too).

$ mvn exec:exec -Dexec.mainClass="org.drools.planner.examples.travelingtournament.app.simple.SimpleTravelingTournamentApp" ... $ mvn exec:exec -Dexec.mainClass="org.drools.planner.examples.travelingtournament.app.smart.SmartTravelingTournamentApp" ...

The smart implementation performs and scales exponentially better than the simple implementation.

There are a number of hard constraints that cannot be broken:

It uses large test data sets of real-life universities.

The problem is defined by the International Timetabling Competition 2007 track 1.

These numbers might give you some insight on the size of this problem.

Geoffrey De Smet (the Drools Planner lead) finished 4th in the International Timetabling Competition 2007's examination track with a very early version of Drools Planner. Many improvements have been made since then.

Below you can see the main examination domain classes:

Notice that we've split up the exam concept into an `Exam`

class and a
`Topic`

class. The `Exam`

instances change during solving (this is the planning
entity class), when they get another period or room property. The `Topic`

,
`Period`

and `Room`

instances never change during solving (these are problem
facts, just like some other classes).

There are a couple of hard constraints:

And of course, there are also some soft constraints:

The problem is defined on this webpage and the test data comes from real world hospitals.