Artificial Intelligence for Games Informed Search (2) Patrick Olivier [email protected].

23
Artificial Intelligence for Games Informed Search (2) Patrick Olivier [email protected]

Transcript of Artificial Intelligence for Games Informed Search (2) Patrick Olivier [email protected].

Page 1: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

Artificial Intelligence for Games

Informed Search (2)

Patrick Olivier

[email protected]

Page 2: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

Heuristic functions

• sample heuristics for 8-puzzle:– h1(n) = number of misplaced tiles

– h2(n) = total Manhattan distance

• h1(S) = ?

• h2(S) = ?

Page 3: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

Heuristic functions

• sample heuristics for 8-puzzle:– h1(n) = number of misplaced tiles– h2(n) = total Manhattan distance

• h1(S) = 8• h2(S) = 3+1+2+2+2+3+3+2 = 18• dominance:

– h2(n) ≥ h1(n) for all n (both admissible)– h2 is better for search (closer to perfect)– less nodes need to be expanded

Page 4: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

Example of dominance• randomly generate 8-puzzle problems

• 100 examples for each solution depth

• contrast behaviour of heuristics & strategies

d 2 4 6 8 10 12 14 16 18 20 22 24

IDS 10 112 680 6384 47127 … … … … … … …

A*(h1) 6 13 20 39 93 227 539 1301 3056 7276 18094 39135

A*(h2) 6 12 18 25 39 73 113 211 363 676 1219 1641

Page 5: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

A* enhancements & local search

• Memory enhancements– IDA*: Iterative-Deepening A*– SMA*: Simplified Memory-Bounded A*

• Other enhancements (next lecture)– Dynamic weighting– LRTA*: Learning Real-time A*– MTS: Moving target search

• Local search (next lecture)– Hill climbing & beam search– Simulated annealing & genetic algorithms

Page 6: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

Improving A* performance

• Improving the heuristic function– not always easy for path planning tasks

• Implementation of A* – key aspect for large search spaces

• Relaxing the admissibility condition– trading optimality for speed

Page 7: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

IDA*: iterative deepening A*

• reduces the memory constraints of A* without sacrificing optimality

• cost-bound iterative depth-first search with linear memory requirements

• expands all nodes within a cost contour• store f-cost (cost-limit) for next iteration• repeat for next highest f-cost

Page 8: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

• Order of expansion:– Move space up– Move space down– Move space left– Move space right

• Evaluation function:– g(n) = number of moves– h(n) = misplaced tiles

• Expand the state space to a depth of 3 and calculate the evaluation function

IDA*: exercise

Start state1 2 3

6 X 4

8 7 5

Goal state1 2 3

8 X 4

7 6 5

Page 9: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

Next f-cost = 5

1 3

6 2 4

8 7 5

1+4=5 1 2 3

6 7 4

8 5

1+3=4 1 2 3

6 4 4

8 7 5

1+4=61+3=41 2 3

X 6 4

8 7 5

0+3=31 2 3

6 X 4

8 7 5

IDA*: f-cost = 3Next f-cost = 3Next f-cost = 4

Page 10: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

IDA*: f-cost = 4

1 2 3

8 6 4

7 5

2+2=41 2 3

6 4

8 7 5

2+3=5

1 3

6 2 4

8 7 5

1+4=5 1 2 3

6 7 4

8 7 5

1+3=4

0+3=31 2 3

6 X 4

8 7 5

Next f-cost = 4Next f-cost = 5

1 2 3

8 6 4

7 5

3+3=6 1 2 3

8 6 4

7 5

3+1=4

1 2 3

8 4

7 6 5

4+0=4

Page 11: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

Simplified memory-bounded A*• SMA*

– When we run out of memory drop costly nodes– Back their cost up to parent (may need them later)

• Properties– Utilises whatever memory is available– Avoids repeated states (as memory allows)– Complete (if enough memory to store path)– Optimal (or optimal in memory limit)– Optimally efficient (with memory caveats)

Page 12: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

Simple memory-bounded A*

Page 13: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

Class exercise

• Use the state space given in the example

• Execute the SMA* algorithm over this state space

• Be sure that you understand the algorithm!

Page 14: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

Simple memory-bounded A*

Page 15: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

Simple memory-bounded A*

Page 16: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

Simple memory-bounded A*

Page 17: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

Simple memory-bounded A*

Page 18: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

Simple memory-bounded A*

Page 19: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

Simple memory-bounded A*

Page 20: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

Simple memory-bounded A*

Page 21: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

Simple memory-bounded A*

Page 22: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

Trading optimality for speed…

• The admissibility condition guarantees that an optimal path is found

• In path planning a near-optimal path can be satisfactory

• Try to minimise search instead of minimising cost: – i.e. find a near-optimal path (quickly)

Page 23: Artificial Intelligence for Games Informed Search (2) Patrick Olivier p.l.olivier@ncl.ac.uk.

Weighting…

fw(n) = (1 - w).g(n) + w.h(n)– w = 0.0 (breadth-first)– w = 0.5 (A*)– w = 1.0 (best-first, with f = h)

• trading optimality for speed• weight towards h when confident in the

estimate of h