{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Concepts+Techniques+and+Models+of+Computer+Programming_Part28

Concepts+Techniques+and+Models+of+Computer+Programming_Part28

Info icon This preview shows pages 1–4. 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] . If there 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.
Image of page 1

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

View Full Document Right 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 , with a 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 > Sol L S= {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.
Image of page 2
770 Constraint Programming Space A Space B
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern