2.3.3 Composing the Solver

As in Prolog, you need only specify your problem and let the search facilities of the language derive its solutions. In contrast to Prolog, search in Oz is encapsulated: in particular this means that the search facilities are not implicit as in Prolog, but rather that search engines are explicit objects in the language, that you can create as many as you want, and that they are all independent and may coexist peacefully.

Each search engine can solve a different problem. Consequently a search problem must be encapsulated into a predicate (a procedure) which is passed explicitly to the search engine. We often call such a procedure a search predicate and it consists of 2 parts:

  1. a description of what constitutes a solution

  2. a specification of the distribution strategy

More precisely, the search predicate takes one argument, intended to denote a solution, and typically follows the design pattern below:

  1. introduce the local variables of the problem

  2. define a solution term using these variables

  3. post the constraints which the variables must satisfy

  4. apply a distribution strategy to the variables

For example, search predicate Equations describes exactly the solutions of the problem considered above.

proc {Equations Sol}
   X Y Z  
   Sol = solution(x:X y:Y z:Z)
%  Propagate
   [X Y Z] ::: 1#7
   X + Y =: 3*Z
   X - Y =: Z
%  Distribute
   {FD.distribute naive [X Y Z]}

The definition of Equations in Oz not only specifies a set of objects but also describes how these objects can be searched by propagation and distribution. For computing its solutions in Oz, it is sufficient to pass the definition of Equations to the Oz-Explorer.

{Explorer.all Equations}
{Explorer.one Equations}

Denys Duchier, Claire Gardent and Joachim Niehren
Version 1.2.4 (20020829)