Prohledávání do hloubky (DFS) rekurzivně

Similar documents
Homework Assignment #1

Hilbert-Huang Transform, its features and application to the audio signal Ing.Michal Verner

Transactions of the VŠB Technical University of Ostrava, Mechanical Series No. 2, 2009, vol. LV, article No. 1692

Czech Technical University in Prague Faculty of Electrical Engineering BACHELOR THESIS. Cooperative Collision Avoidance of Road Vehicles

CSI33 Data Structures

CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2012 Thorsten Joachims. Lecture 17: Heaps and Priority Queues

CSS 343 Data Structures, Algorithms, and Discrete Math II. Balanced Search Trees. Yusuf Pisan

Prednáška. Vypracoval: Ing. Martin Juriga, PhD. Bratislava, marec 2016

METHOD OF SEGMENTED WAVELET TRANSFORM FOR REAL-TIME SIGNAL PROCESSING

Search then involves moving from state-to-state in the problem space to find a goal (or to terminate without finding a goal).

Specification Paint; plastic parts

Experimental Comparison of Uninformed and Heuristic AI Algorithms for N Puzzle Solution

Verification of applicability of ABB robots for trans-planting seedlings in greenhouses

FS-C8100DN Clearing Paper Jams

THE USE OF CCD IMAGE LINE SENSORS IN VIDEO AND COMPUTER SYSTEMS. Luděk Bartoněk 1,JiříKeprt 2

Link State Routing. Brad Karp UCL Computer Science. CS 3035/GZ01 3 rd December 2013

CS188: Section Handout 1, Uninformed Search SOLUTIONS

4.4 Shortest Paths in a Graph Revisited

SECTION 1 1:1 REAR SEAT KIT GUARDIAN SEAT INSTALLATION

Testování a vývoj taktilních senzorů Testing and Development Tactile Sensors

1. Compare between monotonic and commutative production system. 2. What is uninformed (or blind) search and how does it differ from informed (or

Heuristics & Pattern Databases for Search Dan Weld

Section Table of Contents: Section 11.0

Thursday 5 June 2014 Afternoon

WO 2008/ A3 PCT. (19) World Intellectual Property Organization International Bureau

Massachusetts Institute of Technology 15.S50 Poker Theory and Analytics IAP Case 2

MITOCW watch?v=ir6fuycni5a

Using a Stack. Data Structures and Other Objects Using C++

Zpracoval: Petr Žabka Pracoviště: Katedra textilních a jednoúčelových strojů TUL

Transactions of the VŠB Technical University of Ostrava, Mechanical Series. article No. 1999

making them (robots:) intelligent

GETM0700G0EDH6GLYN01 = chemically strengthened, anti-glare, black print

the question of whether computers can think is like the question of whether submarines can swim -- Dijkstra

If you counted by 10 s starting at 43, what would be the first number you say that is greater than 75? Explain your thinking.

Transactions of the VŠB Technical University of Ostrava, Mechanical Series No. 2, 2009, vol. LV, article No Petr DOLEŽEL *, Jan MAREŠ **

HOUSEHOLD/DESKSIDE SHREDDERS

SCIENTIFIC PAPERS OF THE UNIVERSITY OF PARDUBICE UWB RADAR MULTIPATH PROPAGATION EFFECTS

If a pawn is still on its original square, it can move two squares or one square ahead. Pawn Movement

(Allow about 5 secs. Notice what expression the client outwardly gives to refer to it with the client)

Using a Stack. The N-Queens Problem. The N-Queens Problem. The N-Queens Problem. The N-Queens Problem. The N-Queens Problem

UNIVERSITY of PENNSYLVANIA CIS 391/521: Fundamentals of AI Midterm 1, Spring 2010

Artificial Intelligence Uninformed search

Charles University in Prague. Faculty of Mathematics and Physics BACHELOR THESIS. Tomáš Hromada

Programming Stack. Virendra Singh Indian Institute of Science Bangalore Lecture 7. Courtesy: Prof. Sartaj Sahni. Aug 25,2010

AASHTOWare Bridge Rating Training. T6 Truss Cross Sections and Graphics (BrR 6.4)

Collision Avoidance on General Road Network. David Kubeša

Amplifier design for Sigma-Delta modulator

Key things for parents to be aware of

Andrew Hamlin UNIVERSITY LINCOLN. Vice President of Student and Administrative Services

MITOCW watch?v=otkq4osg_yc

We would love to hear from you and post your wonderful creations on our Facebook page to share with others.

Solving Problems by Searching

Machine Translation - Decoding

Using yaposh for CTF team behaviour

Subway simulator Case study

DF-Series Pneumatic Couplings

the question of whether computers can think is like the question of whether submarines can swim -- Dijkstra

The Smart Choice In Dental Supplies CHRISTMAS SPECIALS

Forge War. Game Overview. Components

Thursday 6 June 2013 Afternoon

Informed Search. Read AIMA Some materials will not be covered in lecture, but will be on the midterm.

Lower ground floor information

Transistors, so far. I c = βi b. e b c. Rules 1. Vc>Ve 2. b-e and b-e circuits ~ diodes 3. max values of Ic, Ib, Vce 4. if rules are obeyed,

NIKON D40 MANUAL LENS

Phase Shifter Based on Varactor-Loaded Transmission Line


RICOH Ri 3000/Ri 6000

Montgomery Village Arduino Meetup Dec 10, 2016

The exam is closed book, closed calculator, and closed notes except your one-page crib sheet.

Equipment for the basic dice game

Push-to-talk ios User Guide (v8.0)

Link State Routing. Stefano Vissicchio UCL Computer Science CS 3035/GZ01

Lead Free. G : Green 50 : 5.0V. 13 Tape and Reel Package Packaging Part Number

Contents. Basic Concepts. Histogram of CPU-burst Times. Diagram of Process State CHAPTER 5 CPU SCHEDULING. Alternating Sequence of CPU And I/O Bursts

Quilted Spider Web Trick-or-Treat Drawstring

K REGULÁTOR A MINIPROGRAMÁTOR NÁVOD K OBLUZE. 1. ROZMĚRY (mm) 2. SCHEMA PŘIPOJENÍ K 38/39

Digital industrial radiography methodic of dimension measurement, accuracy of reached results and their relation to acceptance criterion

Multiple Predictors: BTB + Branch Direction Predictors

TPH3202PS TPH3202PS. GaN Power Low-loss Switch PRODUCT SUMMARY (TYPICAL) TO-220 Package. Absolute Maximum Ratings (T C =25 C unless otherwise stated)

Řízení otáček elektrického motoru napájeného solární energií Controlling speed of motor powered by solar energy

Basics of Routing and Link-State Routing

Charles University in Prague. Faculty of Mathematics and Physics BACHELOR THESIS. Matouš Kozma. Multi-agent pathfinding with air transports

Lower Conduction Losses

Impact of the system parameters on the ferroresonant modes

Aims of the class (ciljevi časa)

V DSS R DS(on) max Qg 30V GS = 10V 20nC

FTI DVD+R DL September, 2010 Falcon DVD+R DL media has quickly become a favorite among our clients needing dual layer DVD media.

arxiv: v1 [math.co] 7 Aug 2012

Graphs and Network Flows IE411. Lecture 14. Dr. Ted Ralphs

Algorithms for Memory Hierarchies Lecture 14

WCCI , Section G) Fairies. Julia Vysotska. P.A.Petkov 75 JT, StrateGems st Prize. hs#2.5 2 solutions 8+8 Anti-Andernach Eiffel Chess

Basic SHOGI Rules. By Djuro Emedji. The author of Shogi program GShogi available at

Problem Set 10 Solutions

CZECH TECHNICAL UNIVERSITY IN PRAGUE FACULTY OF ELECTRICAL ENGINEERING Department of Cybernetics

BUILDING INSTRUCTION ERWIN XL. Erwin XL building Instruction September

Once you get a solution draw it below, showing which three pennies you moved and where you moved them to. My Solution:

DIPLOMOVÁ PRÁCE. České vysoké učení technické. Fakulta elektrotechnická

Chess Puzzle Mate in N-Moves Solver with Branch and Bound Algorithm

EECS 427 Lecture 13: Leakage Power Reduction Readings: 6.4.2, CBF Ch.3. EECS 427 F09 Lecture Reminders

MATHCOUNTS. 100 Classroom Lessons. August Prepared by

Transcription:

Prohledávání do hloubky (DFS) rekurzivně 1 function dfs(g, v) 2 mark v as visited 3 previsit(v) 4 for (v, w) E(G) do 5 edgevisit(v, w) 6 if w not visited then 7 dfs(g, w) 8 postvisit(v)

Prohledávání do šířky (BFS) 1 function bfs(g, v) 2 Q empty queue 3 mark v as visited 4 enqueue(q, v) 5 while Q not empty do 6 v dequeue(q) 7 vertexvisit(v) 8 for (v, w) E(G) do 9 edgevisit(v, w) 10 if w not visited then 11 mark w as visited 12 enqueue(q, w)

Prohledávání do šířky (BFS) 1 function bfs(g, v) 2 Q empty queue 3 mark v as visited 4 enqueue(q, v) 5 while Q not empty do 6 v dequeue(q) 7 vertexvisit(v) 8 for (v, w) E(G) do 9 edgevisit(v, w) 10 if w not visited then 11 mark w as visited 12 enqueue(q, w) Co se stane když vyměníme frontu za zásobník?

Tzv. obecné schéma prohledávání grafu 1 function search(g, v) 2 B empty bag 3 put(b, v) 4 while B not empty do 5 v get(b) 6 if v not visited then 7 mark v as visited 8 vertexvisit(v) 9 for (v, w) E(G) do 10 edgevisit(v, w) 11 put(b, w) Je toto tvrzení pravdivé? Pokud je bag fronta, je toto schéma BFS, pokud je bag zásobník, je toto schéma DFS.

Prohledávání do hloubky (DFS) iterativně Chceme skutečné iterativní DFS musí mít všechny vlastnosti DFS, tj. zejména postorder potřebujeme simulovat rekurzi pomocí zásobníku co všechno je na zásobníku rekurze?

Prohledávání do hloubky (DFS) iterativně Chceme skutečné iterativní DFS musí mít všechny vlastnosti DFS, tj. zejména postorder potřebujeme simulovat rekurzi pomocí zásobníku co všechno je na zásobníku rekurze? Varianta 1: indexy následníků (iterátory) s každým prvkem v zásobníku si pamatujeme index ten určuje, které následníky ještě musíme zpracovat použitelnost závisí na reprezentaci grafu index může být obecnější iterátor použitelné pro explicitní grafy (matice sousednosti, seznam následníků) i pro některé implicitní grafy

Prohledávání do hloubky (DFS) iterativně Chceme skutečné iterativní DFS musí mít všechny vlastnosti DFS, tj. zejména postorder potřebujeme simulovat rekurzi pomocí zásobníku co všechno je na zásobníku rekurze? Varianta 1: indexy následníků (iterátory) s každým prvkem v zásobníku si pamatujeme index ten určuje, které následníky ještě musíme zpracovat použitelnost závisí na reprezentaci grafu index může být obecnější iterátor použitelné pro explicitní grafy (matice sousednosti, seznam následníků) i pro některé implicitní grafy Varianta 2: bez iterátorů u některých implicitních grafů nejsme schopni rozumně iterovat přes následníky vygenerujeme všechny následníky a uložíme je na zásobník dva typy prvků na zásobníku (vrcholy a hrany)

Prohledávání do hloubky (DFS) iterativně 1 function dfs(g, v) 2 S empty stack 3 mark v as visited 4 previsit(v) 5 push(s, (v, 1)) 6 while S not empty do 7 (v, k) pop(s) 8 if k number of v s successors in G then 9 push(s, (v, k + 1)) 10 w kth successor of v in G 11 edgevisit(v, w) 12 if w not visited then 13 mark w as visited 14 previsit(w) 15 push(s, (w, 1)) 16 else 17 postvisit(v)

Prohledávání do hloubky (DFS) iterativně (bez iterátorů) 1 function dfs(g, v) 2 S empty stack 3 expand(g, S, v) 4 while S not empty do 5 top pop(s) 6 if top is an edge (v, w) then 7 edgevisit(v, w) 8 if w not visited then expand(g, S, w) 9 else 10 postvisit(top) 11 function expand(g, S, v) 12 mark v as visited 13 previsit(v) 14 push(s, v) 15 for (v, w) E(G) do 16 push(s, (v, w))

Hledání nejkratších cest Dijkstrův algoritmus 1 function dijkstra(g, s) 2 P empty priority queue 3 d[s] 0 4 for v V (G) do 5 if v s then d[v] 6 insert(p, (v, d[v])); 7 while P not empty do 8 v extractmin(p) 9 mark v as closed 10 for (v, w) E(G) do 11 if w not closed and d[v] + δ(v, w) < d[w] then 12 d[w] d[v] + δ(v, w) 13 decreasekey(p, w, d[w])

Hledání nejkratších cest Dijkstrův algoritmus 1 function dijkstra(g, s) 2 P empty priority queue 3 d[s] 0 4 insert(p, (s, 0)) 5 while P not empty do 6 v extractmin(p) 7 mark v as closed 8 for (v, w) E(G) do 9 if w not closed and d[v] + δ(v, w) < d[w] then 10 d[w] d[v] + δ(v, w) 11 if w is in P then 12 decreasekey(p, w, d[w]) 13 else 14 insert(p, (w, d[w])) Vkládáme do prioritní fronty vrcholy až za běhu.

Hledání nejkratších cest Dijkstrův algoritmus (modifikovaný) 1 function dijkstra(g, s) 2 P empty priority queue 3 d[s] 0 4 insert(p, (s, 0)) 5 while P not empty do 6 v extractmin(p) 7 for (v, w) E(G) do 8 if d[v] + δ(v, w) < d[w] then 9 d[w] d[v] + δ(v, w) 10 if w is in P then 11 decreasekey(p, w, d[w]) 12 else 13 insert(p, (w, d[w])) Je tento algoritmus korektní? Jakou má časovou složitost?

Hledání nejkratších cest A* Motivace často chceme hledat pouze cestu ze startu do cíle preferujeme cesty, které vypadají, že vedou směrem k cíli Heuristika pro každý vrchol máme hodnotu h(v), která je odhadem vzdálenosti k cíli přípustná: h(v) nesmí být větší než skutečná vzdálenost k cíli konzistentní: pro každé v, w platí: h(v) δ(v, w) + h(w) K zamyšlení: Je každá konzistentní heuristika přípustná? Je každá přípustná heuristika konzistentní? Algoritmus A* varianta Dijkstrova algoritmu: místo d[v] je kĺıčem d[v] + h(v)

Hledání nejkratších cest A* 1 function astar(g, s, t) 2 P empty priority queue 3 d[s] 0 4 insert(p, (s, 0 + h(s))) 5 while P not empty do 6 v extractmin(p) 7 if v = t then stop 8 for (v, w) E(G) do 9 if d[v] + δ(v, w) < d[w] then 10 d[w] d[v] + δ(v, w) 11 if w is in P then 12 decreasekey(p, w, d[w] + h(w)) 13 else 14 insert(p, (w, d[w] + h(w))) Kterou podmínku musíme na heuristiku klást, aby byl algoritmus korektní? Jakou má složitost?

Hledání nejkratších cest Zajímavé odkazy http://theory.stanford.edu/~amitp/gameprogramming/ http://www.redblobgames.com/pathfinding/a-star/ introduction.html http://zerowidth.com/2013/05/05/ jump-point-search-explained.html (poslední odkaz vysvětluje algoritmus Jump Point Search, heuristiku pro vylepšení algoritmu A*)