63
Heuristic Optimisation Part 6: A* search andor Zolt ´ an N ´ emeth http://web.mat.bham.ac.uk/S.Z.Nemeth [email protected] University of Birmingham SZN´ emeth ([email protected]) Heuristic Optimisation University of Birmingham 1 / 17

Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Heuristic Optimisation

Part 6: A* search

Sandor Zoltan Nemeth

http://web.mat.bham.ac.uk/S.Z.Nemeth

[email protected]

University of Birmingham

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 1 / 17

Page 2: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Overview

Best-first search

Minimizing the total cost ⇒ A*

Two examples of A*

The algorithm of A*

Observations

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 2 / 17

Page 3: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Best-first search

We follow only one path at a time, but when a competing pathlooks more promising, we switch to that path.

We apply a heuristic function to each of the generated nodes.

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 3 / 17

Page 4: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Best-first vs hill climbing

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 4 / 17

Page 5: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Best-first vs hill climbing

(5,2)(4,1)

(5,1) 7

6 6

Hill climbing

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 4 / 17

Page 6: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Best-first vs hill climbing

(5,2)

(5,1) 7

6

Hill climbing

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 4 / 17

Page 7: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Best-first vs hill climbing

(4,2)

(5,2)

(5,1) 7

6

5

Hill climbing

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 4 / 17

Page 8: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Best-first vs hill climbing

(4,3)(4,1)

(4,2)

(5,2)

(5,1) 7

6

5

6 4

Hill climbing

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 4 / 17

Page 9: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Best-first vs hill climbing

(4,3)

(4,2)

(5,2)

(5,1) 7

6

5

4

Hill climbing

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 4 / 17

Page 10: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Best-first vs hill climbing

(4,4)(3,3)

(4,3)

(4,2)

(5,2)

(5,1) 7

6

5

4

3 3

Hill climbing

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 4 / 17

Page 11: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Best-first vs hill climbing

(4,4)

(4,3)

(4,2)

(5,2)

(5,1) 7

6

5

4

3

Hill climbing

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 4 / 17

Page 12: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Best-first vs hill climbing

(4,4)

(4,3)

(4,2)

(5,2)

(5,1) 7

6

5

4

3

(5,4)(3,4)2 4

Hill climbing

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 4 / 17

Page 13: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Best-first vs hill climbing

(4,4)

(4,3)

(4,2)

(5,2)

(5,1) 7

6

5

4

3

(3,4)2

Hill climbing

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 4 / 17

Page 14: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Best-first vs hill climbing

(4,4)

(4,3)

(4,2)

(5,2)

(5,1) 7

6

5

4

3

(3,4)2

Hill climbing

(4,4)(3,3)

(4,3)(4,1)

(4,2)

(5,2)(4,1)

(5,1) 7

6 6

5

6 4

3 3

(5,4)(3,4)2 4

Greedy

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 4 / 17

Page 15: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Best-first vs hill climbing

(4,4)

(4,3)

(4,2)

(5,2)

(5,1) 7

6

5

4

3

(3,4)2

Hill climbing

(4,4)(3,3)

(4,3)(4,1)

(4,2)

(5,2)(4,1)

(5,1) 7

6 6

5

6 4

3 3

(3,5)

(5,4)(3,4)

(3,3)

2 4

3 3

Greedy

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 4 / 17

Page 16: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Best-first vs hill climbing

(4,4)

(4,3)

(4,2)

(5,2)

(5,1) 7

6

5

4

3

(3,4)2

Hill climbing

(4,4)(3,3)

(4,3)(4,1)

(4,2)

(5,2)(4,1)

(5,1) 7

6 6

5

6 4

3 3

(1,4)

(1,5)

(2,5)

(3,5)

(5,4)(3,4)

(3,3)

2 4

3 3

2

1

Greedy

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 4 / 17

Page 17: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

The underlying heuristic function

f(n) = g(n) + h(n)

g(n) is a measure of the cost of getting from the initial state to thecurrent state n.

h(n) is an estimate of the cost of getting from the current state n tothe goal state.

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 5 / 17

Page 18: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

The underlying heuristic function

f(n) = g(n) + h(n)

g(n) is a measure of the cost of getting from the initial state to thecurrent state n.

h(n) is an estimate of the cost of getting from the current state n tothe goal state.

What is a good value of h?(large or low?)

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 5 / 17

Page 19: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1

Underground routes in London (fragment of the map)

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

The estimated distances from Monument (h):

P BaS WaS NHG BoS OC TCR GP V We E M

7 5 4 7 5 5 3 5 5 4 3 0

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 6 / 17

Page 20: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1 – A* solution

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

P

CLOSED=[]

f(P)=0+7=7

OPEN=[P]

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 7 / 17

Page 21: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1 – A* solution

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

2 3

NHG

P

BaS

f(NHG)=2+7=9 f(BaS)=3+5=8

OPEN=[BaS,NHG]

CLOSED=[P]

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 7 / 17

Page 22: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1 – A* solution

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

2 3

NHG

P

BaS

f(NHG)=2+7=9 f(BaS)=3+5=8

OPEN=[BaS,NHG]

CLOSED=[P]

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 7 / 17

Page 23: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1 – A* solution

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

2 3

12

2

NHG

P

BaS

OCBoS WaS

f(NHG)=9

OPEN=[NHG, BoS,WaS,OC]

CLOSED=[P,BaS]

f(BoS)=4+5=9 f(OC)=5+5=10 f(WaS)=5+4=9

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 7 / 17

Page 24: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1 – A* solution

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

2 3

12

2

NHG

P

BaS

OCBoS WaS

f(NHG)=9

OPEN=[NHG, BoS,WaS,OC]

CLOSED=[P,BaS]

f(BoS)=4+5=9 f(OC)=5+5=10 f(WaS)=5+4=9

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 7 / 17

Page 25: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1 – A* solution

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

2

5

3

12

2

V

NHG

P

BaS

OCBoS WaS

f(BoS)=9 f(OC)=10 f(WaS)=9

f(V)=7+5=12 g’(BoS)=6>4=g(BoS)

4

OPEN=[BoS,WaS,OC,V]

CLOSED=[P,BaS,NHG]

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 7 / 17

Page 26: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1 – A* solution

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

2

5

3

12

2

V

NHG

P

BaS

OCBoS WaS

f(BoS)=9 f(OC)=10 f(WaS)=9

f(V)=7+5=12

OPEN=[BoS,WaS,OC,V]

CLOSED=[P,BaS,NHG]

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 7 / 17

Page 27: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1 – A* solution

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

2

5

3

12

2

V

NHG

P

BaS

OCBoS

f(V)=12

WaS

f(OC)=10 f(WaS)=9f(BoS)=9

OPEN=[BoS,WaS,OC,V]

CLOSED=[P,BaS,NHG]

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 7 / 17

Page 28: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1 – A* solution

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 7 / 17

Page 29: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1 – A* solution

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

2

5

3

12

2

1V

NHG

P

BaS

OC

GP

BoS

f(V)=12

WaS

f(GP)=5+5=10

f(OC)=10 f(WaS)=9

OPEN=[WaS,OC,GP,V]

CLOSED=[P,BaS,NHG,BoS]

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 7 / 17

Page 30: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1 – A* solution

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

2

5

3

12

2

1V

NHG

P

BaS

GP

BoS

f(GP)=10

f(V)=12

WaSOCf(WaS)=9f(OC)=10

CLOSED=[P,BaS,NHG,BoS]

OPEN=[WaS,OC,GP,V]

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 7 / 17

Page 31: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1 – A* solution

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

2

5

3

12

2

1V

NHG

P

BaS

TCRGP

BoS

f(GP)=10

f(V)=12

WaS

f(TCR)=7+3=10

2

1OC

g’(OC)=6>5=g(OC)f(OC)=10

OPEN=[OC,GP,TCR,V]

CLOSED=[P,BaS,NHG,BoS,WaS]

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 7 / 17

Page 32: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1 – A* solution

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

2

5

3

12

2

1V

NHG

P

BaS

TCRGP

BoS

f(GP)=10

f(V)=12

WaS

f(TCR)=7+3=10

2

OCf(OC)=10

OPEN=[OC,GP,TCR,V]

CLOSED=[P,BaS,NHG,BoS,WaS]

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 7 / 17

Page 33: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1 – A* solution

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

2

5

3

12

2

1V

NHG

P

BaS

TCRGP

BoS

f(GP)=10

f(V)=12

WaS

f(TCR)=7+3=10

2

OCf(OC)=10

OPEN=[OC,GP,TCR,V]

CLOSED=[P,BaS,NHG,BoS,WaS]

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 7 / 17

Page 34: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1 – A* solution

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

2

5

3

12

2

1 3V

NHG

P

BaS

TCR

EGP

BoS

f(V)=12

WaS

f(E)=8+3=11 g’(TCR)=6<7=g(TCR)f(TCR)=10

211

g’(GP)=6>5=g(GP)f(GP)=10

OPEN=[TCR,GP,V,E]

CLOSED=[P,BaS,NHG,BoS,WaS,OC]

OC1 1

g’(BoS)=6>4=g(BoS) g’(WaS)=6>5=g(WaS)

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 7 / 17

Page 35: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1 – A* solution

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

2

5

3

12

2

1 3V

NHG

P

BaS

OC

TCR

EGP

BoS

f(V)=12

WaS

f(E)=8+3=11f(GP)=10

OPEN=[TCR,GP,V,E]

CLOSED=[P,BaS,NHG,BoS,WaS,OC]

1

f(TCR)=6+3=9

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 7 / 17

Page 36: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1 – A* solution

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

2

5

3

12

2

1 3V

NHG

P

BaS

OC

TCR

EGP

BoS

f(V)=12

WaS

f(E)=8+3=11f(GP)=10

OPEN=[TCR,GP,V,E]

CLOSED=[P,BaS,NHG,BoS,WaS,OC]

1

f(TCR)=6+3=9

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 7 / 17

Page 37: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1 – A* solution

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

2

5

3

12

2

1 3 1V

NHG

P

BaS

OC

TCR

M

EGP

BoS

f(GP)=10

f(V)=12

f(E)=11

f(M)=10

WaS

3

g’(E)=9>8=g(E)

OPEN=[M,GP,V,E]

CLOSED=[P,BaS,NHG,BoS,WaS,OC,TCR]

4

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 7 / 17

Page 38: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1 – A* solution

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

2

5

3

12

2

1 3 1V

NHG

P

BaS

OC

TCR

M

EGP

BoS

f(GP)=10

f(V)=12

f(E)=11

f(M)=10

WaS

OPEN=[M,GP,V,E]

CLOSED=[P,BaS,NHG,BoS,WaS,OC,TCR]

4

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 7 / 17

Page 39: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 1 – A* solution

Paddington

Notting HillGate

Victoria Westminster Embankment

OxfordCircusGreen

Park

BondStreet

Baker Street Warren Street

TottenhamCourt Road

Monument

2

3

5

4

1

1

2

1

1

1

2

2

1

1

2

3

15

3

4

1

2

5

3

12

2

1 3 1V

NHG

P

BaS

OC

TCR

M

EGP

BoS

f(GP)=10

f(V)=12

f(E)=11

f(M)=10

WaS

4

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 7 / 17

Page 40: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 2

The 8-puzzle:

2 3 1 2 3

1 4 5 8 4

8 7 6 7 6 5

Start state Goal state

Possible estimated costs:

The number of tiles in wrong position:h(start) = 6

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 8 / 17

Page 41: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 2

The 8-puzzle:

2 3 1 2 3

1 4 5 8 4

8 7 6 7 6 5

Start state Goal state

Possible estimated costs:

The number of tiles in wrong position:h(start) = 6

The Manhattan distance:h(start) = 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 = 6

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 8 / 17

Page 42: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Example 2 – A* solution

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 9 / 17

Page 43: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Algorithm of A*

Let OPEN be the list of generated, but not yet examined nodes.

1. Start with OPEN containing the initial state.

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 10 / 17

Page 44: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Algorithm of A*

Let OPEN be the list of generated, but not yet examined nodes.

1. Start with OPEN containing the initial state.

2. Do until a goal state is found or no nodes are left in OPEN:

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 10 / 17

Page 45: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Algorithm of A*

Let OPEN be the list of generated, but not yet examined nodes.

1. Start with OPEN containing the initial state.

2. Do until a goal state is found or no nodes are left in OPEN:

(a) Take the best node(lowest f value) in OPEN and generate its

successors.

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 10 / 17

Page 46: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Algorithm of A*

Let OPEN be the list of generated, but not yet examined nodes.

1. Start with OPEN containing the initial state.

2. Do until a goal state is found or no nodes are left in OPEN:

(a) Take the best node(lowest f value) in OPEN and generate its

successors.

(b) For each successor do:

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 10 / 17

Page 47: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Algorithm of A*

Let OPEN be the list of generated, but not yet examined nodes.

1. Start with OPEN containing the initial state.

2. Do until a goal state is found or no nodes are left in OPEN:

(a) Take the best node(lowest f value) in OPEN and generate its

successors.

(b) For each successor do:

i. if it has not been generated before, evaluate it and add it to OPEN.

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 10 / 17

Page 48: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Algorithm of A*

Let OPEN be the list of generated, but not yet examined nodes.

1. Start with OPEN containing the initial state.

2. Do until a goal state is found or no nodes are left in OPEN:

(a) Take the best node(lowest f value) in OPEN and generate its

successors.

(b) For each successor do:

i. if it has not been generated before, evaluate it and add it to OPEN.

What does evaluation mean?

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 10 / 17

Page 49: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Algorithm of A*

Let OPEN be the list of generated, but not yet examined nodes.

1. Start with OPEN containing the initial state.

2. Do until a goal state is found or no nodes are left in OPEN:

(a) Take the best node(lowest f value) in OPEN and generate its

successors.

(b) For each successor do:

i. if it has not been generated before, evaluate it and add it to OPEN.

ii. otherwise change the parent, if this path is better and modify accordingly

the costs for the depending nodes.

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 10 / 17

Page 50: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Algorithm of A*

Let OPEN be the list of generated, but not yet examined nodes.

1. Start with OPEN containing the initial state.

2. Do until a goal state is found or no nodes are left in OPEN:

(a) Take the best node(lowest f value) in OPEN and generate its

successors.

(b) For each successor do:

i. if it has not been generated before, evaluate it and add it to OPEN.

ii. otherwise change the parent, if this path is better and modify accordingly

the costs for the depending nodes.

When is a path better then the other?

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 10 / 17

Page 51: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

How to perform step 2.(b)ii.

Let CLOSED be the list of generated and examined nodes.

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 11 / 17

Page 52: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

How to perform step 2.(b)ii.

Let CLOSED be the list of generated and examined nodes.

For a node that has a copy in the OPEN list we only have to modifythe parent and the g, f values.

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 11 / 17

Page 53: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

How to perform step 2.(b)ii.

Let CLOSED be the list of generated and examined nodes.

For a node that has a copy in the OPEN list we only have to modifythe parent and the g, f values.

A node that has a copy in the CLOSED list has already beenexamined.

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 11 / 17

Page 54: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

How to perform step 2.(b)ii. – 2

So, we need to modify the g values (and the f values, too) of thenodes below this node.

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 12 / 17

Page 55: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

How to perform step 2.(b)ii. – 2

So, we need to modify the g values (and the f values, too) of thenodes below this node.

We can do a depth-first traversal of the tree rooted at this node.

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 12 / 17

Page 56: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

How to perform step 2.(b)ii. – 2

So, we need to modify the g values (and the f values, too) of thenodes below this node.

We can do a depth-first traversal of the tree rooted at this node.

Each branch ends if there are no more successors or the present gvalue of a node is better.

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 12 / 17

Page 57: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Observations

f(n) is the shortest estimated path from the start state to the goalstate that passes through state n.

If the cost of each step is 1, A* will find the path consisting of thefewest number of steps.

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 13 / 17

Page 58: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Particular cases of A*

g = 0 ⇒ greedy best-first search

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 14 / 17

Page 59: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Particular cases of A*

g = 0 ⇒ greedy best-first search

h = 0 and g = 0 ⇒ random search

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 14 / 17

Page 60: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Properties of h

If h is a perfect estimator of the distance from the current nodeto the goal node, A* will never leave the optimal path.

The better h estimates the real distance, the closer A* is to the”direct” path.

If h never overestimates the real distance, A* is guaranteed tofind the optimal solution.

If h may overestimate the real distance, the optimal path can befound only if all paths in the search graph longer than theoptimal solution are expanded.

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 15 / 17

Page 61: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Search tree or search graph?

More general form ⇒ search graph

More simple form ⇒ search tree

Search trees generate nodes faster, BUT duplicate nodes.

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 16 / 17

Page 62: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Search tree or search graph?

More general form ⇒ search graph

More simple form ⇒ search tree

Search trees generate nodes faster, BUT duplicate nodes.

Is node duplication a problem?

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 16 / 17

Page 63: Heuristic Optimisation - University of Birminghamweb.mat.bham.ac.uk/S.Z.Nemeth/presentations_ho_part_06.pdf · 2016-01-29 · Best-first search We follow only one path at a time,

Recommended reading

S. Russell and P. Norvig: Artificial Intelligence, A Modern Approach

Section 4.1

E. Rich and K. Knight: Artificial Intelligence

Section 3.3

S Z Nemeth ([email protected]) Heuristic Optimisation University of Birmingham 17 / 17