• Non ci sono risultati.

Fundamentals of Artificial Intelligence

N/A
N/A
Protected

Academic year: 2021

Condividi "Fundamentals of Artificial Intelligence"

Copied!
33
0
0

Testo completo

(1)

Fundamentals of Artificial Intelligence

Laboratory

Dr. Mauro Dragoni

Department of Information Engineering and Computer Science

Academic Year 2020/2021

(2)

Exercise 3.14

page 02

 Design a genetic algorithm for solving a Sudoku puzzle.

(3)

Exercise 3.14 – some hints

page 03

 Crossover

(4)

Exercise 3.14 – some hints

page 04

 Mutation (sensorless)

x

{1,2,3,4,5,6,7,8,9}

(5)

Exercise 3.14 – some hints

page 05

 Mutation (partial observation - home square)

x

{1,2,3,4,5,6,7,8,9}

(6)

Exercise 3.14 – some hints

page 06

 Mutation (partial observation – row + home square)

x

{1,2,3,4,5,6,7,8,9}

(7)

Exercise 3.14 – some hints

page 07

 Mutation (partial observation – column + home square)

x

{1,2,3,4,5,6,7,8,9}

(8)

Exercise 3.14 – some hints

page 08

 Mutation (full field)

x

{1,2,3,4,5,6,7,8,9}

(9)

Exercise 3.14 – a last thing about GA

page 09

 How GAs walk on the solution space…

(10)

Before to start…

page 010

 A corpus for building (very) intelligent agents The Abstraction and Reasoning Corpus (ARC) https://github.com/fchollet/ARC

 Reference paper:

“On The Measure of Intelligence” - https://arxiv.org/abs/1911.01547

(11)

Exercise 4.1

page 011

 Consider the sensorless version of the erratic vacuum world. Draw the belief-

state space reachable from the initial belief state {1, 2, 3, 4, 5, 6, 7, 8}, and explain why the problem is unsolvable.

 Erratic vacuum world:

• When applied to a dirty square the action cleans the square and sometimes cleans up dirt in an adjacent square, too.

• When applied to a clean square the action sometimes deposits dirt on the

carpet.

(12)

Exercise 4.1 - solution

page 012

 Consider the sensorless version of the erratic vacuum world. Draw the belief-

state space reachable from the initial belief state {1, 2, 3, 4, 5, 6, 7, 8}, and explain why the problem is unsolvable.

L R

R

S L S

S

(13)

Exercise 4.2

page 013

 Consider the search space below, where S is the start node and G1 and G2 satisfy the goal test. Arcs are labeled with the cost of traversing them and the estimated cost to a goal (i.e., the h function) is reported inside nodes (so lower scores are better). Apply Greedy Best-First and A* search strategies; indicate

which goal state is reached (if any) and list, in order, all the states. In case of equal values, nodes should be removed from the list in alphabetical order.

(14)

Exercise 4.2 – Greedy best-first

page 014

Step Queue Processed node Children

1 S(9) S(9) A(6) C(2) D(5)

2 C(2) D(5) A(6) C(2) B(2) F(3) J(1)

3 J(1) B(2) F(3) D(5) A(6) J(1) F(3) G1(0)

4 G1(0) B(2) F(3) D(5) A(6) G1(0)

(15)

Exercise 4.2 – A*

page 015

Step Queue Processed

node

Children

1 S(9) S(9) A(4+6) C(3+2) D(1+5)

2 C(5) D(6) A(10) C(5) B(5+2) F(5+3) D(5+5) J(7+1)

3 D(6) B(7) F(8) J(8) A(10) D(6) E(4+5) 4 B(7) F(8) J(8) E(9) A(10) B(7) G1(9+0) 5 F(8) J(8) E(9) G1(9) A(10) F(8) G2(9+0)

6 J(8) E(9) G1(9) G2(9) A(10) J(8) F(12+3) G1(10+0) 7 E(9) G1(9) G2(9) A(10) E(9) F(7+3) G2(10+0)

8 G1(9) G2(9) A(10) G1(9)

(16)

Exercise 4.2

page 016

Is this h function admissible?

(17)

Exercise 4.2

page 017

Is this h function admissible?

This h function is admissible. For all nodes n, h(n) <= h*(n), where h*(n) is the actual cost to reach the goal from node n.

Node h h*

S 9 10

A 6 7

B 2 4

C 2 6

D 5 9

E 5 6

F 3 4

J 1 3

(18)

Exercise 4.3

page 018

 Graph coloring: start with random coloring of nodes and change color of one node to reduce the number of conflicts.

Step A B C D E F # conflicts 1 r g b r b b 3 {CE, CF, EF}

function HILL-CLIMBING (problem) returns a state that is a local maximum

current ← MAKE-NODE (problem.INITIAL-STATE) loop do

neighbor ← a highest-valued successor of current

if neighbor.VALUE ≤ current.VALUE then return current.STATE current ← neighbor

(19)

Exercise 4.3

page 019

 Graph coloring: start with random coloring of nodes and change color of one node to reduce the number of conflicts.

Step A B C D E F # conflicts 1 r g b r b b 3 {CE, CF, EF}

2 r g G r b b 1 {EF}

(20)

Exercise 4.3

page 020

 Graph coloring: start with random coloring of nodes and change color of one node to reduce the number of conflicts.

Step A B C D E F # conflicts 1 r g b r b b 3 {CE, CF, EF}

2 r g G r b b 1 {EF}

3 r g g r b R 1 {DF}

(21)

Exercise 4.3

page 021

 Graph coloring: start with random coloring of nodes and change color of one node to reduce the number of conflicts.

Step A B C D E F # conflicts 1 r g b r b b 3 {CE, CF, EF}

2 r g G r b b 1 {EF}

3 r g g r b R 1 {DF}

4 r g g G b r 0

(22)

Exercise 4.4

page 022

 Solve the Column Jump game

 The initial board has some configuration of colored balls with at least one empty space.

The objective is to remove all but one ball from the board.

Balls are removed when they are jumped

according to the following rules. If a ball of one color jumps over a different colored

ball to an empty space, the jumped ball is removed from the board.

Additionally, if multiple balls of the same color are in a line, they can be jumped and removed together (by a different colored ball, provided that an empty space is on the other side of the line).

1 2 3 4

1

2

3

4

(23)

Exercise 4.4

page 023

 Provide possible heuristics for solving the

game. 1 2 3 4

1

2

3

4

(24)

Exercise 4.4

page 024

 Color code:

White (empty cells): 0 Red: 1

Green: 2 Orange: 3

 Provide the series of moves required to

solve the puzzle. A move is represented by two locations on the grid with (row,

column) numbers.

 The grid locations follow this convention:

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

1 2 3 4

1

2

3

4

(25)

Exercise 4.4

page 025

 By applying a “maximum-zero” heuristic – step 1

1 2 3 4

1 2 3 4

1 2 3 4

1

2

3

4

(26)

1 2 3 4 1

2 3 4

Exercise 4.4

page 026

 By applying a “maximum-zero” heuristic – step 2

1 2 3 4

1

2

3

4

(27)

1 2 3 4 1

2 3 4

Exercise 4.4

page 027

 By applying a “maximum-zero” heuristic – step 3

1 2 3 4

1

2

3

4

(28)

1 2 3 4 1

2 3 4

Exercise 4.4

page 028

 By applying a “maximum-zero” heuristic – step 4

1 2 3 4

1

2

3

4

(29)

1 2 3 4 1

2 3 4

Exercise 4.4

page 029

 By applying a “maximum-zero” heuristic – step 5

1 2 3 4

1

2

3

4

(30)

1 2 3 4 1

2 3 4

Exercise 4.4

page 030

 By applying a “maximum-zero” heuristic – step 6

1 2 3 4

1

2

3

4

(31)

1 2 3 4 1

2 3 4

Exercise 4.4

page 031

 By applying a “maximum-zero” heuristic – step 7

1 2 3 4

1

2

3

4

(32)

1 2 3 4 1

2 3 4

Exercise 4.4

page 032

 By applying a “maximum-zero” heuristic – step 8

1 2 3 4

1

2

3

4

(33)

Exercise 4.5 - Homework

page 033

 Color code:

White (empty cells): 0 Red: 1

Green: 2 Orange: 3 Blue: 4

 Provide the series of moves required to

solve the puzzle. A move is represented by two locations on the grid with (row,

column) numbers.

 The grid locations follow this convention:

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

1 2 3 4

1

2

3

4

Riferimenti

Documenti correlati

 Starting from the green node at the top, which algorithm will visit the least number of nodes before visiting the yellow goal node?... Neither BFS nor DFS will ever encounter

Remove first path, Create paths to all children, Reject loops and Add paths..

Department of Information Engineering and Computer Science Academic Year 2020/2021...

Department of Information Engineering and Computer Science Academic Year 2020/2021... Algorithms

 The next step is to transform each well-formed formula into Prenex Normal Form, skolemize, and rewrite as clauses in conjunctive normal

So, here we have that garbage is mutex with not clean and with not quiet (the only way to make garbage true is to maintain it, which is mutex with carry and with dolly)...

If you bring in as many team-mates as you like to help David, reallocating some of the tasks to these folk (but nobody is over-allocated work), what is the earliest finish time of

 Represent the following seven sentences using and extending the representations developed in the chapter:.. The water in John’s water bottle