Neuron 101

Solving by search / Uniform cost search

Türkçe

Plate16

Unit 2 · Topic 5 of 10

Uniform cost search

Medium, 7 min, 9 steps

S
Keyboard: left and right arrows change the step, space plays and pauses.

Step 1 of 9 Maze

The maze

S is the start and the flag is the goal. Black blocks are walls, brown cells are mud: entering mud costs 3, entering a plain cell costs 1.

Tap a part of the scene to see its details here.

Open in Colab
  1. import heapq
  2. def ucs(harita, S, G):
  3. kuyruk = [(0, S)]
  4. g = {S: 0}
  5. while kuyruk:
  6. gx, x = heapq.heappop(kuyruk)
  7. if x == G:
  8. return gx
  9. for k in komsular(harita, x):
  10. yg = gx + maliyet(k)
  11. if yg < g.get(k, 1e9):
  12. g[k] = yg
  13. heapq.heappush(
  14. kuyruk, (yg, k))
acilan
0
sinir
1
yolUzunlugu
0
maliyet
0