Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
768 Constraint Programming fun {DFE S} case {Ask S} of failed then nil [] succeeded then [S] [] alternatives(2) then C={Clone S} in {Commit S 1} case {DFE S} of nil then {Commit C 2} {DFE C} [] [T] then [T] end end end % Given {Script Sol}, returns solution [Sol] or nil: fun {DFS Script} case {DFE {NewSpace Script}} of nil then nil [] [S] then [{Merge S}] end end Figure 12.3: Depth-first single solution search ± statement ² ::= {NewSpace ± x ²± y ² } | {Choose ± x y ² } | {Ask ± x y ² } | {Commit ± x y ² } | {Clone ± x y ² } | {Inject ± x y ² } | {Merge ± x y ² } Table 12.1: Primitive operations for computation spaces A depth-first search engine Figure 12.3 shows how to program depth-first single solution search, in the case of binary choice points. This explores the search tree in depth-first manner and returns the first solution it finds. The problem is defined as a unary procedure {Script Sol} that gives a reference to the solution Sol , just like the examples of Section 12.2. The solution is returned in a one-element list as [Sol] .I fthe re is no solution, then nil is returned. In Script , choice points are defined with the primitive space operation Choose . The search function uses the primitive operations on spaces NewSpace , Ask , Commit , Clone ,and Merge . We will explain each operation in detail as it comes in the execution. Table 12.1 lists the complete set of primitive operations. Copyright c ³ 2001-3 by P. Van Roy and S. Haridi. All rights reserved.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
12.4 Computation spaces 769 A script example Let us run the search engine on the example given in Section 12.1.3. The problem was specified by the procedure Rectangle . proc {Rectangle ?Sol} sol(X Y)=Sol in X::1#9 Y::1#9 X*Y=:24 X+Y=:10 X=<:Y {FD.distribute naive Sol} end We start the execution with the statement Sol={DFS Rectangle} ,where DFS and Rectangle are defined as above, and Sol is a fresh variable. If we expand the body of the function, it should create two variables, say S and L , leading to a configuration like the following. The box represents the thread that executes the statements, and below it is a representation of the store. S={NewSpace Rectangle} L={DFE S} Sol= case L of ... end Rectangle=< proc > Sol L S Space creation The first primitive space operation we use is NewSpace . In our example, it creates a new computation space S ,w i tha root variable Root , and one thread that executes {Rectangle Root} . Both the new thread and the new store are shown inside a box, which delimits the “boundaries” of the space. L={DFE S} Sol= case L of ... end Rectangle=< proc >S o lLS = {Rectangle Root} Root A precise definition of NewSpace is S={NewSpace P} , when given a unary procedure P , creates a new compu- tation space and returns a reference to it. In this space, a fresh variable R , called the root variable , is created and a new thread, and {P R} is invoked in the thread. Recall that a computation space encapsulates a computation. It is thus an in- stance of the stateful concurrent model, with its three parts: thread store, con- straint store, and mutable store. As it can itself nest a computation space, the spaces naturally form a tree structure: Copyright c ± 2001-3 by P. Van Roy and S. Haridi. All rights reserved.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 08/10/2011.

Page1 / 30


This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online