Autonomy Problem Solving Using Search - PowerPoint PPT Presentation

1 / 100
About This Presentation
Title:

Autonomy Problem Solving Using Search

Description:

Autonomy Problem Solving Using Search. Shyh-Kang Jeng. Department of Electrical Engineering ... Problem-Solving Agent. A kind of goal-based agent ... – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 101
Provided by: shyhka
Category:

less

Transcript and Presenter's Notes

Title: Autonomy Problem Solving Using Search


1
Autonomy Problem Solving Using Search
  • Shyh-Kang Jeng
  • Department of Electrical Engineering/
  • Graduate Institute of Communication Engineering
  • National Taiwan University

2
References
  • J. P. Bigus and J. Bigus, Constructing
    Intelligent Agents with Java, Wiley Computer
    Publishing, 1998
  • S. Russell and P. Norvig, Artificial
    Intelligence A Modern Approach, Englewood
    Cliffs, NJ Prentice Hall, 1995

3
Intelligent Agents (1)
  • A computational system which
  • Is long-lived
  • Has goals, sensors, and effectors
  • Decides autonomously which actions to take in the
    current situation to maximize progress toward its
    (time-varying) goals

4
Intelligent Agents (2)
5
Goal-Based Agents
Sensors
Environment
State
Environment Model
Action Sequence
Decision Maker
Goals
Agent
Effectors
6
Problem-Solving Agent
  • A kind of goal-based agent
  • Given the current environment situation, decides
    what to do by finding sequences of actions that
    lead to desirable states
  • Goal formulation
  • Problem formulation
  • Search
  • Solution

7
Simple Problem Solving Agent (1)
  • Class ProblemSolvingAgent
  • State state
  • ActionSequence s
  • Goal g
  • void updateState(Percept percept)
  • //
  • void formulateGoal() //
  • Problem void formulateProblem() //

8
Simple Problem Solving Agent (2)
  • public Action run(Percept p)
  • updateState(p)
  • formulateGoal()
  • Problem problem
  • formulateProblem()
  • s search(problem)
  • action s.recommend()
  • s s.takeRemainder()
  • return action

9
Problem Definition
  • A problem is a collection of information that the
    agent will use to decide what to do
  • Elements of a problem
  • Initial state
  • Set of possible actions available (operators)
  • Goal test
  • Path cost
  • State space
  • Path

10
Route Finding Problem
11
Search Tree for a Problem
12
Breadth-First Search Concept
13
Depth-First Search Concept
14
Search Strategies
  • Brute-force, uninformed, or blind search
  • Heuristic, informed, or directed search
  • Optimal search
  • Complete search
  • Complexity
  • Time
  • Space

15
General Search Algorithm
  • Initialize the search tree using the initial
    state of problem
  • Loop
  • If there are no candidates for expansion, return
    failure
  • Choose a leaf node for expansion according to
    strategy
  • If the node contains a goal state, return the
    corresponding solution
  • Else expand the node and add the resulting nodes
    to the search tree

16
Problem-Solving Performance
  • Does it find a solution at all?
  • Is it a good solution?
  • Search cost
  • Time
  • Memory
  • Total cost of the search
  • Path cost
  • Search cost

17
Searching over a Graph
18
Breadth-First Search Algorithm
  • Create a queue and add the first node to it
  • 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

19
Trace of Breadth-First Search
  • Rochester
  • Sioux Falls, Minneapolis, LaCrosse, Debuque
  • Minneapolis, LaCrosse, Debuque, Fargo,
    Rochester
  • LaCrosse, Debuque, Fargo, Rochester, St. Cloud,
    Wausau, Duluth, LaCross, Rochester
  • Debuque, Fargo, Rochester, St. Cloud, Wausau,
    Duluth, LaCross, Rochester, Minneapolis,
    GreenBay, Madison, Dubuque, Rochester
  • Fargon, Rochester, St. Cloud, Wausau, Duluth,
    LaCross, Rochester, Minneapolis, GreenBay,
    Madison, Dubuque, Rochester, Rochester, LaCrosse,
    Rockford

20
Avoiding Repeated States
  • Use a flag in the node data structure to avoid
    expanding a tested node
  • This will cut down the time and space complexity

21
Features of Breadth-First Search
  • All the nodes at depth d in the search tree are
    expanded before the node of depth d1
  • If there is a solution, breadth-first search is
    guaranteed to find it
  • If there are several solutions, breadth-first
    search will always find the shallowest goal state
    first
  • Is complete and optimal provided that the path
    cost is a nondecreasing function of the depth of
    the node

22
Time and Memory Requirements
  • Branching factor b
  • Maximum number of nodes expanded before finding a
    solution with a path length d 1bb2b3bd,
    O(bd)
  • The space complexity is the same as the time
    complexity, because all the leaf nodes of the
    tree must be maintained in memory at the same
    time
  • If b 10, and dealing with one node takes 1 ms
    as well as 100 bytes, we will need 18 minutes and
    111 megabytes for depth 6 (bd106), and 3500
    years as well as 11111 terabytes for depth 14
    (bd1014)

23
Depth-First Search Algorithm
  • Create a queue and add the first node to it
  • 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 front of the queue

24
Trace of Depth-First Search
  • Rochester
  • Debuque , LaCrosse, Minneapolis, Sioux Falls
  • Rockford, LaCrosse, Rochester, LaCrosse,
    Minneapolis, Sioux Falls
  • Chicago, Madison, Dubuque, LaCrosse, Rochester,
    LaCross, Minneapolis, Sioux Falls
  • Milwaukee, Rockford, Madison, Dubuque, LaCrosse,
    Rochester, LaCross, Minneapolis, Sioux Falls
  • Green Bay, Madison, Chicago, Rockford, Madison,
    Dubuque, LaCrosse, Rochester, LaCross,
    Minneapolis, Sioux Falls

25
Features of Depth-First Search
  • Expands the node at the deepest level
  • Only when the search hits a dead end does the
    search go back and expand nodes at shallower
    levels
  • Store only a single path from the root to a leaf,
    along with the remaining unexpanded sibling nodes
    for each node on the path
  • For branching factor b and maximum depth m,
    requires only storage of bm nodes
  • For b10, m12, needs only 12 kilobytes memory
  • Time complexity O(bm)
  • Could be faster if many solutions exit
  • Can get stuck going down the wrong path
  • Neither complete nor optimal

26
Depth-Limited Search
  • Imposes a cutoff on the maximum depth of a path
  • Guaranteed to find the solution if it exists and
    the depth limit is not too small
  • Not guaranteed to find the shortest solution
    first
  • Time complexity O(bl), l is the depth limit
  • Space complexity O(bl)

27
Informed Search
  • Characterized by that we have limited time and
    space in which to find an answer to complex
    problems and so we are willing to accept a good
    solution
  • Applies heuristics or rule of thumb as we are
    searching the tree to try to determine the
    likelihood that following one path or another is
    more likely to lead to a solution
  • Uses objective functions called evaluation
    functions to try to gauge the value of a
    particular node in the search tree and to
    estimate the value of following down any of the
    paths from the node

28
Best-First Search Algorithm
  • Create a queue and add the first node to it
  • 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
  • Insert the child to the queue according to the
    evaluation function

29
Greedy Search
  • A Best-First Search strategy using heuristic
    functions as the evaluation function
  • Heuristic function h(n) is a function that
    estimates the cost of the state at node n to the
    goal state
  • h(n) 0 if n is the goal state
  • Example the straight-line distance to the goal
    city in the graph search problem

30
SearchApplet Demo
31
Class Diagram for SearchApplet
32
Class SearchNode (1)
  • import java.util.
  • import java.awt.
  • public class SearchNode extends Object
  • String label
  • Object state
  • Object oper
  • Vector links
  • int depth
  • boolean expanded
  • boolean tested
  • float cost0

33
Class SearchNode (2)
  • static TextArea textArea1
  • public static final int FRONT 0
  • public static final int BACK 1
  • public static final int INSERT 2
  • SearchNode(String Label,
  • Object State)
  • label Label state State
  • depth 0
  • links new Vector()

34
Class SearchNode (3)
  • oper null
  • expanded false
  • tested false
  • public void addLink(
  • SearchNode Node)
  • links.addElement(Node)

35
Class SearchNode (4)
  • public void addLinks(
  • SearchNode n1, SearchNode n2)
  • links.addElement(n1)
  • links.addElement(n2)
  • public void addLinks(
  • SearchNode n1, SearchNode n2, SearchNode n3)
  • links.addElement(n1)
  • links.addElement(n2)
  • links.addElement(n3)

36
Class SearchNode (5)
  • public void addLinks(
  • SearchNode n1, SearchNode n2,
  • SearchNode n3, SearchNode n4)
  • links.addElement(n1) links.addElement(n2)
  • links.addElement(n3) links.addElement(n4)
  • public void addLinks(Vector Nodes)
  • for (int i0 i ltNodes.size()
  • i)

37
Class SearchNode (6)
  • links.addElement(
  • Nodes.elementAt(i))
  • public boolean leaf() return (links.size()
    0)
  • public void setDepth(int Depth) depth
    Depth
  • public void setOperator(Object Oper) oper
    Oper
  • public void setExpanded() expanded true

38
Class SearchNode (7)
  • public void setExpanded(
  • boolean state) expanded state
  • public void setTested(
  • boolean state) tested state
  • static public void setDisplay(TextArea
    textArea) textArea1 textArea
  • public void reset()
  • depth 0
  • expanded false
  • tested false

39
Class SearchNode (8)
  • public void trace()
  • String indent new String()
  • for (int i0 i lt depth i) indent "
    "
  • textArea1.append(indent
  • "Searching " depth " " label
  • " with state " state "\n")
  • public void expand(Vector queue, int position)
  • setExpanded()

40
Class SearchNode (9)
  • for (int j 0
  • j lt links.size() j)
  • SearchNode nextNode (SearchNode)links.elem
    entAt(j)
  • if (!nextNode.tested)
  • nextNode.setTested(true)
  • nextNode.setDepth(depth1)
  • switch (position)
  • case FRONT queue.insertElementAt(nextNo
    de,0)
  • break

41
Class SearchNode (10)
  • case BACK
  • queue.addElement(nextNode)
  • break
  • case INSERT
  • boolean inserted false
  • float nextCost
  • nextNode.cost
  • for (int k0 k lt
  • queue.size() k)
  • if (nextCost lt ((SearchNode)queue.elementAt(k))
    .cost)

42
Class SearchNode (11)
  • queue.insertElementAt(nextNode,
  • k)
  • inserted true
  • break
  • if (!inserted) queue.addElement(nextNode)
  • break

43
Class SearchGraph (1)
  • import java.util.
  • import java.awt.
  • class SearchGraph extends Hashtable
  • String name
  • SearchGraph(String Name)
  • name Name
  • void reset()
  • Enumeration enum
  • this.elements()

44
Class SearchGraph (2)
  • while(enum.hasMoreElements())
  • SearchNode nextNode (SearchNode)enum
    .
  • nextElement()
  • nextNode.reset()
  • void put(SearchNode node)
  • put(node.label, node)

45
Class SearchGraph (3)
  • public SearchNode depthFirstSearch(
  • SearchNode initialNode,
  • Object goalState)
  • Vector queue
  • new Vector() queue.addElement(
  • initialNode) initialNode.
  • setTested(true)

46
Class SearchGraph (4)
  • while (queue.size()gt 0)
  • SearchNode testNode
    (SearchNode)queue.firstElement()
  • queue.removeElementAt(0)
  • testNode.trace()
  • if (testNode.state.equals(goalState)) return
    testNode
  • if (!testNode.expanded)
    testNode.expand(
  • queue,SearchNode.FRONT)
  • return null

47
Class SearchGraph (5)
  • public SearchNode breadthFirstSearch(
  • SearchNode initialNode,
  • Object goalState)
  • Vector queue new Vector()
  • queue.addElement(initialNode)
  • initialNode.setTested(true) while
    (queue.size()gt 0)
  • SearchNode testNode (SearchNode)queue.fi
    rstElement()
  • queue.removeElementAt(0)
  • testNode.trace()

48
Class SearchGraph (6)
  • if (testNode.state.equals(
  • goalState)) return testNode
  • if (!testNode.expanded)
  • testNode.expand(
  • queue,SearchNode.BACK)
  • return null

49
Class SearchGraph (7)
  • public SearchNode depthLimitedSearch(
  • SearchNode initialNode,
  • Object goalState, int maxDepth)
  • Vector queue new Vector()
    queue.addElement(initialNode)
  • initialNode.setTested(true) while
    (queue.size()gt 0)
  • SearchNode testNode (SearchNode)queue.fi
    rstElement()
  • queue.removeElementAt(0)
  • testNode.trace()

50
Class SearchGraph (8)
  • if (testNode.state.equals(
  • goalState)) return testNode
  • if (testNode.depth lt maxDepth)
  • if (!testNode.expanded)
  • testNode.expand(
  • queue,SearchNode.FRONT)
  • return null

51
Class SearchGraph (9)
  • public SearchNode iterDeepSearch(
  • SearchNode startNode,
  • Object goalState)
  • int maxDepth 10
  • for (int j0 j lt maxDepth
  • j)
  • reset()
  • SearchNode answer depthLimitedSearch(st
    artNode,
  • goalState, j)
  • if (answer ! null)
  • return answer
  • return null

52
Class SearchGraph (10)
  • public SearchNode bestFirstSearch(
  • SearchNode initialNode,
  • Object goalState)
  • Vector queue new Vector()
    queue.addElement(initialNode)
    initialNode.setTested(true) while
    (queue.size()gt 0)
  • SearchNode testNode
    (SearchNode)queue.
  • firstElement()
  • queue.removeElementAt(0)
  • testNode.trace()

53
Class SearchGraph (11)
  • if (testNode.state.equals(
  • goalState))
  • return testNode
  • if (!testNode.expanded)
  • testNode.expand(
  • queue,SearchNode.INSERT)
  • return null

54
Class SearchApplet (1)
  • import java.awt.
  • import java.applet.
  • import java.util.
  • public class SearchApplet extends Applet
  • void button1_Clicked(
  • java.awt.event.ActionEvent event)
  • int method 0
  • SearchNode answer null
  • SearchNode startNode
  • String start
  • choice1.getSelectedItem()

55
Class SearchApplet (2)
  • startNode (SearchNode)graph.get(start)
  • String goal
  • choice2.getSelectedItem()
  • graph.reset()
  • if (radioButton1.getState()
  • true)
  • textArea1.append(
  • "\n\nDepth-First Search for "
  • goal "\n\n")
  • answer
  • graph.depthFirstSearch(
  • startNode,goal)

56
Class SearchApplet (3)
  • if (radioButton2.getState()
  • true)
  • textArea1.append(
  • "\n\nBreadth-First Search for "
  • goal "\n\n")
  • answer
  • graph.breadthFirstSearch(
  • startNode, goal)

57
Class SearchApplet (4)
  • if (radioButton3.getState()
  • true)
  • textArea1.append(
  • "\n\nIterated-Deepening Search for"
  • goal "\n\n")
  • answer
  • graph.iterDeepSearch(
  • startNode, goal)

58
Class SearchApplet (5)
  • if (radioButton4.getState()
  • true)
  • textArea1.append(
  • "\n\nBest-First Search for "
  • goal "\n\n")
  • choice2.select("Rochester") answer
  • graph.bestFirstSearch(
  • startNode, "Rochester")

59
Class SearchApplet (6)
  • if (answer null)
  • textArea1.append(
  • "Could not find answer!\n")
  • else
  • textArea1.append(
  • "Answer found in node "
  • answer.label)

60
Class SearchApplet (7)
  • void button2_Clicked(
  • java.awt.event.ActionEvent event)
  • void button3_Clicked(
  • java.awt.event.ActionEvent event)
  • textArea1.setText("")

61
Class SearchApplet (8)
  • public static SearchGraph testGraph()
  • SearchGraph graph
  • new SearchGraph("test") SearchNode roch
  • new SearchNode("Rochester",
  • "Rochester")
  • graph.put(roch)
  • SearchNode sfalls
  • new SearchNode(
  • "Sioux Falls","Sioux Falls")
  • graph.put(sfalls)

62
Class SearchApplet (9)
  • SearchNode mpls new SearchNode("Minneapol
    is",
  • "Minneapolis")
  • graph.put(mpls)
  • SearchNode lacrosse new SearchNode("LaCr
    osse",
  • "LaCrosse")
  • graph.put(lacrosse)
  • SearchNode fargo new
  • SearchNode("Fargo",
  • "Fargo")
  • graph.put(fargo)

63
Class SearchApplet (10)
  • SearchNode stcloud new SearchNode("St.Clou
    d",
  • "St.Cloud")
  • graph.put(stcloud)
  • SearchNode duluth new
  • SearchNode("Duluth",
  • "Duluth")
  • graph.put(duluth)
  • SearchNode wausau new
  • SearchNode("Wausau",
  • "Wausau")
  • graph.put(wausau)

64
Class SearchApplet (11)
  • SearchNode gforks new
  • SearchNode("Grand Forks",
  • "Grand Forks")
  • graph.put(gforks)
  • SearchNode bemidji new SearchNode("Bemid
    ji",
  • "Bemidji")
  • graph.put(bemidji)
  • SearchNode ifalls new
  • SearchNode(
  • "International Falls",
  • "International Falls")
  • graph.put(ifalls)

65
Class SearchApplet (12)
  • SearchNode gbay new
  • SearchNode("Green Bay",
  • "Green Bay")
  • graph.put(gbay)
  • SearchNode madison new
  • SearchNode("Madison",
  • "Madison")
  • graph.put(madison)
  • SearchNode dubuque new SearchNode("Dubuq
    ue",
  • "Dubuque")
  • graph.put(dubuque)

66
Class SearchApplet (13)
  • SearchNode rockford new SearchNode("Rockfor
    d",
  • "Rockford")
  • graph.put(rockford)
  • SearchNode chicago new SearchNode("Chica
    go",
  • "Chicago")
  • graph.put(chicago)
  • SearchNode milwaukee new
    SearchNode("Milwaukee",
  • "Milwaukee")
  • graph.put(milwaukee)

67
Class SearchApplet (14)
  • roch.addLinks(mpls, lacrosse,
  • sfalls, dubuque)
  • mpls.addLinks(duluth, stcloud,
  • wausau)
  • mpls.addLinks(lacrosse,
  • roch )
  • lacrosse.addLinks(madison,
  • dubuque, roch)
  • lacrosse.addLinks(mpls,gbay)
  • sfalls.addLinks(fargo, roch)
  • fargo.addLinks(sfalls, gforks,
  • stcloud)

68
Class SearchApplet (15)
  • gforks.addLinks(bemidji,
  • fargo, ifalls)
  • bemidji.addLinks(gforks,
  • ifalls, stcloud, duluth)
  • ifalls.addLinks(bemidji,
  • duluth, gforks)
  • duluth.addLinks(ifalls,mpls,
  • bemidji)
  • stcloud.addLinks(bemidji,
  • mpls, fargo)
  • dubuque.addLinks(lacrosse,
  • rockford)

69
Class SearchApplet (16)
  • rockford.addLinks(dubuque,
  • madison, chicago)
  • chicago.addLinks(rockford,
  • milwaukee)
  • milwaukee.addLinks(gbay,
  • chicago)
  • gbay.addLinks(wausau, milwaukee,
    lacrosse)
  • wausau.addLinks(mpls, gbay)
  • roch.cost 0
  • sfalls.cost 232
  • mpls.cost 90

70
Class SearchApplet (17)
  • lacrosse.cost 70
  • dubuque.cost 140
  • madison.cost 170
  • milwaukee.cost 230
  • rockford.cost 210
  • chicago.cost 280
  • stcloud.cost 140
  • duluth.cost 180
  • bemidji.cost 260
  • wausau.cost 200
  • gbay.cost 220
  • fargo.cost 280
  • gforks.cost 340

71
Class SearchApplet (18)
  • return graph
  • public void init()
  • super.init()
  • setLayout(null)
  • addNotify()
  • resize(459,407)
  • button1 new java.awt.Button("Start")
  • button1.setBounds(36,360,
  • 100,30)
  • add(button1)

72
Class SearchApplet (19)
  • button2 new
  • java.awt.Button("Stop")
  • button2.setBounds(168,360,
  • 100,30)
  • add(button2)
  • button3 new java.awt.Button("Clear") button
    3.setBounds(312,360,
  • 100,30)
  • add(button3)

73
Class SearchApplet (20)
  • Group1 new CheckboxGroup()
  • radioButton1 new
  • java.awt.Checkbox(
  • "Depth-First", Group1, false)
  • radioButton1.setBounds(24,300,
  • 100,24)
  • add(radioButton1)
  • radioButton2 new java.awt.Checkbox(
  • "Breadth-First", Group1, false)
  • radioButton2.setBounds(24,324,
  • 120,23)
  • add(radioButton2)

74
Class SearchApplet (21)
  • radioButton3 new
  • java.awt.Checkbox(
  • "Iterative Deepening",
  • Group1, false)
  • radioButton3.setBounds(
  • 216,300,168,25)
  • add(radioButton3)
  • radioButton4 new
  • java.awt.Checkbox(
  • "Best-First", Group1, false)
  • radioButton4.setBounds(216,324,
  • 122,25)
  • add(radioButton4)

75
Class SearchApplet (22)
  • choice2 new
  • java.awt.Choice()
  • add(choice2)
  • choice2.setBounds(240,264,156,
  • 24)
  • choice1 new
  • java.awt.Choice()
  • add(choice1)
  • choice1.setBounds(36,264,144,
  • 24)
  • label2 new
  • java.awt.Label(
  • "Goal State")

76
Class SearchApplet (23)
  • label2.setBounds(228,240,
  • 108,24)
  • add(label2)
  • label1 new
  • java.awt.Label("Start Node")
  • label1.setBounds(24,240,96,24)
  • add(label1)
  • textArea1 new
  • java.awt.TextArea()
  • textArea1.setBounds(0,0,
  • 456,240)
  • add(textArea1)

77
Class SearchApplet (24)
  • graph testGraph()
  • Enumeration enum graph.keys()
  • while(enum.hasMoreElements())
  • String name
  • (String)enum.nextElement()
  • choice1.addItem(name)
    choice2.addItem(name)
  • radioButton1.setState(true)
    SearchNode.setDisplay(textArea1)
    choice1.select("Rochester")

78
Class SearchApplet (25)
  • SymAction lSymAction
  • new SymAction() button1.addActionListener(
  • lSymAction)
  • button2.addActionListener(
  • lSymAction)
  • button3.addActionListener(
  • lSymAction)
  • java.awt.Button button1
  • java.awt.Button button2
  • java.awt.Button button3
  • java.awt.Checkbox radioButton1

79
Class SearchApplet (26)
  • CheckboxGroup Group1
  • java.awt.Checkbox radioButton2
  • java.awt.Checkbox radioButton3
  • java.awt.Checkbox radioButton4
  • java.awt.Choice choice2
  • java.awt.Choice choice1
  • java.awt.Label label2
  • java.awt.Label label1
  • java.awt.TextArea textArea1
  • SearchGraph graph

80
Class SearchApplet (27)
  • class SymAction implements java.awt.event.ActionL
    istener
  • public void actionPerformed(
  • java.awt.event.ActionEvent event)
  • Object object
  • event.getSource()

81
Class SearchApplet (28)
  • if (object button1)
  • button1_Clicked(event)
  • else if (object button2)
  • button2_Clicked(event)
  • else if (object button3)
  • button3_Clicked(event)

82
Uniform Cost Search
  • Always expand the lowest-cost node on the fringe
  • The cost of a path must never decrease as we go
    along the path, i.e., g(successor(n))gtg(n)
  • Breadth-First Search is a special case, with g(n)
    depth(n)
  • Complete and optimal
  • Time and space complexity O(bd)

83
A Search
  • A Best-First Search strategy using the evaluation
    function f(n) g(n)h(n), where g(n) is the
    cost of the path so far, and h(n) is the
    estimated cost to the goal
  • Combines the Greedy search and the uniform-cost
    search
  • h(n) should be an admissible heuristic, which
    never overestimate the cost to reach the goal.
    i.e., the straight-line distance in the city
    traveling problem
  • pathmax equation f(n) max( f(n), g(n)h(n)
    ), where node n is the parent of node n

84
Optimality of A Search
85
Features of A Search
  • The first solution found must be the optimal one,
    because nodes in all subsequent contours will
    have higher f-cost
  • Is complete
  • Optimally efficient for any given heuristic
    function

86
Proof of the Optimality of A
  • Assume that G2 is a suboptimal goal state that
    g(G2) gtf
  • Node n is currently a leaf node on an optimal
    path to the optimal goal state G
  • f gt f(n)
  • f(n) gt f(G2)
  • f gt f(G2)
  • f gt g(G2), a contradiction

Start
n
G2
G
87
Iterative Improvement Algorithms
  • Need not maintain a search tree
  • Starts with a complete configuration and make
    modifications to improve its quality
  • Example Eight-Queen Problem
  • Landscape concept

88
Hill-Climbing Search
  • current initial state
  • Loop
  • next a highest-valued successor of current
  • if valuenext lt valuecurrent return current
  • current next

89
Drawbacks of Hill-Climbing
  • May halt at a local maximum
  • Plateaux may result in a random walk
  • Ridges may cause oscillation
  • Random-restart hill-climbing may help

90
Simulated Annealing
  • current initial state
  • Loop for t 1 to infinity
  • T schedulet
  • if T 0 return current
  • next a randomly selected successor of current
  • DE valuenext-valuecurrent
  • if DE gt 0 then current next
  • else current next only with probability
    exp(DE/T)

91
Two-Person Games
  • A game can be formally defined as a kind of
    search problem with initial state, a set of
    operators, a terminal test, and a utility
    function
  • A search tree may be constructed, with large
    number of states
  • States at depth d and depth d1 are for different
    players (two plies)
  • Uncertainly is introduced

92
A Partial Tree for Tic-Tac-Toe
93
A Two-Ply Game Tree
MAX
3
MIN
3
2
2
5
2
3
6
14
8
12
2
4
94
MiniMax Algorithm
  • 1. Loop for each operator
  • Valueoperator MiniMaxValue of the state
    obtained by applying the operator
  • 2. return the operator with the highest value

95
MiniMaxValue Function
  • if the state is terminal then
  • return the corresponding utility function value
  • else if MAX is to move in state then
  • return the highest MiniMaxValue of the successors
    of the state
  • else
  • return the lowest MiniMaxValue of the successors
    of the state

96
Evaluation Functions
  • Returns an estimate of the expected utility of
    the game from a given position
  • Must agree with the utility function on terminal
    states
  • Must not take too long to compute
  • Should accurately reflect the actual chance of
    winning

97
Alpha-Beta Pruning
  • When applied to a standard minimax tree, it
    returns the same move as minimax would, but
    prunes away branches that can not possibly
    influence the final decision
  • Alpha is the value of the best choice we have
    found so far at any choice point along the path
    for MAX
  • Beta is the value of the best choice we have
    found so far at any choice point along the path
    for MIN

98
Example of Alpha-Beta Pruning
MAX
3
MIN
3
2
2
5
2
3
14
8
12
2
99
MaxValue Function
  • if the state is cutoff
  • val Eval( state )
  • a Max( a, val )
  • Return val
  • for each state s in successors of the state
  • a Max( a, MinValue of state s )
  • If a gt b return b
  • return a

100
MinValue Function
  • if the state is cutoff
  • Val Eval( state )
  • b Min( b, val )
  • Return val
  • for each state s in successors of the state
  • b Min( b, MaxValue of state s )
  • If b lt a return a
  • return b
Write a Comment
User Comments (0)
About PowerShow.com