22
١ Engineering Engineering Engineering Engineering Systems Systems Systems Systems Design and Analysis Design and Analysis Design and Analysis Design and Analysis (ENG (ENG (ENG (ENG 504 504 504 504) د/ / أﺣﻤﺪ ﻣﺤﻤﺪ ﺣﻠﻤﻲ أﺣﻤﺪ ﻣﺤﻤﺪ ﺣﻠﻤﻲ ﻗﺴﻢ ﻫﻨﺪﺳﺔ اﻟﺤﺎﺳﺒﺎت و اﻟﻤﻨﻈﻮﻣﺎت ﻗﺴﻢ ﻫﻨﺪﺳﺔ اﻟﺤﺎﺳﺒﺎت و اﻟﻤﻨﻈﻮﻣﺎت ﻛﻠﻴﺔ اﻟﻬﻨﺪﺳﺔ ﻛﻠﻴﺔ اﻟﻬﻨﺪﺳﺔ ﺟﺎﻣﻌﺔ اﻟﺰﻗﺎزﻳﻖ ﺟﺎﻣﻌﺔ اﻟﺰﻗﺎزﻳﻖEmail: [email protected] / [email protected] Webpage: http://www.staff.zu.edu.eg/amhm/ Lecture Lecture Lecture Lecture 2 Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014 Eng. Sys. Design and Analysis (ENG 504) 1 Agenda Agenda Agenda Agenda AI Paradigms. Solving Problems by Search Tree Search Algorithms Local Search Algorithms

lecture 2

  • Upload
    aliknf

  • View
    212

  • Download
    0

Embed Size (px)

Citation preview

١

Engineering Engineering Engineering Engineering Systems Systems Systems Systems Design and Analysis Design and Analysis Design and Analysis Design and Analysis (ENG (ENG (ENG (ENG 504504504504))))

أحمد محمد حلميأحمد محمد حلمي/ / ددقسم هندسة الحاسبات و المنظومات قسم هندسة الحاسبات و المنظومات

جامعة الزقازيقجامعة الزقازيق––كلية الهندسة كلية الهندسة

Email: [email protected] / [email protected]

Webpage: http://www.staff.zu.edu.eg/amhm/

Lecture Lecture Lecture Lecture 2222

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

1AgendaAgendaAgendaAgenda

� AI Paradigms.

� Solving Problems by Search

� Tree Search Algorithms

� Local Search Algorithms

٢

AI ParadigmsAI ParadigmsAI ParadigmsAI ParadigmsAI ParadigmsAI ParadigmsAI ParadigmsAI Paradigms

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

2AI ParadigmsAI ParadigmsAI ParadigmsAI Paradigms

� The term intelligence is always defined as the ability to learn effectively, to

react adaptively, to make proper decisions, to communicate in language or

images in a sophisticated way, and to understand.

� Main objectives of AI are to develop methods and systems for solving

problems, usually solved by the intellectual activity of humans.

� Signs of AI:

� Learn or understand from experience.

� Make sense out of ambiguous or contradictory messages.

� Respond quickly and successfully to new situations.

� Think and reason.

� Use reasoning to solve problems.

٣

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

3AI ParadigmsAI ParadigmsAI ParadigmsAI Paradigms

� Signs of AI:

� Deal with perplexing situations.

� Understand and infer in ordinary, rational ways.

� Apply knowledge to manipulate the environment.

� Recognize the relative importance of different elements in a situation.

� Turing Test for Intelligence:

A computer can be considered to be smart only

when a human interviewer, “conversing” with

both an unseen human being and an unseen

computer, can not determine which is which

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

4AI ParadigmsAI ParadigmsAI ParadigmsAI Paradigms

� AI represents knowledge as sets of symbols.

� AI Programs manipulate symbols to solve problems.

� Symbols and symbol structures form knowledge representation.

� AI deals primarily with symbolic, non-algorithmic problem-solving methods.

� Heuristic methods for processing information:

� Search.

� Inference .

٤

Solving Problems by Solving Problems by Solving Problems by Solving Problems by Solving Problems by Solving Problems by Solving Problems by Solving Problems by SearchingSearchingSearchingSearchingSearchingSearchingSearchingSearching

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

5SearchSearchSearchSearch

� Many of the tasks underlying AI can be phrased in terms of a search for the

solution to the problem .

� For example: in production systems, the need to search for a sequence of rule

applications that lead to the required action.

� A search algorithm takes a problem as an input and returns a solution in the

form of an action sequence.

٥

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

6

� Problem Space:

� Initial state(s).

� Goal state(s). (Intermediate states)

� Actions or operations.

� A solution: is a sequence of actions (path) that map an initial state to

a goal state.

� Best solution: the shortest path from the initial state to the goal state.

� All available (feasible) paths form a search tree.

SearchSearchSearchSearch

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

7SearchSearchSearchSearch

�Example: 8-Puzzle

Initial state Goal state

� Actions: moves up, down, left, right.

� Solution: a set of movements that reach the goal state.

٦

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

8Types of Search AlgorithmsTypes of Search AlgorithmsTypes of Search AlgorithmsTypes of Search Algorithms

Informed SearchUnInformed Search

(brute force)

GreedyBest first

Breadth-first (BFS)

A*Depth-first (DFS)

Hill climbing

(Greedy Local Search)

Local Search

Uniform-cost (UCS)

(Dijkstra shortest path) Genetic algorithms

Simulated annealingIterative deepening (IDS)

Tabu searchBidirectional

……

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

9Types of Search AlgorithmsTypes of Search AlgorithmsTypes of Search AlgorithmsTypes of Search Algorithms

Informed SearchUnInformed Search

Heuristic search

(a guess about which is best, not exact)Blind search

Use a cost (heuristic) function to

evaluate each solution.

Search through the space of possible

solutions

Backtrack if it realizes that the

present path proves unworthy.

No knowledge about which path is

likely to be best

Heuristic (it is of Greek origin) means discovery

٧

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

10Properties of search algorithmsProperties of search algorithmsProperties of search algorithmsProperties of search algorithms

I. Completeness. find one solution at least?

II. Optimality. find the best solution?

III. Time Complexity. Upper bound of consumed time?

IV. Space Complexity. Upper bound of required memory storage?

Local SearchLocal SearchLocal SearchLocal SearchLocal SearchLocal SearchLocal SearchLocal Search

٨

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

11Local Search Algorithms Local Search Algorithms Local Search Algorithms Local Search Algorithms paradigm

� State space = set of "complete" configurations.

� Find configuration satisfying constraints.

� Define a cost (heuristic) function to evaluate solutions.

� Start with some random solution, then keep a single "current" state

and try to improve it.

� They are iterative improvement algorithms.

� The goal is to find the state with the best cost.

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

12Local Search Algorithms Local Search Algorithms Local Search Algorithms Local Search Algorithms paradigm

� Generation mechanism, generating a transition from one configuration

to another.

� Neighborhood is a function which defines a simple transition

from a solution to another solution by doing an action.

� Selection of neighborhood:

� choose the first lower cost neighbor found;

� select the best neighbor in the entire neighborhood;

� choose the best of a sample of neighbors.

٩

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

13Local Search Algorithms Local Search Algorithms Local Search Algorithms Local Search Algorithms paradigm

� Local search is visualized as state-space landscape.

� Location: state.

� Elevation: value of heuristic cost function.

� The search aims to find the best solution

(global minimum).

(using heuristic cost function)co

st

State space

Local minimum

global minimum

*

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

14Local Search AlgorithmsLocal Search AlgorithmsLocal Search AlgorithmsLocal Search Algorithms

Example #1: n-queens problem

� Put n queens on an n × n board with no two queens on the same row,

column, or diagonal.

h = 4 h= 3 h= 2

� Cost function: how many queens attack each other?

n = 4

١٠

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

15Types of Search AlgorithmsTypes of Search AlgorithmsTypes of Search AlgorithmsTypes of Search Algorithms

Informed SearchUnInformed Search

(brute force)

GreedyBest first

Breadth-first (BFS)

A*Depth-first (DFS)

Hill climbing

(Greedy Local Search)

Local Search

Uniform-cost (UCS)

(Dijkstra shortest path) Genetic algorithms

Simulated annealingIterative deepening (IDS)

Tabu searchBidirectional

……

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

16Hill climbing algorithmHill climbing algorithmHill climbing algorithmHill climbing algorithm

� Problem: depending on initial state, can get stuck in local minima.

� One solution: start from different initial solutions.

١١

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

17

Example #1: 4-queens problem solution

(one possible solution path by a computer program)

Solution: h= 0

Initial state

Hill climbing algorithmHill climbing algorithmHill climbing algorithmHill climbing algorithm

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

18

Example #1: 4-queens problem solution

(another possible solution path by a computer program)

Initial state Solution: h= 0

h = 4

h = 3

Hill climbing algorithmHill climbing algorithmHill climbing algorithmHill climbing algorithm

١٢

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

19

What about 8-queens problem?

Hill climbing algorithmHill climbing algorithmHill climbing algorithmHill climbing algorithm

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

20Types of Search AlgorithmsTypes of Search AlgorithmsTypes of Search AlgorithmsTypes of Search Algorithms

Informed SearchUnInformed Search

(brute force)

GreedyBest first

Breadth-first (BFS)

A*Depth-first (DFS)

Hill climbing

(Greedy Local Search)

Local Search

Uniform-cost (UCS)

(Dijkstra shortest path) Genetic algorithms

Simulated annealingIterative deepening (IDS)

Tabu searchBidirectional

……

١٣

Genetic AlgorithmsGenetic AlgorithmsGenetic AlgorithmsGenetic AlgorithmsGenetic AlgorithmsGenetic AlgorithmsGenetic AlgorithmsGenetic Algorithms

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

21Genetic AlgorithmsGenetic AlgorithmsGenetic AlgorithmsGenetic Algorithms

The most important terms:

� Gene: a basic unit, which controls a property of an individual.

� Chromosome: a string of genes; it is used to represent an individual,

or a possible solution of a problem in the solution space.

� Population: a collection of individuals.

� Crossover (mating) operation: substrings of different individuals are taken

and new strings (offsprings) are produced.

� Mutation: random change of a gene in a chromosome.

١٤

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

22Genetic AlgorithmsGenetic AlgorithmsGenetic AlgorithmsGenetic Algorithms

The most important terms:

� Fitness (goodness) function: a criterion which evaluates each individual.

� Selection: a procedure for choosing a part of the population that will

continue the process of searching for the best solution, while the other

part of the population "dies".

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

23Genetic Algorithms (GA)Genetic Algorithms (GA)Genetic Algorithms (GA)Genetic Algorithms (GA)

A simple pseudo code:A simple pseudo code:

1. Initialize population of possible solutions.

2. WHILE criterion of termination is not reached DO

{

2.a Crossover two individuals (mother and father) and generate new

individuals (offspring).

2.b Select the most promising ones according to fitness function.

2.c Development. (Terminate if a solution is found)

2.d Mutation (rare).

} (Terminate if time is up)

١٥

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

24Flow chart:Flow chart:

If necessary

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

25Genetic Algorithms (GA)Genetic Algorithms (GA)Genetic Algorithms (GA)Genetic Algorithms (GA)

Graphical representation for the Graphical representation for the pseudo code:pseudo code:

١٦

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

26Genetic AlgorithmsGenetic AlgorithmsGenetic AlgorithmsGenetic Algorithms

Example #2: Guess a number game

� One of two players (Pep) thinks up a number (e.g., 001010) and the other

(Alice) has to find it out with a minimal number of questions.

� Alice guesses a solution and Pep replies another number indicating the

number of correctly guessed bits.

� The number of correct bits is the criterion (for Alice) for the selection

of promising solutions.

� If there is no improvement after a certain number of steps, then Alice

should make a change (mutation: randomly flip one bit).

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

27Genetic AlgorithmsGenetic AlgorithmsGenetic AlgorithmsGenetic Algorithms

Example #2: Guess a number game(one possible solution)

First iteration: Alice produces four solutions and Peb replies :

fitnessindividuals

1101010A

1101111B

4110110C

3001101D

“001010”in mind of Peb

Promising father & mother

١٧

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

28Genetic AlgorithmsGenetic AlgorithmsGenetic AlgorithmsGenetic Algorithms

Example #2: Guess a number game(one possible solution)

Second iteration:

110110C

001101D

“001010”in mind of Peb

Promising father & mother

110110C

001101D

3001110E

4110101F

4000110G

3111101H

New individualsmating fitness

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

29Genetic AlgorithmsGenetic AlgorithmsGenetic AlgorithmsGenetic Algorithms

Example #2: Guess a number game(one possible solution)

third iteration:

110101F

000110G

“001010”in mind of Peb

Promising father & mother

110101F

000110G

3000111H

5110100I

4000101J

4110110K

New individualsmating fitness

١٨

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

30Genetic AlgorithmsGenetic AlgorithmsGenetic AlgorithmsGenetic Algorithms

Example #2: Guess a number game(one possible solution)

fourth iteration:

110100I

000101J

“001010”in mind of Peb

solution 110100I

000101J

5000100L

4110101M

6010100N

3100101O

New individualsmating fitness

End

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

31Genetic AlgorithmsGenetic AlgorithmsGenetic AlgorithmsGenetic Algorithms

In Example #2:

� There was no need for mutation:

� Mutation takes evolution out of a "dead end.“

� When the fitness or matching becomes worse.

� Success is achieved after 16 questions, which is four times faster than

checking all the possible combinations (64 possible variants).

١٩

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

32Genetic AlgorithmsGenetic AlgorithmsGenetic AlgorithmsGenetic Algorithms

Termination of a GA:

� A solution is found that satisfies minimum criteria.

� Fixed number of generations reached.

� Allocated budget (computation time/money) reached.

� The highest ranking solution's fitness is reaching or has reached a plateau

such that successive iterations no longer produce better results.

� Combinations of the above.

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

33Genetic Algorithms (GA)Genetic Algorithms (GA)Genetic Algorithms (GA)Genetic Algorithms (GA)

More GA variations:

� Parallel and Distributed Genetic Algorithm (PGA and DGA)

� Hybrid Genetic Algorithm (HGA)

� Adaptive Genetic Algorithm(AGA)

� Fast Messy Genetic Algorithm (FMGA)

� Independent Sampling Genetic Algorithm(ISGA)

٢٠

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

34Genetic Algorithms (GA)Genetic Algorithms (GA)Genetic Algorithms (GA)Genetic Algorithms (GA)

LimitationsAdvantages

No absolute assurance that a

genetic algorithm will find a global

optimum/minima

Solve problems with multiple

solutions

If it is hard to define a fitness

function then GA will not be

useful

Easy to avoid trapped in localoptima/minima

GA can not assure constant

optimization response times

Easy for implementation on

parallel architectures

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

35Genetic Algorithms (GA)Genetic Algorithms (GA)Genetic Algorithms (GA)Genetic Algorithms (GA)

Problem domain of GA:

� Timetabling and Scheduling problems.

� Traveling Salesman Problem (TSP).

� Bioinformatics.

� Combinatorial Optimization Problem.

� Network Design and Routing Problems.

� In general for global optimization problems.

٢١

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

36MaterialsMaterialsMaterialsMaterials

� Chapter 1, Nikola K. Nikola K. KasabovKasabov, pages , pages 11--1414

�� Chapter 3, , Stuart Russell & Peter Stuart Russell & Peter NorvigNorvig, pages , pages 6464--106106

�� Chapter 4, , Stuart Russell & Peter Stuart Russell & Peter NorvigNorvig, pages , pages 120120--130130

�� For more information: ask GoogleGoogle !

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

37RequiredRequiredRequiredRequired

� Have a look on the following search algorithms:

� Breadth-first (BFS)

� Depth-first (DFS)

� Dijkstra shortest path

� A* Best first search

� For each one: to know the search strategy , applications, advantages,

limitations and solve few examples.

٢٢

Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504) Zagazig Univ-Eng. Faculty 2013/2014Eng. Sys. Design and Analysis (ENG 504)

38Assignment #Assignment #Assignment #Assignment #1111

Can we solve an 8-queens problem using genetic algorithms?

Write a computer program in the language you prefer

(i.e., C++, Java, VB, Matlab, …) in order to solve this

problem. Then draw the correct solution on a chess

board either by hand or by a computer program.

� Send a soft copy of your answer by email.

� DeadLine: 15/12/2013 (two weeks later !)

ThanksThanks