Syntax examples
Provides examples of support for floating point expressions, element constraint syntax, and specialized constraints in OPL CP models.
The Euler problem
This problem, also known as The Knight's Tour, is a mathematical problem involving a knight on a chessboard. The knight is placed on the empty board and, moving according to the rules of chess, must visit each square exactly once. There are several billion solutions to the problem, of which about 122,000,000 have the knight finishing on a square from which it attacks the starting square. Such a tour is described as closed. Otherwise the tour is described as open. In Euler’s version of the problem, the knight must end up in its original position.
To access this example, go to: examples/opl/euler.
Floating point expressions problem
CP
supports only integer decision variables. However, it is possible
to constrain floating point expressions, or to use them as an objective
term. It is also possible to declare floating point expressions with
the dexpr keyword.
To access this example, go to: examples/opl/floatexpr.
Quadratic assignment problem
In CP, it is possible
to access an array with one (or several) of its indexes that is a
decision variable index. The example that uses this element constraint
is a quadratic assignment problem. This is an example of combinatorial
optimization based on a standard problem in location theory. You are
given a set of n products and n sites,
and are told to assign each product to a site. You have size products
to build in size sites, and perm is
a decision variable. The problem is to find the allocation of product
to production sites that generates the lowest transportation cost.
The transportation costs are dependent upon the distance between each
site, and the required flow of products required as input to a production
site.
To access this example, go to: examples/opl/quadassign.
The talent problem
This problem consists of planning a movie production. A set of scenes have to be filmed in which various actors play their parts. The planning consists of deciding in which slot a scene is to be filmed.
The data consist of the scenes to be filmed, the actors, and which actor participates in which scenes. In addition, the actors represent a cost, because they are paid from the first to the last slot of the scenes that they appear in. The objective is to minimize the idle cost of the actors.
The model uses a dual representation of the problem. An array
is used to represent which slot is planned for each scene, and another
array represents the scene planned for each slot. The two arrays are
linked using an inverse constraint. Then
all the other problem elements are easily written as expressions of
these decision variables.
To access this example, go to: examples/opl/talent.