SlideShare une entreprise Scribd logo
1  sur  26
Heuristics

Some further elaborations
of the art of heuristics and
examples.
Goodness of heuristics
If a heuristic is perfect, search work is proportional to solution length
  S = O(b*d)           b is average branching, d depth of solution
If h1 and h2 are two heuristics, and h1 < h2 everywhere,
then A*(h2) will expand no more nodes than A*(h1)
If an heuristic never overestimates more than N % of the least cost,
then the found solution is not more than N% over the optimal
solution.
h()=0 is an admissible trivial heuristic, worst of all


In theory, we can always make a perfect heuristics, if we perform a
full breadth first search from each node, but that would be pointless.
Example of good heuristics for the 8
             puzzle

Transparency shows the heuristic


 f(n)=g(n) + h(n)
 h(n)=# misplaced tiles


On an A* search for the 8 - puzzle
Graph Search
%% Original version
function GRAPH-SEARCH(problem,fringe) returns a solution, or
failure
closed <-    an empty set
fringe <-    INSERT(MAKE-NODE(INITIAL-STATE[problem]),fringe)
loop do
    if EMPTY?(fringe) then return failure
    node <- REMOVE-FIRST(fringe)
    if GOAL-TEST[problem](STATE[node]) then return SOLUTION(node)
    if STATE[node] is not in closed then
             add STATE[node] to closed
             fringe <- INSERT-ALL(EXPAND(node,problem),fringe)
Heuristic Best First Search
%% f [problem] is the heuristic selection function of the problem

function BEST-FIRST-SEARCH([problem])returns a solution,or failure
OPEN <- an empty set                // P1
CLOSED   <- an empty set            // P2
OPEN <- INSERT(MAKE-NODE(INITIAL-STATE[problem]),OPEN) // P3
repeat
    if EMPTY?(OPEN) then return failure //P4
    best <- the lowest f-valued node on OPEN // P5
    remove best from OPEN // P6
    if GOAL-TEST[problem](STATE[best])
               then return SOLUTION(best) // P7
    for all successors M of best
    if STATE[M] is not in CLOSED then     // P8
         OPEN <-INSERT(successor,OPEN) // P9
    add STATE[best] to CLOSED    // P10
Heuristic Best First Search
                            (A*)Java Pseudocode
 // Instantiating OPEN, CLOSED                   // Move selected node from OPEN to n // P6
   OPEN = new Vector<Node>();           // P1      n = OPEN.elementAt(lowIndex);
   CLOSED = new Vector<Node>();          // P2      OPEN.removeElement(n);
                                                 // Successful exit if n is goal node // P8
   // Placing initial node on OPEN                     if (n.equals(goalnode)) return;
   OPEN.add(0, initialnode);             // P3         // Retrieve all possible successors of n
                                                       M = n.successors();
// After  initial phase,we enter the main loop   //Compute f-,g- and h-value for each successor
          // of the A* algorithm                       for (int i = 0; i < M.size(); i++) {
    while (true) {                                          Node s = M.elementAt(i);
     // Check if OPEN is empty                              s.g = n.g + s.cost;
     if (OPEN.size() == 0) { // P4                          s.h = s.estimate(goalnode);
          System.out.println("Failure :");                  s.f = s.g + s.h;
                     return;                     // Augmenting OPEN with suitable nodes from M
 // Locate next node on OPEN with heuristic            for (int i = 0; i < M.size(); i++)
     lowIndex = 0;                       // P5   // Insert node into OPEN if not on CLOSED// P9
     low = OPEN.elementAt(0).f;                            if (!(on CLOSED))
     for (int i = 0; i < OPEN.size(); i++) {                OPEN.add(0, M.elementAt(i));
                 number = OPEN.elementAt(i).f;         // Insert n into CLOSED
          if (number < low) {                          CLOSED.add(0, n); // P10
                lowIndex = i;
               low = number;
AStar
                 Java Code
See exercise 7

 http://www.idi.ntnu.no/emner/tdt4136/PRO/Astar.java
Example
      Mouse King Problem
  (1,5)        (5,5)
    ___________
    | | | | | |
    | | |X| | |
    | | |X| | |
    | | |X| | |
    |M| |X| |C|
    -----------
   (1,1)       (5,1)

There is a 5X5 board.
At (1,1) there is a mouse M which can move as a king on a chess board.
The target is a cheese C at (5,1).

There is however a barrier XXXX at (3,1-4) which the mouse cannot go
through, but the mouse heuristics is to ignore this.
Heuristics for Mouse King
public class MouseKingState extends State {
  public int[] value;
  public MouseKingState(int[] v) {value = v;}
  public boolean equals(State state) {…}
  public String toString() {…}
  public Vector<State> successors() {…}

 public int estimate(State goal) {
       MouseKingState goalstate = (MouseKingState)goal;
       int[] goalarray = goalstate.value;
       int dx = Math.abs(goalarray[0] - value[0]);
        int dy = Math.abs(goalarray[1] - value[1]);
       return Math.max(dx, dy);
 }

} // End class MouseKingState
Behaviour of Mouse King
The mouse will expand the following nodes:

1,1   2,1   2,2   2,3   1,2 1,3      2,4   1,4     2,5
3,5   4,4   4,3   4,2   5,1



Solution Path:
start,f,g,h         (1,5)        (5,5)                   (1,5)        (5,5)
                            _______________                      _______________
(1,1),4,0,4                 | | 9|10| | |                        | | |5 | | |
(2,2),4,1,3                 | 8| 7| |11| |                       | | 4| |6 | |
(2,3),5,2,3                 | 6| 4| |12| |                       | | 3| |7 | |
                            | 5| 3| |13| |                       | | 2| |8 | |
(2,4),6,3,3
                            | 1| 2| | |14|                       | 1| | | |9 |
(3,5),8,4,4                 ----------------                     ----------------
(4,4),8,5,3             (1,1)              (5,1)             (1,1)            (5,1)
(4,3),8,6,2
                    Order of expansion                   Solution Path
(4,2),8,7,1
(5,1),8,8,0
Perfect Heuristics Behaviour
If the heuristics had been perfect, the expansion of the nodes would have
been equal to the solution path.
     1,1 2,2 2,3 2,4 3,5 4,4 4,2 4,2 5,1
This means that a perfect heuristics ”encodes” all the relevant knowledge of the problem
space.

Solution Path:
start,f,g,h                  (1,5)            (5,5)             (1,5)              (5,5)
                              _______________                      _______________
(1,1),8,0,8                  | | |5 | | |                         | | |5 | | |
(2,2),8,1,7                  | | 4| |6 | |                        | | 4| |6 | |
(2,3),8,2,6                  | | 3| |7 | |                        | | 3| |7 | |
                             | | 2| |8 | |                        | | 2| |8 | |
(2,4),8,3,5
                             | 1| | | |9 |                        | 1| | | |9 |
(3,5),8,4,4                  ----------------                     ----------------
(4,4),8,5,3                  (1,1)               (5,1)            (1,1)               (5,1)
(4,3),8,6,2
                         Order of expansion                  Solution Path
(4,2),8,7,1
(5,1),8,8,0
Monotone (consistent) heuristics
A heuristic is monotone if the f-value is non-decreasing
along any path from start to goal.
This is fulfilled if for every pair of nodes
    n  n’
  f(n) <= f(n’) = g(n’) + h(n’)
                = g(n) + cost(n,n’) + h(n’)
  f(n) = g(n) + h(n)
Which gives the triangle inequality
     h(n) <= cost(n.n’) + h(n’)

         cost(n,n’)
                                  h(n’)

                                               goal
             h(n)
Properties of monotone heuristics
1) All monotone heuristics are admissible
2) Monotone heuristic is admissible at all nodes (if h(G)=0)
3) If a node is expanded using a monotone heuristic, A* has
   found the optimal route to that node
4) Therefore, there is no need to consider a node if it is already
   found.
5) If this is assumed, and the heuristic is monotone, the
   algorithm is still admissible
6) If the monotone assumption is not true, we risk a non
   optimal solution
7) However, most heuristics are monotone
Some more notes on heuristics
If h1(n) and h2(n) are admissible heuristics, then the
following are also admissible heuristics

• max(h1(n),h2(n))
• α*h1(n) + β*h2(n) where α+β=1
Monotone heuristic repair

Suppose a heuristic h is admissible but not consistent, i.e.

   h(n) > c(n,n’)+h(n’), which means

   f(n) > f(n’) (f is not monotone)

In that case, f’(n’) can be set to f(n) as a better heuristic,
(higher but still underestimate), i.e. use

    h’(n’) = max(h(n’),h(n)-c(n,n’))
An example of a heuristics
Consider a knight (”horse”) on a chess board.
It can move 2 squares in one direction and 1 to either side.
The task is to get from one square to another in fewest possible steps
 (e.g. A1 to H8).

A proposed heuristics could be      ManHattanDistance/2
   Is it admissible ? Is it monotone ?

(Actually, it is not straightforward to find an heuristics that is both admissible and not
monotone)


                  8   | | | | | |              |
                                               |*|
                  7   | | | | | |              |
                                               | |
                  6   | | | | | |              |
                                               | |
                  5   | | | | | |              |
                                               | |
                  4   | | | | | |              |
                                               | |
                  3   | | | | | |              |
                                               | |
                  2   | | | | | |              |
                                               | |
                  1   |*| | | | |              |
                                               | |
                       A B C D E            F G H
Relaxed problems
Many heuristics can be found by using a relaxed (easier, simpler)
model of the problem.
By definition, heuristics derived from relaxed models are
underestimates of the cost of the original problem
For example, straight line distance presumes that we can move in
straight lines.
For the 8-puzzle, the heuristics
   W(n) = # misplaced tiles
would be exact if we could move tiles freely
The less relaxed, (and therefore better) heuristic
   P(n) =    distance from home ( Manhattan distance)
 would allow tiles to be moved to an adjacent square even though
there may already be a tile there.
Generalized A*
       f(n) = *g(n) + *h(n)
     = =1          A*
=0                 Uniform cost
=0                Greedy search
< 0,=0            Depth first
      >            Conservative (still admissible)
 <                 Radical (not admissible)
, depending on g,h Dynamic
Learning heuristics from experience
Where do heuristics come from ?

Heuristics can be learned as a computed (linear?) combination of features of the state.
Example: 8-puzzle

Features:

    x1(n) : number of misplaced tiles
    x2(n) : number of adjacent tiles that are also adjacent in the goal state

Procedure: make a run of searches from 100 random start states. Let h(ni) be the
found minimal cost.
          n1   h(n1)   x1(n1)     x2(n1)
          …    ……      ……..       ……….
          n100 h(n100) x1(n100)   x2(n100)

From these, use regression to estimate
            h(n) = c1*x1(n) + c2*x2(n)
Learning heuristics from
                 experience (II)
Suppose the problem is harder than the heuristic (h1) indicates but that the
hardness is assumed to be uniform over the state space. Then , it is an estimate to
let an improved heuristics h2(x) = *h1(x).


       |S|   |   | |   |   |   | |      Problem: move a piece from S to G using ChessKing
       | |   |   | |   |   |   | |      heuristics h1(x) = # horisontal/vertical/diagonal moves.

       | |   |   | |   |   |   | |         h1(S)=7 h1(n) = 4
       | |   |   |n|   |   |   | |
       | |   |   | |   |   |   | |      Assume problem is actual harder (in effect Manhattan
                                        disance h2(x), but we dont’ know that). It means
       | |   |   | |   |   |   | |
                                             g(n) = 6
       | |   |   | |   |   |   | |      We then estimate = g(n)/(h1(s)-h1(n))
       | |   |   | |   |   |   | G|
                                             h2(n) = g(n)/(h1(s)-h1(n)) * h1(n)

                                                    = 6/(7 – 4) *4 = 8 (correct)
Learning heuristics from
                 experience (III)
Suppose the problem is easier than the heuristic (h1) indicates but that the
easiness is assumed to be uniform over the state space. Then , it is an estimate to
let an improved heuristics h2(x) = *h1(x).


       |S|   |   | |   |   |   | |       Problem: move a piece from S to G using Manhattan
       | |   |   | |   |   |   | |       heuristics h1(x) = # horisontal/vertical moves

       | |   |   | |   |   |   | |          h1(S)=14 h1(n) = 8
       | |   |   |n|   |   |   | |
       | |   |   | |   |   |   | |       Assume problem is actual easier (in effect Chess King
                                         disance h2(x), but we dont’ know that). It means
       | |   |   | |   |   |   | |
                                              g(n) = 3
       | |   |   | |   |   |   | |       We then estimate = g(n)/(h1(s)-h1(n))
       | |   |   | |   |   |   | G|
                                             h2(n) = g(n)/(h1(s)-h1(n)) * h1(n)

                                                     = 3/(14 – 8) *8 = 4 (correct)
Practical example
                       (Bus world scenario)

Find an optimal route from one place to
another by public transport


Nodes: Bus passing events
 A bus route passes a station at a time
 Actions:    - enter bus
             - leave bus
             - wait
Bus scenario search space
       Search space      space(2) X time(1)

Time




                                            Bus 3

                                     wait


         Space               Bus 5




                                                    Space
Heuristics for bus route planner
                        which route is best ?
                                    T3 = Z      N # bus transfers
                            K3                  A wait time 1. departure
                                                Z wait time before arrival
                   T2                           T sum transfer waiting time

          K2                                    K sum driving time
               Equivalent
               transfer
     T1


   K1


T0 = A
Planner discussion
1.   (T1+T2) = T critical if rain
2.   If Z is to be minimised, must search backwards
3.   Many equivalent transfers (same T and K)
4.   In practice, A* is problematic
5.   Waiting time A maybe unimportant



Solution: Relaxation
a)   Find trasees independent of time
b) Eliminate equivalent transfers
c)   For each trasee, find best route plan
d) Keep the best of these solutions

Contenu connexe

Tendances

Machine Learning Chapter 11 2
Machine Learning Chapter 11 2Machine Learning Chapter 11 2
Machine Learning Chapter 11 2
butest
 

Tendances (16)

Lesson 18
Lesson 18Lesson 18
Lesson 18
 
Polycycles and their elementary decompositions
Polycycles and their elementary decompositionsPolycycles and their elementary decompositions
Polycycles and their elementary decompositions
 
THE RESULT FOR THE GRUNDY NUMBER ON P4- CLASSES
THE RESULT FOR THE GRUNDY NUMBER ON P4- CLASSESTHE RESULT FOR THE GRUNDY NUMBER ON P4- CLASSES
THE RESULT FOR THE GRUNDY NUMBER ON P4- CLASSES
 
Machine learning Lecture 2
Machine learning Lecture 2Machine learning Lecture 2
Machine learning Lecture 2
 
Surds,
Surds,Surds,
Surds,
 
code optimization 1...code optimization-1221849738688969-9
code optimization 1...code optimization-1221849738688969-9code optimization 1...code optimization-1221849738688969-9
code optimization 1...code optimization-1221849738688969-9
 
4 chap
4 chap4 chap
4 chap
 
Global Domination Set in Intuitionistic Fuzzy Graph
Global Domination Set in Intuitionistic Fuzzy GraphGlobal Domination Set in Intuitionistic Fuzzy Graph
Global Domination Set in Intuitionistic Fuzzy Graph
 
11 applications of factoring
11 applications of factoring11 applications of factoring
11 applications of factoring
 
Unit 3-Greedy Method
Unit 3-Greedy MethodUnit 3-Greedy Method
Unit 3-Greedy Method
 
Lp and ip programming cp 9
Lp and ip programming cp 9Lp and ip programming cp 9
Lp and ip programming cp 9
 
Machine Learning Chapter 11 2
Machine Learning Chapter 11 2Machine Learning Chapter 11 2
Machine Learning Chapter 11 2
 
Prerna Jee Advanced 2013 maths- Paper 2
Prerna Jee Advanced 2013 maths- Paper 2Prerna Jee Advanced 2013 maths- Paper 2
Prerna Jee Advanced 2013 maths- Paper 2
 
Gate Previous Years Papers
Gate Previous Years PapersGate Previous Years Papers
Gate Previous Years Papers
 
Multi objective optimization and Benchmark functions result
Multi objective optimization and Benchmark functions resultMulti objective optimization and Benchmark functions result
Multi objective optimization and Benchmark functions result
 
Modul t4
Modul t4Modul t4
Modul t4
 

En vedette

Ai 03 solving_problems_by_searching
Ai 03 solving_problems_by_searchingAi 03 solving_problems_by_searching
Ai 03 solving_problems_by_searching
Mohammed Romi
 
Presentation - Bi-directional A-star search
Presentation - Bi-directional A-star searchPresentation - Bi-directional A-star search
Presentation - Bi-directional A-star search
Mohammad Saiful Islam
 
16890 unit 2 heuristic search techniques
16890 unit 2 heuristic  search techniques16890 unit 2 heuristic  search techniques
16890 unit 2 heuristic search techniques
Jais Balta
 
09 heuristic search
09 heuristic search09 heuristic search
09 heuristic search
Tianlu Wang
 
(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 ai(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 ai
Radhika Srinivasan
 

En vedette (20)

Ai 03 solving_problems_by_searching
Ai 03 solving_problems_by_searchingAi 03 solving_problems_by_searching
Ai 03 solving_problems_by_searching
 
simple
simplesimple
simple
 
Travel Plan using Geo-tagged Photos in Geocrowd2013
Travel Plan using Geo-tagged Photos in Geocrowd2013 Travel Plan using Geo-tagged Photos in Geocrowd2013
Travel Plan using Geo-tagged Photos in Geocrowd2013
 
Seminar "Technology Enhanced Learning" - Einheit 1
Seminar "Technology Enhanced Learning" - Einheit 1Seminar "Technology Enhanced Learning" - Einheit 1
Seminar "Technology Enhanced Learning" - Einheit 1
 
Technology Seminar Handout
Technology Seminar HandoutTechnology Seminar Handout
Technology Seminar Handout
 
Presentation heuristics
Presentation heuristicsPresentation heuristics
Presentation heuristics
 
Presentation - Bi-directional A-star search
Presentation - Bi-directional A-star searchPresentation - Bi-directional A-star search
Presentation - Bi-directional A-star search
 
M4 Heuristics
M4 HeuristicsM4 Heuristics
M4 Heuristics
 
Heuristc Search Techniques
Heuristc Search TechniquesHeuristc Search Techniques
Heuristc Search Techniques
 
16890 unit 2 heuristic search techniques
16890 unit 2 heuristic  search techniques16890 unit 2 heuristic  search techniques
16890 unit 2 heuristic search techniques
 
04 search heuristic
04 search heuristic04 search heuristic
04 search heuristic
 
Lecture 11 Informed Search
Lecture 11 Informed SearchLecture 11 Informed Search
Lecture 11 Informed Search
 
Solving problems by searching Informed (heuristics) Search
Solving problems by searching Informed (heuristics) SearchSolving problems by searching Informed (heuristics) Search
Solving problems by searching Informed (heuristics) Search
 
Optimization Heuristics
Optimization HeuristicsOptimization Heuristics
Optimization Heuristics
 
Lecture 14 Heuristic Search-A star algorithm
Lecture 14 Heuristic Search-A star algorithmLecture 14 Heuristic Search-A star algorithm
Lecture 14 Heuristic Search-A star algorithm
 
Lect6 csp
Lect6 cspLect6 csp
Lect6 csp
 
AI search techniques
AI search techniquesAI search techniques
AI search techniques
 
Firefly algorithm
Firefly algorithmFirefly algorithm
Firefly algorithm
 
09 heuristic search
09 heuristic search09 heuristic search
09 heuristic search
 
(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 ai(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 ai
 

Similaire à Heuristics

Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In Ruby
Ross Lawley
 
13 recursion-120712074623-phpapp02
13 recursion-120712074623-phpapp0213 recursion-120712074623-phpapp02
13 recursion-120712074623-phpapp02
Abdul Samee
 
1- please please please don't send me an incomplete program this code.docx
1- please please please don't send me an incomplete program this code.docx1- please please please don't send me an incomplete program this code.docx
1- please please please don't send me an incomplete program this code.docx
EvandWyBurgesss
 
Skiena algorithm 2007 lecture15 backtracing
Skiena algorithm 2007 lecture15 backtracingSkiena algorithm 2007 lecture15 backtracing
Skiena algorithm 2007 lecture15 backtracing
zukun
 
Jarrar.lecture notes.aai.2011s.ch4.informedsearch
Jarrar.lecture notes.aai.2011s.ch4.informedsearchJarrar.lecture notes.aai.2011s.ch4.informedsearch
Jarrar.lecture notes.aai.2011s.ch4.informedsearch
PalGov
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
Damian T. Gordon
 
Using an Array include ltstdiohgt include ltmpih.pdf
Using an Array include ltstdiohgt include ltmpih.pdfUsing an Array include ltstdiohgt include ltmpih.pdf
Using an Array include ltstdiohgt include ltmpih.pdf
giriraj65
 
Owf 2013 rii veri t fontaine speaker4
Owf 2013 rii veri t fontaine speaker4Owf 2013 rii veri t fontaine speaker4
Owf 2013 rii veri t fontaine speaker4
Patrick MOREAU
 

Similaire à Heuristics (20)

An introduction to Google test framework
An introduction to Google test frameworkAn introduction to Google test framework
An introduction to Google test framework
 
Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In Ruby
 
Lecture#9
Lecture#9Lecture#9
Lecture#9
 
13 recursion-120712074623-phpapp02
13 recursion-120712074623-phpapp0213 recursion-120712074623-phpapp02
13 recursion-120712074623-phpapp02
 
A* and Min-Max Searching Algorithms in AI , DSA.pdf
A* and Min-Max Searching Algorithms in AI , DSA.pdfA* and Min-Max Searching Algorithms in AI , DSA.pdf
A* and Min-Max Searching Algorithms in AI , DSA.pdf
 
algorithm Unit 3
algorithm Unit 3algorithm Unit 3
algorithm Unit 3
 
1- please please please don't send me an incomplete program this code.docx
1- please please please don't send me an incomplete program this code.docx1- please please please don't send me an incomplete program this code.docx
1- please please please don't send me an incomplete program this code.docx
 
Skiena algorithm 2007 lecture15 backtracing
Skiena algorithm 2007 lecture15 backtracingSkiena algorithm 2007 lecture15 backtracing
Skiena algorithm 2007 lecture15 backtracing
 
Absolute Value
Absolute ValueAbsolute Value
Absolute Value
 
Jarrar.lecture notes.aai.2011s.ch4.informedsearch
Jarrar.lecture notes.aai.2011s.ch4.informedsearchJarrar.lecture notes.aai.2011s.ch4.informedsearch
Jarrar.lecture notes.aai.2011s.ch4.informedsearch
 
Absolute Value Notes
Absolute Value NotesAbsolute Value Notes
Absolute Value Notes
 
Pert 05 aplikasi clustering
Pert 05 aplikasi clusteringPert 05 aplikasi clustering
Pert 05 aplikasi clustering
 
Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
 
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
 
Unit 3 daa
Unit 3 daaUnit 3 daa
Unit 3 daa
 
Pythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPUPythonbrasil - 2018 - Acelerando Soluções com GPU
Pythonbrasil - 2018 - Acelerando Soluções com GPU
 
Using an Array include ltstdiohgt include ltmpih.pdf
Using an Array include ltstdiohgt include ltmpih.pdfUsing an Array include ltstdiohgt include ltmpih.pdf
Using an Array include ltstdiohgt include ltmpih.pdf
 
Owf 2013 rii veri t fontaine speaker4
Owf 2013 rii veri t fontaine speaker4Owf 2013 rii veri t fontaine speaker4
Owf 2013 rii veri t fontaine speaker4
 
Ip 5 discrete mathematics
Ip 5 discrete mathematicsIp 5 discrete mathematics
Ip 5 discrete mathematics
 

Dernier

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Dernier (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 

Heuristics

  • 1. Heuristics Some further elaborations of the art of heuristics and examples.
  • 2. Goodness of heuristics If a heuristic is perfect, search work is proportional to solution length S = O(b*d) b is average branching, d depth of solution If h1 and h2 are two heuristics, and h1 < h2 everywhere, then A*(h2) will expand no more nodes than A*(h1) If an heuristic never overestimates more than N % of the least cost, then the found solution is not more than N% over the optimal solution. h()=0 is an admissible trivial heuristic, worst of all In theory, we can always make a perfect heuristics, if we perform a full breadth first search from each node, but that would be pointless.
  • 3. Example of good heuristics for the 8 puzzle Transparency shows the heuristic f(n)=g(n) + h(n) h(n)=# misplaced tiles On an A* search for the 8 - puzzle
  • 4.
  • 5. Graph Search %% Original version function GRAPH-SEARCH(problem,fringe) returns a solution, or failure closed <- an empty set fringe <- INSERT(MAKE-NODE(INITIAL-STATE[problem]),fringe) loop do if EMPTY?(fringe) then return failure node <- REMOVE-FIRST(fringe) if GOAL-TEST[problem](STATE[node]) then return SOLUTION(node) if STATE[node] is not in closed then add STATE[node] to closed fringe <- INSERT-ALL(EXPAND(node,problem),fringe)
  • 6. Heuristic Best First Search %% f [problem] is the heuristic selection function of the problem function BEST-FIRST-SEARCH([problem])returns a solution,or failure OPEN <- an empty set // P1 CLOSED <- an empty set // P2 OPEN <- INSERT(MAKE-NODE(INITIAL-STATE[problem]),OPEN) // P3 repeat if EMPTY?(OPEN) then return failure //P4 best <- the lowest f-valued node on OPEN // P5 remove best from OPEN // P6 if GOAL-TEST[problem](STATE[best]) then return SOLUTION(best) // P7 for all successors M of best if STATE[M] is not in CLOSED then // P8 OPEN <-INSERT(successor,OPEN) // P9 add STATE[best] to CLOSED // P10
  • 7. Heuristic Best First Search (A*)Java Pseudocode // Instantiating OPEN, CLOSED // Move selected node from OPEN to n // P6 OPEN = new Vector<Node>(); // P1 n = OPEN.elementAt(lowIndex); CLOSED = new Vector<Node>(); // P2 OPEN.removeElement(n); // Successful exit if n is goal node // P8 // Placing initial node on OPEN if (n.equals(goalnode)) return; OPEN.add(0, initialnode); // P3 // Retrieve all possible successors of n M = n.successors(); // After initial phase,we enter the main loop //Compute f-,g- and h-value for each successor // of the A* algorithm for (int i = 0; i < M.size(); i++) { while (true) { Node s = M.elementAt(i); // Check if OPEN is empty s.g = n.g + s.cost; if (OPEN.size() == 0) { // P4 s.h = s.estimate(goalnode); System.out.println("Failure :"); s.f = s.g + s.h; return; // Augmenting OPEN with suitable nodes from M // Locate next node on OPEN with heuristic for (int i = 0; i < M.size(); i++) lowIndex = 0; // P5 // Insert node into OPEN if not on CLOSED// P9 low = OPEN.elementAt(0).f; if (!(on CLOSED)) for (int i = 0; i < OPEN.size(); i++) { OPEN.add(0, M.elementAt(i)); number = OPEN.elementAt(i).f; // Insert n into CLOSED if (number < low) { CLOSED.add(0, n); // P10 lowIndex = i; low = number;
  • 8. AStar Java Code See exercise 7 http://www.idi.ntnu.no/emner/tdt4136/PRO/Astar.java
  • 9. Example Mouse King Problem (1,5) (5,5) ___________ | | | | | | | | |X| | | | | |X| | | | | |X| | | |M| |X| |C| ----------- (1,1) (5,1) There is a 5X5 board. At (1,1) there is a mouse M which can move as a king on a chess board. The target is a cheese C at (5,1). There is however a barrier XXXX at (3,1-4) which the mouse cannot go through, but the mouse heuristics is to ignore this.
  • 10. Heuristics for Mouse King public class MouseKingState extends State { public int[] value; public MouseKingState(int[] v) {value = v;} public boolean equals(State state) {…} public String toString() {…} public Vector<State> successors() {…} public int estimate(State goal) { MouseKingState goalstate = (MouseKingState)goal; int[] goalarray = goalstate.value; int dx = Math.abs(goalarray[0] - value[0]); int dy = Math.abs(goalarray[1] - value[1]); return Math.max(dx, dy); } } // End class MouseKingState
  • 11. Behaviour of Mouse King The mouse will expand the following nodes: 1,1 2,1 2,2 2,3 1,2 1,3 2,4 1,4 2,5 3,5 4,4 4,3 4,2 5,1 Solution Path: start,f,g,h (1,5) (5,5) (1,5) (5,5) _______________ _______________ (1,1),4,0,4 | | 9|10| | | | | |5 | | | (2,2),4,1,3 | 8| 7| |11| | | | 4| |6 | | (2,3),5,2,3 | 6| 4| |12| | | | 3| |7 | | | 5| 3| |13| | | | 2| |8 | | (2,4),6,3,3 | 1| 2| | |14| | 1| | | |9 | (3,5),8,4,4 ---------------- ---------------- (4,4),8,5,3 (1,1) (5,1) (1,1) (5,1) (4,3),8,6,2 Order of expansion Solution Path (4,2),8,7,1 (5,1),8,8,0
  • 12. Perfect Heuristics Behaviour If the heuristics had been perfect, the expansion of the nodes would have been equal to the solution path. 1,1 2,2 2,3 2,4 3,5 4,4 4,2 4,2 5,1 This means that a perfect heuristics ”encodes” all the relevant knowledge of the problem space. Solution Path: start,f,g,h (1,5) (5,5) (1,5) (5,5) _______________ _______________ (1,1),8,0,8 | | |5 | | | | | |5 | | | (2,2),8,1,7 | | 4| |6 | | | | 4| |6 | | (2,3),8,2,6 | | 3| |7 | | | | 3| |7 | | | | 2| |8 | | | | 2| |8 | | (2,4),8,3,5 | 1| | | |9 | | 1| | | |9 | (3,5),8,4,4 ---------------- ---------------- (4,4),8,5,3 (1,1) (5,1) (1,1) (5,1) (4,3),8,6,2 Order of expansion Solution Path (4,2),8,7,1 (5,1),8,8,0
  • 13. Monotone (consistent) heuristics A heuristic is monotone if the f-value is non-decreasing along any path from start to goal. This is fulfilled if for every pair of nodes n  n’ f(n) <= f(n’) = g(n’) + h(n’) = g(n) + cost(n,n’) + h(n’) f(n) = g(n) + h(n) Which gives the triangle inequality h(n) <= cost(n.n’) + h(n’) cost(n,n’) h(n’) goal h(n)
  • 14. Properties of monotone heuristics 1) All monotone heuristics are admissible 2) Monotone heuristic is admissible at all nodes (if h(G)=0) 3) If a node is expanded using a monotone heuristic, A* has found the optimal route to that node 4) Therefore, there is no need to consider a node if it is already found. 5) If this is assumed, and the heuristic is monotone, the algorithm is still admissible 6) If the monotone assumption is not true, we risk a non optimal solution 7) However, most heuristics are monotone
  • 15. Some more notes on heuristics If h1(n) and h2(n) are admissible heuristics, then the following are also admissible heuristics • max(h1(n),h2(n)) • α*h1(n) + β*h2(n) where α+β=1
  • 16. Monotone heuristic repair Suppose a heuristic h is admissible but not consistent, i.e. h(n) > c(n,n’)+h(n’), which means f(n) > f(n’) (f is not monotone) In that case, f’(n’) can be set to f(n) as a better heuristic, (higher but still underestimate), i.e. use h’(n’) = max(h(n’),h(n)-c(n,n’))
  • 17. An example of a heuristics Consider a knight (”horse”) on a chess board. It can move 2 squares in one direction and 1 to either side. The task is to get from one square to another in fewest possible steps (e.g. A1 to H8). A proposed heuristics could be ManHattanDistance/2 Is it admissible ? Is it monotone ? (Actually, it is not straightforward to find an heuristics that is both admissible and not monotone) 8 | | | | | | | |*| 7 | | | | | | | | | 6 | | | | | | | | | 5 | | | | | | | | | 4 | | | | | | | | | 3 | | | | | | | | | 2 | | | | | | | | | 1 |*| | | | | | | | A B C D E F G H
  • 18. Relaxed problems Many heuristics can be found by using a relaxed (easier, simpler) model of the problem. By definition, heuristics derived from relaxed models are underestimates of the cost of the original problem For example, straight line distance presumes that we can move in straight lines. For the 8-puzzle, the heuristics W(n) = # misplaced tiles would be exact if we could move tiles freely The less relaxed, (and therefore better) heuristic P(n) = distance from home ( Manhattan distance) would allow tiles to be moved to an adjacent square even though there may already be a tile there.
  • 19. Generalized A* f(n) = *g(n) + *h(n) = =1 A* =0 Uniform cost =0 Greedy search < 0,=0 Depth first > Conservative (still admissible) < Radical (not admissible) , depending on g,h Dynamic
  • 20. Learning heuristics from experience Where do heuristics come from ? Heuristics can be learned as a computed (linear?) combination of features of the state. Example: 8-puzzle Features: x1(n) : number of misplaced tiles x2(n) : number of adjacent tiles that are also adjacent in the goal state Procedure: make a run of searches from 100 random start states. Let h(ni) be the found minimal cost. n1 h(n1) x1(n1) x2(n1) … …… …….. ………. n100 h(n100) x1(n100) x2(n100) From these, use regression to estimate h(n) = c1*x1(n) + c2*x2(n)
  • 21. Learning heuristics from experience (II) Suppose the problem is harder than the heuristic (h1) indicates but that the hardness is assumed to be uniform over the state space. Then , it is an estimate to let an improved heuristics h2(x) = *h1(x). |S| | | | | | | | Problem: move a piece from S to G using ChessKing | | | | | | | | | heuristics h1(x) = # horisontal/vertical/diagonal moves. | | | | | | | | | h1(S)=7 h1(n) = 4 | | | |n| | | | | | | | | | | | | | Assume problem is actual harder (in effect Manhattan disance h2(x), but we dont’ know that). It means | | | | | | | | | g(n) = 6 | | | | | | | | | We then estimate = g(n)/(h1(s)-h1(n)) | | | | | | | | G| h2(n) = g(n)/(h1(s)-h1(n)) * h1(n) = 6/(7 – 4) *4 = 8 (correct)
  • 22. Learning heuristics from experience (III) Suppose the problem is easier than the heuristic (h1) indicates but that the easiness is assumed to be uniform over the state space. Then , it is an estimate to let an improved heuristics h2(x) = *h1(x). |S| | | | | | | | Problem: move a piece from S to G using Manhattan | | | | | | | | | heuristics h1(x) = # horisontal/vertical moves | | | | | | | | | h1(S)=14 h1(n) = 8 | | | |n| | | | | | | | | | | | | | Assume problem is actual easier (in effect Chess King disance h2(x), but we dont’ know that). It means | | | | | | | | | g(n) = 3 | | | | | | | | | We then estimate = g(n)/(h1(s)-h1(n)) | | | | | | | | G| h2(n) = g(n)/(h1(s)-h1(n)) * h1(n) = 3/(14 – 8) *8 = 4 (correct)
  • 23. Practical example (Bus world scenario) Find an optimal route from one place to another by public transport Nodes: Bus passing events A bus route passes a station at a time Actions: - enter bus - leave bus - wait
  • 24. Bus scenario search space Search space space(2) X time(1) Time Bus 3 wait Space Bus 5 Space
  • 25. Heuristics for bus route planner which route is best ? T3 = Z N # bus transfers K3 A wait time 1. departure Z wait time before arrival T2 T sum transfer waiting time K2 K sum driving time Equivalent transfer T1 K1 T0 = A
  • 26. Planner discussion 1. (T1+T2) = T critical if rain 2. If Z is to be minimised, must search backwards 3. Many equivalent transfers (same T and K) 4. In practice, A* is problematic 5. Waiting time A maybe unimportant Solution: Relaxation a) Find trasees independent of time b) Eliminate equivalent transfers c) For each trasee, find best route plan d) Keep the best of these solutions