Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov...

22
Algorithms, Exploration and Search Nov 6 th -Nov 10 th Matlab, python, C, Processing, etc… Turn on an LED, little dance, etc…

Transcript of Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov...

Page 1: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

Algorithms, Exploration and Search

• Nov 6th-Nov 10th

Matlab, python, C, Processing, etc…

Turn on an LED, little dance, etc…

Page 2: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

S

Algorithms and Search• Brute force search• Depth First Search (DFS)

1

2

3

4 5 6 7

8

9

10

111213

14

15

16 17

Find a treasureSearch order: N, E, S, W

Page 3: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

S

Find a treasureAlgorithms and Search

• Brute force search• Depth First Search (DFS)• Breadth First Search (BFS)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

Search order: N, E, S, W

Page 4: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

S

Find a treasureAlgorithms and Search

• Brute force search• Depth First Search (DFS)

y

x

(0,0)

(0,1) (1,0)

(0,2) (1,1)

(0,3) (1,2)

(0,4) (1,3)

and so on…

1

2

3

4

Page 5: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

S

Find a treasure

6

7

• Brute force search• Depth First Search (DFS)• Breadth First Search (BFS)

y

x

(0,0)(0,1) (1,0)

(0,2) (1,1) (2,0)

(0,3) (3,1)

and so on…

1

2

3

4

5

Algorithms and Search

Page 6: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

S

Find a treasure• Brute force search• Depth First Search (DFS)• Breadth First Search (BFS)• Common structure

• For every node, n• you have a set of actions, a• that moves you to a new node, n’

y

x

na1

a2

a3n’1

n’2

n’3

Algorithms and Search

Page 7: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

Sy

x

n = state(init)frontier.append(n)while(frontier not empty)

n = pull state from frontierif n = goal, return solutionfor all actions in n

n’ = a(n)if n’ not visited

append n’ to visitedappend n’ to frontier

visited

frontier

0,00,0

General Search Algorithm

X*YHow much space to allocate?

Page 8: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

0,0

visited

X*Y

frontier• Depth First Search (DFS)

Sy

x

n = state(init)frontier.append(n)while(frontier not empty)

n = pull state from frontierif n = goal, return solutionfor all actions in n

n’ = a(n)if n’ not visited

append n’ to visitedappend n’ to frontier

General Search Algorithm

0,0

Page 9: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

(0,0)

(0,1) (1,0)

(0,2) (1,1)

(0,3) (1,2)

(0,4) (1,3)

and so on…

Memory grows linearly with the depth of the graph

How much memory to allocate for the frontier buffer?

• Depth First Search (DFS)

General Search Algorithm

visited

X*Y

frontier

Sy

x

0,0

0,1

0,2

0,3

1,0

0,4

Type of Buffer?Last-In First-Out (LIFO) Buffer

1,1

1,2

1,3

Page 10: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

visited

0,0

frontier

General Search Algorithm• Depth First Search (DFS)• Breadth First Search (BFS)

Sy

x

n = state(init)frontier.append(n)while(frontier not empty)

n = pull state from frontierif n is goal, return solutionfor all actions in n

n’ = a(n)if n’ not visited

append n’ to visitedappend n’ to frontier

0,1

1,0

0,2

1,1

0,1

1,0

2,0

0,3 Type of Buffer?First-In First-Out (FIFO) Buffer

0,0

0,2

Page 11: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

• Depth First Search (DFS)• Breadth First Search (BFS)

Memory grows exponentially with the depth of the graph

General Search Algorithm

(0,0)(0,1) (1,0)

(0,2) (1,1) (2,0)

(0,3) (3,1)

How much memory to allocate for the frontier buffer?

visited

0,0

frontier

Sy

x

0,1

1,0

0,2

1,1

0,1

1,0

2,0

0,3 Type of Buffer?First-In First-Out (FIFO) Buffer

0,0

0,2

Page 12: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

Algorithms and Search• What is the most efficient way to explore the full maze?

• Hint: Your robot takes time to move!• Double hint: Your robot takes time to turn!

4 5 6 7

3 16 17 8

2 15 18 9

1 14 19 10

S 13 12 11DFS

13 14 18 19

6 12 15 17

3 7 11 16

1 4 8 10

S 2 5 9BFS

S

Page 13: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

S

Algorithms and Search• Can we be done already?...

• No! Your robot also has to get to the frontier.

S

4 5 6 7

3 16 17 8

2 15 18 9

1 14 19 10

S 13 12 11DFS

Page 14: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

Sequence of actions to get

there

Nomenclature:• Exploration: pick next site to search• Search problem: find the shortest path to that site

Algorithms and Search

Page 15: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

S

Algorithms and Search• Can we be done already?...

• No! Your robot also has to get to the frontier.• What algorithm is more efficient to get you to the frontier?

S

Page 16: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

Breadth First Search and Dijkstra’s Algorithm

• Breadth-First Search

R

G

(2,3)

(2,2)

(1,4) (3,4)

(3,3) (1,3)(2,4)

(3,2) (1,2)(2,1)(2,4)

(3,3)

(2,2)

(1,3)

(3,4)(1,4)

(3,2)

(2,1)

(1,2)

(0,3)(0,3)

(0,4)

(3,1)

(3,1) (2,0)

(2,0)

(1,1)

Data structure• n.state• n.parent

(0,4)

Search order: N, E, S, W

Page 17: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

Breadth First Search and Dijkstra’s Algorithm

• Breadth-First Search

R

G

(2,4)

(3,3)

(2,2)

(1,3)

(3,4)(1,4)

(3,2)

(2,1)

(1,2)

(0,3)

(0,4)

(3,1)

(2,0)

Data structure• n.state• n.parent

Does not include the cost to get there…

(2,3)

(2,2)

(1,4) (3,4)

(3,3) (1,3)(2,4)

(3,2) (1,2)(2,1) (0,3)

(3,1) (2,0) (1,1)(0,4)

Page 18: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

Breadth First Search and Dijkstra’s Algorithm

• Dijkstra’s Algorithm: consider parent cost

R

G

(2,3)

(2,2)(3,3) (1,3)(2,4)(2,4)

(3,3)

(2,2)

(1,3)

Data structure• n.state• n.parent• n.cost• n.action

Search order: N, E, S, W

2 1 2 3

Go straight, cost 1Turn quadrant, cost 1

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

(3,2)

(1,4)(1,4)

2 2 (2,1)

(2,1)

(1,2)

(1,2)

2 1 2

(3,1)

(3,1) (2,0)

(2,0)

(1,1)2 1 2

May save some computation!

2

Page 19: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

Breadth First Search and Dijkstra’s Algorithm

• Dijkstra’s Algorithm: consider parent cost(Wikipedia)

Page 20: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

Could we be smarter?

• Sure!• Detect walls to the side• Detect treasures/walls from further away• Pick closest frontier (minimize distance)• Pick a path to frontier that traverses most

possible unknown space

• …Informed algorithms• Consider parent cost, and• estimates the shortest path to the “goal”

?

?

Page 21: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

28

Prof Allison Okamura, StanfordECE Colloquium tonight: “Let’s be Flexible!”• 4.30-6pm (PH233)

Opportunities for Graduate Study in Engineering • 7.30-8pm (PH203)• Pizza served from 7pm

Page 22: Matlab, python, C, Processing, etc… - cei-lab.github.ioAlgorithms, Exploration and Search • Nov 6. th-Nov 10. th. Matlab, python, C, Processing, etc… Turn on an LED, little dance,

29

Class website: https://cei-lab.github.io/ece3400/Piazza: https://piazza.com/cornell/fall2017/ece3400/home