Loading in 5 sec....

Design of Problem Solvers (PS) using Classical Problem Solving (CPS) techniquesPowerPoint Presentation

Design of Problem Solvers (PS) using Classical Problem Solving (CPS) techniques

- 375 Views
- Uploaded on

Download Presentation
## PowerPoint Slideshow about 'Design of Problem Solvers PS using Classical Problem Solving CPS techniques' - MartaAdara

**An Image/Link below is provided (as is) to download presentation**

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

Design of Problem Solvers (PS) using Classical Problem Solving (CPS) techniques

Classical Problem Solver has 2 basic components:

- Search engine (uses breadth-first, depth-first, best-first, etc. general purpose search through a specified problem space)
- Interface for user-supplied problem spaces, which includes procedures for manipulating states and procedures for manipulating operators.
Procedures for manipulating states perform the following operations:

- Check if the goal criterion is satisfied in a given state.
- Check if two states are the same.
- Print out a state.
Procedures for manipulating operators perform the following operations:

- Define available operators.
- Decide if a given operator is applicable to a given state, and if yes – generate the resulting state.

Problem specification Solving (CPS) techniques

To define a problem space, we must create a representation for states and operators; to

define a particular problem in this problem space, we must define the initial state and the

goal criterion. Let our representation include only the goal criterion, but not the initial state.

Then, the following structure can be used to represent a problem:

(defstruct <problem>

name ; identified with the goal

(goal-recognizer nil)

(states-identical? nil) ; fields describing problem states

(state-printer nil)

(operators nil) ; fields describing operators

(operator-applier nil)

(path-filter nil) ; fields containing search related information

(distance-remaining nil))

Another data type, path, is used to represent queue elements:

(defstruct <path>

(problem nil)

(current nil)

(so-far nil)

(distance nil))

To set up a specific problem, we must define the fields of the problem structure

with a specific problem in mind. Consider the Boston subway problem

(book, pages 35 – 39)

Problems are defined by the following function, make-problem:

(make-problem

:NAME goal-state

:GOAL-RECOGNIZER

#'(lambda (state) (subway-states-identical? state goal-state))

:OPERATOR-APPLIER 'subway-operator-finder

:OPERATORS '(TAKE-LINE)

:STATES-IDENTICAL? 'subway-states-identical?

:PATH-FILTER 'prune-subway-path?

:STATE-PRINTER #'(lambda (f) (format nil "~A" f))

:SOLUTION-ELEMENT-PRINTER 'print-path-element

:DISTANCE-REMAINING

#'(lambda (state)

(subway-distance state `(,goal-state))))

The Boston subway example continued the problem structure

To represent a graph defining a subway (see book, fig.3.3) , we must define

stations and lines. In subways.lsp, stations are represented as structures, called

subway-station, and stored in *stations*. Lines are also represented as structures,

called subway-line, and stored in *lines*.

(defstruct (subway-station (:PRINT-FUNCTION

(lambda (inst str ignore)

(format str "<Station ~A>"

(subway-station-name inst)))))

(name nil)

(lines nil)

(coordinates nil)) ;; For advanced versions of CPS

(defstruct (subway-line (:PRINT-FUNCTION

(lambda (inst str ignore)

(format str "<Subway ~A>"

(subway-line-name inst)))))

(name nil)

(stations nil))

The Boston subway example (contd.) the problem structure

The macros, defline and defstation, allow the user to define a particular subway

instance.

(defmacro defline (line-name)

`(progn (setq ,line-name (make-subway-line :NAME ',line-name))

(push ',line-name *lines*)))

(defmacro defstation (name lines &optional (x 0) (y 0))

`(progn (setq ,name (make-subway-station

:NAME ',name

:LINES ',lines

:COORDINATES (cons ,x ,y)))

,@ (mapcar #'(lambda (line)

`(push ',name (subway-line-stations ,line))) lines)

(push ',name *stations*)))

The Boston subway example (contd.) the problem structure

A subway instance is defined in boston.lsp (see code). Now, to solve a particular subway

problem, we must first define it and then run a search engine to solve it. Example:

* (setup-subway-problem 'harvard-square) ; Harvard Square is where we want to go

<Problem: HARVARD-SQUARE>

* (bsolve 'boston-u (setup-subway-problem 'harvard-square)) ; Go from Boston University to Harvard Sq

CPS: State explored: BOSTON-U

CPS: New operator instances: ; The only operator is TAKE-LINE, but it

(TAKE-LINE BOSTON-U GREEN-LINE HAYMARKET) ; can be instantiated in different ways.

(TAKE-LINE BOSTON-U GREEN-LINE NORTH-STATION)

(TAKE-LINE BOSTON-U GREEN-LINE COPLEY-SQUARE)

(TAKE-LINE BOSTON-U GREEN-LINE GOVERNMENT-CENTER)

(TAKE-LINE BOSTON-U GREEN-LINE PARK-STREET).

CPS: State explored: HAYMARKET

CPS: New operator instances:

(TAKE-LINE HAYMARKET ORANGE-LINE WASHINGTON)

(TAKE-LINE HAYMARKET ORANGE-LINE NORTH-STATION)

(TAKE-LINE HAYMARKET ORANGE-LINE STATE).

CPS: State explored: NORTH-STATION

CPS: New operator instances:

(TAKE-LINE NORTH-STATION ORANGE-LINE WASHINGTON)

(TAKE-LINE NORTH-STATION ORANGE-LINE HAYMARKET)

(TAKE-LINE NORTH-STATION ORANGE-LINE STATE).

CPS: State explored: COPLEY-SQUARE the problem structure

CPS: New operator instances:.

CPS: State explored: GOVERNMENT-CENTER

CPS: New operator instances:

(TAKE-LINE GOVERNMENT-CENTER BLUE-LINE STATE)

(TAKE-LINE GOVERNMENT-CENTER BLUE-LINE WOOD-ISLAND)

(TAKE-LINE GOVERNMENT-CENTER BLUE-LINE AQUARIUM)

(TAKE-LINE GOVERNMENT-CENTER BLUE-LINE AIRPORT).

CPS: State explored: PARK-STREET

CPS: New operator instances:

(TAKE-LINE PARK-STREET RED-LINE HARVARD-SQUARE)

(TAKE-LINE PARK-STREET RED-LINE CENTRAL-SQUARE)

(TAKE-LINE PARK-STREET RED-LINE KENDALL-SQUARE)

(TAKE-LINE PARK-STREET RED-LINE WASHINGTON)

(TAKE-LINE PARK-STREET RED-LINE SOUTH-STATION).

CPS: State explored: WASHINGTON

CPS: New operator instances:

(TAKE-LINE WASHINGTON RED-LINE HARVARD-SQUARE)

(TAKE-LINE WASHINGTON RED-LINE CENTRAL-SQUARE)

(TAKE-LINE WASHINGTON RED-LINE KENDALL-SQUARE)

(TAKE-LINE WASHINGTON RED-LINE SOUTH-STATION)

(TAKE-LINE WASHINGTON RED-LINE PARK-STREET).

CPS: State explored: NORTH-STATION

CPS: New operator instances:

(TAKE-LINE NORTH-STATION GREEN-LINE COPLEY-SQUARE)

(TAKE-LINE NORTH-STATION GREEN-LINE GOVERNMENT-CENTER)

(TAKE-LINE NORTH-STATION GREEN-LINE PARK-STREET).

CPS: State explored: STATE

CPS: New operator instances:

(TAKE-LINE STATE BLUE-LINE GOVERNMENT-CENTER)

(TAKE-LINE STATE BLUE-LINE WOOD-ISLAND)

(TAKE-LINE STATE BLUE-LINE AQUARIUM)

(TAKE-LINE STATE BLUE-LINE AIRPORT).

CPS: State explored: WASHINGTON

CPS: New operator instances:

(TAKE-LINE WASHINGTON RED-LINE HARVARD-SQUARE)

(TAKE-LINE WASHINGTON RED-LINE CENTRAL-SQUARE)

(TAKE-LINE WASHINGTON RED-LINE KENDALL-SQUARE)

(TAKE-LINE WASHINGTON RED-LINE SOUTH-STATION)

(TAKE-LINE WASHINGTON RED-LINE PARK-STREET).

CPS: State explored: HAYMARKET

CPS: New operator instances:

(TAKE-LINE HAYMARKET GREEN-LINE COPLEY-SQUARE)

(TAKE-LINE HAYMARKET GREEN-LINE GOVERNMENT-CENTER)

(TAKE-LINE HAYMARKET GREEN-LINE PARK-STREET).

CPS: State explored: STATE

CPS: New operator instances:

(TAKE-LINE STATE BLUE-LINE GOVERNMENT-CENTER)

(TAKE-LINE STATE BLUE-LINE WOOD-ISLAND)

(TAKE-LINE STATE BLUE-LINE AQUARIUM)

(TAKE-LINE STATE BLUE-LINE AIRPORT).

CPS: State explored: STATE

CPS: New operator instances:

(TAKE-LINE STATE ORANGE-LINE WASHINGTON)

(TAKE-LINE STATE ORANGE-LINE HAYMARKET)

(TAKE-LINE STATE ORANGE-LINE NORTH-STATION).

CPS: State explored: WOOD-ISLAND

CPS: New operator instances:.

CPS: State explored: AQUARIUM

CPS: New operator instances:.

CPS: State explored: AIRPORT

CPS: New operator instances:.

CPS: Found goal state: HARVARD-SQUARE

<path HARVARD-SQUARE>

17

Another CPS example: mathematical reasoning the problem structure

The problem: given a mathematical equation, find its solution.

Problem space: nodes represent mathematical equations, arcs represent algebraic laws transforming one equation into another.

Example:

loge (x+1) + loge (x-1) = c

logw U + logw V <-> logw U * V

loge (x+1) * (x-1) = c

(U + V) * (U - V) <-> U2 - V2

loge (x2 - 1) = c

logUV = W <-> V = UW

x2 - 1 = ec

U - V = W <-> U = W + V

x2 = ec + 1

U2 = V <-> U = +/- (sqr V)

x = +/- (sqr (ec + 1))

How to reduce the complexity of the search? the problem structure

We can apply "expert knowledge" to choose the best operator at each step.To make this

possible, we must:

- Explicate implicit expert knowledge.
- Formally represent it.
Alan Bundy suggested that mathematicians use three categories of methods controlling the

use of algebraic laws:

- Attraction methods.
- Collection methods
- Isolation methods
These methods are used to analyze how a given law transforms an equation, and whether

a transformation leads towards the goal. They can be represented as production rules,

and using pattern-matching and forward chaining the problem space can be efficiently

searched.

Attraction methods the problem structure

Attraction methods move occurrences of the unknown closer together.

Example: Consider the following algebraic law: W * U + W * V --> W * (U + V). Assume that only U and V contain the unknown, x.

The initial expression is represented The transformed expression is represented

by the following tree: by the following tree:

+ *

* * W +

W U W V U V

The distance between occurrences of x is the number of steps required to move through

the tree from one occurrence to another.

Other algebraic laws belonging to this category are:

- logw U + logw V --> logw U * V
- (WU)V --> WUV
- UVW --> (UV)W

Attraction methods (cont.) the problem structure

Attraction methods can be applied only to the least dominant term in the equation, i.e. to

a term containing at least two subterms containing x.

Example:

[log (x) * xp] + [(x - 1) * (x + 1)] + q

each of the two subterms contain two occurrences of x.

Expression,<first subterm> + <second subterm> also contains more than two

occurrences of x.Therefore, this expression has three least dominant terms to which

attraction methods can be applied:

- log(x) * xp
- (x - 1) * (x + 1)
- [log (x) * xp] + [(x - 1) * (x + 1)]

Collection methods the problem structure

Collection methods reduce the number of occurrences of the unknown in the equation.

Example: Assume that U and V contain occurrences of the unknown, x, in the following law

(U + V) * (U - V) --> U2 - V2

Trees describing the left hand side (lhs) and the right hand side (rhs) of this transformation are:

* -

+ - ^2 ^2

U V U V U V

Another algebraic law belonging to this category is

U * W + U * Y --> U * (W + Y) ; assume that only U and V contain x.

Collection methods are also applied to least dominant terms in the expression.

Isolation methods the problem structure

Isolation methods reduce the depth of the occurrences of the unknown, x. They are applied

to the whole equation.

Example: Assume that only U contains occurrences of the unknown, x, in the following law

U - W = Y --> U = Y + W

Trees describing the left hand side (lhs) and the right hand side (rhs) of this transformation are:

= =

- Y U +

U W Y W

Two more algebraic laws belong to this category (only U contains x):

logWU = Y --> U = WY

U2 = W --> U = +/- (sqrt W)

Implementation of a CPS for algebra problems the problem structure

1. Representation of states: assuming that an equation is described in a prefix

form, we can use a list to represent it. For example, the equation

loge (x+1) + loge (x-1) = c

can be represented as the following list:

(= <left hand side> <right hand side>)

(= (+ (log (+ x 1) e) (log (- x 1) e)) c )

2. Representation of operators:

(<operator name> <expansion procedure>)

symbol returns a list of pairs <operator state>

To implement operator procedures, we need:

- A way to match components of the equation to those in a specific law being explored (i.e. we need a pattern-matching procedure)
- A substitution procedure to use the results of the pattern-matching process.

Example the problem structure

Consider the following isolation law represented as a pattern, with W, U, Y being

pattern variables:

logW U = Y --> U = WY

The lhs expression can be represented as follows:

(= (log (? arg) (? base)) (? rhs))

To match this pattern to a state means to define specific values for pattern variables,

(? arg), (? base), (? rhs). Assume that these values are stored in a dictionary of

bindings. Then, the rhs expression, U = WY, represented as

(= (? arg) (expt (? base) (? rhs)))

can be computed by means of the following substitution procedure:

Matching phase (= (log (? arg) (? base)) (? rhs))

Operator logW U = Y --> U = WY

is applied to generate a new state

Substitution phase (= (? arg) (expt (? base) (? rhs)))

Additional constraints on the pattern-matching process the problem structure

1. Some of pattern variables contain instances of x, while others do not. To account for

this property, we can expand the representation of pattern variables as follows:

(? patt-var contains-x?)

(? patt-var no-x?)

Example: logW U = Y --> U = WY will be represented as follows

(= log (? arg contains-x?) (? base no-x?) (? rhs no-x?)

2. There are laws that are always worth applying, because they reduce the complexity of

the expression. For example:

- U + 0 --> U
- U * 0 --> 0
- U * 1 --> U
- If possible, replace a sub-term by its values. Example: sub-term (+ 2 2) can be replaced by its value, 4, thus reducing the complexity of the expression.

To use the same pattern-matching mechanism in applying these simplifying rules, we must

account for the following cases:

… + 0 + … -->

… * 1 * … -->

… * 0 * … --> 0

segment variables

Let us call whatever comes before and after 0 and 1 terms segment variables. Segment

variables may match more than one element on a list. To represent them, we use

(?? segm-var). For example,

(+ (?? pre) 0 (?? post)) --> (+ (?? pre) (?? post))

Segment variables allow a pattern to match an expression in more than one way. For

Example, expression

(a b foo foo foo c d) can be represented as ((?? before) foo (?? after)),

where the following are several possible variable bindings:

(?? before) = (a b) | (a b foo) | (a b foo foo)

(?? after) = (foo foo c d) | (foo c d) | (c d)

To summarize, the pattern matcher must recognize two types of variable:

- Segment variable. These match zero or several elements on a list, and start with ??
- Element variables. These match exactly one element on a list, and are represented as
(? <var-name> <a predicate representing an optional restriction>)

To handle pattern variables we need the following functions (refer to match.lsp):

- pattern-variable?
- element-variable?
- segment-variable?
- var-name
- var-restriction
- var-value
- lookup-var
- bind-element-var
- bind-segment-var

One more detail that must be addressed is substituting expressions with their values. This

can be implemented as follows:

(+ (? num1 numberp) (? num2 numberp) (?? terms))

these two are to be added

(+ (:eval (+ (? num1) (? num2))) (?? tems))

:eval is a special form which computes the result of the expression and places it in the dictionary.

The simplification rule now becomes:

(+ (? num1 numberp) (? num2 numberp) (?? terms)) -->

(+ (:eval (+ (? num1) (? num2))) (?? tems))

Consider the following expression expressions with their values. This

(+ A 2 3)

Note that it will not match the simplification rule, but the equivalent expression (+ 2 3 A)

will. To handle such cases we must be able to rearrange the expression bringing its

numerical terms before non-numerical terms. This can be done by introducing a

relationship "less than" on the order of term, where:

- Numerical terms are "less than" non-numerical.
- The expression is sorted with respect to this relationship.
This is implemented by the form :splice.

To run the CPS for solving algebra problem, you need the following files: search.lsp,

variants.lsp, algebra.lsp, simplify.lsp, match.lsp A specific example is defined in algebra.lsp

(defvar *bundy* '(= (+ (log (+ x 1) E) (log (- x 1) E)) C)

"A single example problem from Alan Bundy's reasoner.")

See book page 60 for example runs on the program.

Example (book, page 60) expressions with their values. This

Function setup-algebra-problem in algebra.lsp defines a particular problem

(same as in setup-subway-problem)

(defun setup-algebra-problem ()

"Create an generic algebra 'problem space'."

(make-problem

:NAME 'Algebra

:GOAL-RECOGNIZER 'got-algebra-goal?

:OPERATOR-APPLIER 'find-algebra-operator

:STATE-PRINTER #'(lambda (f) (format nil "~A" f))

:SOLUTION-ELEMENT-PRINTER #'print-derivation-step

:STATES-IDENTICAL? 'equal

:DISTANCE-REMAINING 'algebra-distance

:OPERATORS '((Isolate-Log try-isolate-log)

(Isolate-Sum try-isolate-sum)

(Isolate-Difference try-isolate-difference)

(Isolate-Square try-isolate-square)

(Collect-Product-Difference try-collect-prod-diff)

(Attract-Log-Sum try-attract-log-sum)

(Canonicalize try-canonicalization))))

Implementation of the pattern-matcher expressions with their values. This

Consider the following expression and the pattern it matches:

(+ (log (+ x 1) e) (log (- x 1) e)

(+ (log (? U has-unknown?) (? W no-unknown?)) (log (? V has-unknown? (? W))

The following substitutions are required for these matches:

(V (- x 1)) Assume that these substitutions are stored in a

(W e) dictionary of bindings as an association list.

(U (+ x 1))

The dictionary has the following format:

((patt_var1 value) (patt_var2 value) …)

Given the key, patt_varN, the corresponding value can be accessed via the assoc primitive:

(assoc (var-name var) dictionary), where (var-name var) is a procedure to get to the

name of pattern variable var in the dictionary.

The match function expressions with their values. This

The match function takes the following parameters: pat, dat, and the current

dictionary, and returns the new extended dictionary. It must consider the

following cases:

- A component is found for which the pattern and the expression do not match, therefore the match fails.
- pat is a symbol
- pat is an element variable
- pat is an empty list
- pat is a segment variable
- pat is a list, but dat is an atom, therefore the match process fails.
- If none of these is the case, match must return the dictionary accumulated so far.

The substitution process expressions with their values. This

As a result of the substitution process, a new expression is created. This new expression

represents the rhs of the simplification rule being applied. To carry out this process,

we need:

- the dictionary generated during the matching process,
- the expression constituting the rhs of the simplification rule.
Example: Assume that (?? A) has the value (1 2), and (?? B) has the value (3 4). Then:

- expression (+ (?? A) (?? B)) is transform by the substitution process into
(+ (1 2) (3 4)).

- (:eval ((?? A) (?? B)) returns 10.
- (* (:splice (42 (?? A) (?? B)))) returns (* 42 1 2 3 4)

Implementation of the simplifier expressions with their values. This

Consider the following expression: (+ (* x -2) (* x 2)). It is always 0, which is why it must

be eliminated as early as possible. A simplification of this type can be performed by a set

of rewrite rules of the form (<pattern> <result>).Note that knowledge needed to recognize

situations where simplification is possible must be acquired and embedded in the PS.

There are 4 categories of simplification rules:

- Rules for recognizing special arguments to operators. Example:
Rule: 0 + U --> U. Encoded: ((+ (? Zero zero?) (?? E)) (+ (?? E)))

Rule: e0 --> 1. Encoded: ((expt (? E) (? Zero zero?)) 1)

2. Rules dealing with equivalences involving multiplication, squaring and exponent.

Rule: (sqrt (U2)) --> |U|. Encoded: ((sqrt (sqr (? E))) (abs (? E)))

3. Rules for reducing expressions if numerical values are available. Examples:

Rule: A / B --> value.

Encoded: ((/ (? e1 numberp) (? e2 numberp)) (:eval (/ (? e1) (? e2))))

Rule: A + (B + C) --> A + B +C.

Encoded: (((? op =/*?) (?? e1) ((? op) (?? e2) (?? e3)))((? op) (?? e1) (?? e2) (?? e3)))

4. Rules for producing canonical forms. Example:

(+ a 2 3) --> (+ 2 3 a)

Problems with the CPS model expressions with their values. This

In 1957, Herbert Simon wrote: "… It is not my aim to surprise or shock you …

But the simplest way I can summarize is to say that there are now in the world

machines that think, that learn and create. Moreover, their ability to do these

things is going to increase rapidly - in a visible future - the range of problems

they can handle will be coextensive with the range to which the human mind has

been applied…“

Was Herbert Simon right? The short answer is NO. And the short explanation is

that the CPS-type systems are based on the idea that there exists a general

Problem solving method that can be applied to any problem requiring human

intelligence. 10 years were needed to realize that the real power of human

intelligence is not the problem solving per se, but knowledge behind the problem

solving process. In CPS, knowledge is embedded implicitly (like in conventional

computer programs), although it is separated from the search engine.

To build a powerful AI program, we need a way to represent knowledge

explicitly. This is true for both, domain knowledge and control knowledge.

Download Presentation

Connecting to Server..