Beruflich Dokumente
Kultur Dokumente
(ENG 504)
504)
Lecture 3
/
Email: amhm@zu.edu.eg / amhm162@gmail.com
Webpage: http://www.staff.zu.edu.eg/amhm/
AI Paradigms.
Solving Problems by Search
Tree Search Algorithms (just names!)
Local Search Algorithms
Genetic Algorithms
2013/2014
Agenda
2013/2014
Introduction
B
A
1
8
D
4
C
2
3
E
2013/2014
Introduction
4
Solutions of TSP?
You may select the cheapest way out of each city until
You may test all possible tours, then select the cheapest one.
(Exhaustive search, so expensive)
You may setup only the first possible tour, then search for other tours
that could be better than the current best one.
(Branch and Bound, will save effort in most cases!)
You can also try genetic algorithms. (may succeed)
2013/2014
Introduction
5
Solutions of TSP?
Branch and Bound: is an enhanced version of the so-called back tracking search.
It can be applied when the solution can be represented by a search tree:
root A
node
2013/2014
Introduction
6
Solutions of TSP?
Thus we need first to know how to traverse a tree in (a depth first fashion
vs. breadth first fashion).
Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504)
Depth--first search
Depth
2013/2014
2013/2014
Pseudo-code:
DFS(G,v) ( v is the vertex where the search starts )
Stack S := {}; Visited V:={}
push (S, v);
While (S is not empty) do
u := pop (S);
If ( u is not in V) Then
insert (V, u);
for each neighbor w of u that is not in V, push (S, w);
End If
End While
END DFS()
Dr. A. Helmi Eng. Sys. Design and Analysis (ENG 504)
2013/2014
Notice:
Stack: is a data structure (like an array for ex.) where elements that enters
the stack first will leave it at last also (LIFO order).
push(S,v): inserts the element v in the stack S.
pop(S): returns or gets the first element in the stack S.
2013/2014
10
root A
C
E
2013/2014
11
root A
S={C}
V={A,B}, S={C,D}
S={D}
V={A,B,C}, S={D,D}
S={D}
V={A,B,C,D}, S={D,E}
S={E}
D has been visited once before !
S={ }
V={A,B,C,D,E} .While ends and thus DFS() stops.
2013/2014
12
B
root A
E
D
C
2013/2014
13
2013/2014
14
B
root A
E
D
C
2013/2014
15
Methodology:
Methodology
For each node, if the current partial solution is not
promising, then back to the father node and test
another child. (prune this subtree)
Always keep the best complete solution so far.
2013/2014
16
root
19
unfeasible
Cost=17
One solution
15
Best solution
prune
2013/2014
17
1.
2.
Insert partial solutions (PS) in memory and rank them from best to worst w.r.t. the lb.
3.
4.
5.
6.
7.
8.
2013/2014
18
Example #2: find the shortest tour such that B must be visited
before C?
It is easier for you to try to apply your technique
D
4
C
2
3
E
2013/2014
19
Example #2
#2: solution:
First step is always to find a clever bound function that can help to
prune as many as possible branches in the search tree.
Each class of problems may require different bound strategy.
For TSP, the following function works (in most cases):
The initial bound for the minimum tour is the sum of the minimum
outgoing edges from each vertex.
Lower bound: lb(u,v) = Length from u to v + sum of min outgoing
edges for vertices from v to root node.
2013/2014
Example #2
#2: solution:
20
A
1
D,E
7
15
E,D
24
C
2
12
16
E,C
19
10
D
-
10
13
14
14
18
11
17
C,E
16
12
B
18
E
3
B,C
24
14
24
BSSF
2013/2014
21
Example #2
#2: solution:
The cheapest tour (with minimum cost) = {A,B,D,E,C}
Computations of lower bounds
lb(A)=1+3+1+1+3+2=10
lb
rank evolution
PS
10 A
12 A,B
lb(A,D)=5+3+1+3+2=14
14 A,D
2 ,1
lb(A,B,C)=9+1+3+2=15
17 A,E
3,4 ,3, 2, 1
Cost(A,D,E,B,C) = 24
15 A,B,C
2 ,1
16 A,B,D
3, 2 ,1
18 A,B,E
5, 4 ,3, 2
18 A,D,B
6 ,5 ,4,3
14 A,D,E
lb(A,B)= 3+3+1+3+2=12
Memory
2013/2014
22
Exercise #2
#2:
Given n tasks and n agents.
Each agent has a cost to complete each task
Assign each agent one task
Minimize cost
Example of the solution:
(C,1),(A,2),(D,3),(B,4)
1
11
14
11
17
A
B
C
D
2
12
15
17
14
3
18
13
19
20
4
40
22
23
28
2013/2014
23
Exercise #3
#3:
Starting from A, find the shortest tour for this graph.
Construct the search tree using B&B algorithm.
Show why you may do pruning if this is the case at
any step.
What is the order of traversing the vertices?
2013/2014
Thanks