• 沒有找到結果。

Problem Solving Using Search

N/A
N/A
Protected

Academic year: 2021

Share "Problem Solving Using Search"

Copied!
28
0
0

加載中.... (立即查看全文)

全文

(1)

Problem Solving Using Search

 Problem Solving Procedures

 Common Problem Solving Methods

 Brute Force Search Techniques

 Traveling Salesman Problem (TSP)

(2)

Problem Solving Procedures

Defining and Representing the Problem

Descriptions of Problem Solving

Selecting Some Suitable Solving Methods

Finding Several Possible Solutions

Choosing One Feasible Solution to Make a Decision

(3)

Defining and Representing the Problem

State space: The combination of the initial state and the set of operators make up the state space of the problem.

Initiate state: The original state of the problem.

Operators: used to modify the current state, thereby creating a new state.

Path: The sequence of states produced by the valid

application of operators from an old state to a new state is called the path.

Goal state: A state fit to the searching objective is called the goal state.

(4)

Example of a search problem

) 6 ( ,

2 , 1 ,

) 5 ..(

...

...

...

...

...

, 2 , 1 ,

0 ,

1

) 4 ( ...

...

...

...

...

, 2 , 1 ,

0 ,

1

) 3 . (

0

, 1

) 2 ...(

...

...

...

...

/ ) .

. (

) 1 ...(

...

...

...

...

...

...

.

0 1

0 1

0

1 0 0

1 1 1

M k

V L

M k

i X

M k

j X

otherwise

k vehicle by

served is

j to i from sequence

the X if

to Subject

TC X

C L

AC Minimize

X C

TC Minimize

N i

ik N i

k i N j

jk ijk

M k

N i

N j

ijk ij

ik ijk M

k N i

N j

ij

 



 

(5)

Descriptions of Problem Solving

In many search problem, we are not only interested in reaching a go al state, we would like to reach it with the lowest cost (or the maximum profit).

We can compute a cost as we apply operators and transit from state to state.

The path cost or cost function is usually denoted by g.

Given a problem which can be represented by a set os states and operators and then solves using a search algorithm.

For many real-world problems the search space can grow very large, so we need algorithms to deal with that.

(6)

Effective search algorithm must do two things: cause motion or traversal of the state space, and do so in a controlled or systematic manner.

The method that never using the information about the problem to help direct the search is called brute-force, uninformed, or blind search.

Search algorithms which use information about the

problem, such as the cost or distance to the goal state, are called heuristic, informed, or directed search.

Descriptions of Problem Solving

(7)

An algorithm is optimal if it will find the best solution from among several possible solutions.

A strategy is complete if it guarantees that it will find a solution if one exists.

The complexity of the algorithm , in terms of time complexity (how long it takes to find a solution) and space complexity (how much memory it require), is a major practical considerations.

In real-world, the search problem can be classified to two classes: P and NP.

Descriptions of Problem Solving

(8)

In real-world, the search problem can be classified to two classes: P and NP.

The classes P consists of all problems for which

algorithms with polynomial time behavior have been found.

The class NP is essentially the set of problems for which algorithms with exponential behavior have been found.

If an optimization of the problem cannot be solved in polynomial time, it is called NP-hard.

Descriptions of Problem Solving

(9)

Common Problem Solving Methods

線性規劃法 (Linear Programming: LP)

整數規劃法 (Integer Programming)

分支界限法 (Branch and Bound Method)

啟發式解法: MST, RMST, SA

– Kruskal, 1956; Prim, 1959; Dijkstra, 1959;

Sollin, 1965; Yu, 1998

全域搜尋法 (Global Searching) : GA

Brute-Force Search Method

(10)

Brute Force Search Techniques

 Breadth-First Search (BFS)

 Depth-First Search (DFS)

(11)

Algorithm of Breadth-First Search

1. Create the queue and add the first Node to it.

2. Loop:

 If the queue is empty, quit.

 Remove the first Node from the queue.

 If the Node contains the goal state, then exit with the Node as the solution.

 For each child of the current Node: Add the new state to the back of the queue.

(12)

Algorithm of Depth-First Search

1. Create the stack and add the first SearchNode to it.

2. Loop:

 1 If the stack is empty, quit.

 2 Remove the top SearchNode from the stack.

 3 If the Node contains the goal state, then exit with the SearchNode as the solution.

 4 If the Node contains child node, then add the new state to the top of the stack

 5 If the Node is the Leaf node , then go back to Step 2.

(13)

Example

從苗栗到新竹之可能路徑

造橋 苗栗

後龍 尖山

頭屋 竹南

頭份

新竹 公館

汶水 三灣 獅潭

(14)

The path generated by BFS

[ 苗栗 ]

←[ 苗栗 ], [ 公館 ][ 頭屋 ][ 造橋 ][ 後龍 ]

← [ 公館 ], [ 頭屋 ][ 造橋 ][ 後龍 ][ 汶水 ]

← [ 頭屋 ], [ 造橋 ][ 後龍 ][ 汶水 ][ 尖山 ]

← [ 造橋 ], [ 後龍 ][ 汶水 ][ 尖山 ]

← [ 後龍 ], [ 汶水 ][ 尖山 ]

← [ 汶水 ], [ 尖山 ][ 獅潭 ]

← [ 尖山 ], [ 獅潭 ][ 頭份 ][ 竹南 ]

← [ 獅潭 ], [ 頭份 ][ 竹南 ][ 三灣 ]

← [ 頭份 ], [ 竹南 ][ 三灣 ][ 新竹 ]

← [ 竹南 ], [ 三灣 ][ 新竹 ]

← [ 三灣 ], [ 新竹 ]

← [ 新竹 ]

(15)

The path generated by DFS- using Queue

[ 苗栗 ]

←[ 苗栗 ], [ 後龍 ][ 造橋 ][ 頭屋 ][ 公館 ]

←[ 後龍 ], [ 尖山 ][ 造橋 ][ 頭屋 ][ 公館 ]

←[ 尖山 ], [ 竹南 ][ 頭份 ][ 造橋 ][ 頭屋 ][ 公館 ]

←[ 竹南 ], [ 新竹 ][ 頭份 ][ 造橋 ][ 頭屋 ][ 公館 ]

←[ 新竹 ], [ 頭份 ][ 造橋 ][ 頭屋 ][ 公館 ]

(16)

The path generated by DFS- using Stack

[ 苗栗 ]

[ 後龍 ], [ 苗栗 ]

[ 尖山 ], [ 後龍 ], [ 苗栗 ]

[ 竹南 ],[[ 尖山 ], [ 後龍 ], [ 苗栗 ]

[ 新竹 ],[ 竹南 ],[[ 尖山 ], [ 後龍 ], [ 苗栗 ]

(17)

Improving DFS

The DFS algorithm can be improved by adding a parameter to limit the search to a maximum depth of the tree. Then we add a control loop where we continuously deepen our DFS until we find the solution.

(18)

TSP Problem

Definition

The Traveling Salesman Problem (TSP), where a salesman makes a complete tour of the cities on his route, visiting each city exactly once, while

traveling the shortest possible distance, is an

example of a problem which has a combinatorial explosion.

As such, it cannot be solved using BFS or DFS for problems of any realistic size. TSP belongs to a class of problems known as NP-hard or NP-

complete.

(19)

Searching method for TSP Problem

Finding the best possible answer is not

computationally feasible, and so we have to settle a good answer. Several heuristic search methods are employed to solve this type of problem.

Generate and Test (GAT)

Best-First Search (BFS)

Greedy Search (GS)

A* Search

Constraint Satisfaction (CS)

Mean-Ends Analysis (MEA)

(20)

The Algorithm of GAT

1.Generate a possible solution, either a new state or a path through the problem space.

2.Test to see if the new state or path is a solution by comparing it to a set of goal states.

3.If a solution has been found, return success; else return to step 1.

(21)

The modification of GAT

To avoid getting trapped in a suboptimal states, variations on the hill climbing strategy have been proposed.

One is to inject noise into the evaluation function, with the initial noise level high and slowly

decreasingly over time. This technique, called

simulated annealing, allows the search algorithm to go in directions which are not “best” but allow more complete exploration of the search space.

(Kirkpartrick, Gelatt, and Vecchi, 1983)

(22)

The Algorithm of BFS

BFS is a systematic control strategy, combining the strengths of breadth-first and depth-first search into one algorithm. The main difference between BFS and the brute-force search techniques is that we make use of an evaluation or heuristic function to order the SearchNode objects on the queue. In this way, we choose the SearchNode that appears to be best, before any others, regardless of their

position in the tree or graph.

(23)

The Algorithm of Greedy Search

GS is a best-first strategy where we try to minimize the estimated cost to reach the goal. Since we are greedy, we always expand the node that is

estimated to be closest to the goal state.

Unfortunately, the exact cost of reaching the goal state usually can’t be computed, but we can

estimate it by using a cost estimate or heuristic function h().

(24)

A* Search

One of the famous search algorithms used in AI is A* search algorithm, which combines the greedy algorithm for efficiency with the uniform-cost

search for optimality and completeness. In A* the evaluation function is computed by adding the two heuristic measures; the h(n) cost estimate of

traveling from n to the goal state, and g(n) which is the known path cost from the start node to n into a function called f(n).

(25)

The Algorithm of Constraint Satisfaction

Usually, all problems have some constraints which define what the acceptable solutions are. For

example, if our problem is to load a delivery truck with packages, a constraint may be that the truck holds only 2000 pounds. This constraint could help us substantially reduce our search space by ignoring search paths uses a set of constraints to define the space of acceptable solutions.

(26)

Means-Ends Analysis

MEA is a process for problem solving which is based on detecting differences between states and then trying to reduce those differences. First used in the General Problem Solver (Newell and Simon,

1963), MEA uses both forward and backward reasoning and a recursive algorithm to

systematically minimize the differences between the initial and the goal states.

(27)

The Algorithm of MEA

1. Compare the current-state to the goal-state. If states are identical then return success.

2. Select the most important difference and reduce it by performing the following steps until success or failure:

i.Select an operator that is applicable to the current difference. If there are no operators which can be applied, then return failure.

ii.Attempt to apply the operator to the current state by generating two temporary states, one where the

operator’s preconditions are true (prestate), and one that would be the result if the operator were applied to the current state (poststate).

(28)

The Algorithm of MEA

iii. Divide the problem into two parts, a First part, from the current state to the prestate, and a Last part, from the poststate to the goal state. Call MEA to solve both pieces. If both are true, then return success, with the solution consisting of the First part, the selected

operator, and the Last part.

參考文獻

相關文件

• Adding restrictions on the allowable solutions (the solution space) may make a problem harder, equally hard, or easier.. • It is

• Adding restrictions on the allowable solutions (the solution space) may make a problem harder, equally hard, or easier.. • It is

♦ The action functional does not discriminate collision solutions from classical solutions...

Students are able to use different learning strategies such as inquiry, reasoning, and problem solving skills in various learning activities. Teachers will employ a variety

Both problems are special cases of the optimum communication spanning tree problem, and are reduced to the minimum routing cost spanning tree (MRCT) prob- lem when all the

Establish the start node of the state graph as the root of the search tree and record its heuristic value.. while (the goal node has not

• If we know how to generate a solution, we can solve the corresponding decision problem. – If you can find a satisfying truth assignment efficiently, then sat is

- Greedy Best-First Search (or Greedy Search) Minimizing estimated cost from the node to reach a goal Expanding the node that appears to be closest to goal - A* Search.. Minimizing