Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
c =wi={2,3,5,7,11}
i
2
11
S=15
Max 15
Knapsack as decision tree
wi={2,3,5,7,11}
Yes No
Chooce 2 2 -
Yes No Yes No
Max 15
Chooce 3 5 2 3 -
Chooce 5 10 5 7 2 8 3 5 -
Yes Yes No
Chooce 7 17 10 12 5 5 14 9 2 15 8 10 3 12 5 7 -
… … No
… …
28 12 14 13 26 15 12 -
Bounding criterion
Brute force:
search full tree
Greedy: 2 -
take if fits in
O(2N)
N choices
5 2 3 -
10 5 7 2 8 3 5 -
17 10 12 5 5 14 9 2 15 8 10 3 12 5 7 -
… … …
28 10 12 14 13 26 15 12 -
Bounding criterion
+wnext > S
Must be sorted!
wi={2,3,5,7,11}
Chooce 2 2 -
Chooce 3 5 2 3 -
Chooce 5 10 5 7 2 8 3 5 -
Chooce 7 12 5 5 14 9 2 15 8 10 3 12 5 7 -
Chooce 11 13 14 11
Traveling salesman problem
Input: Graph (V,E)
Problem: Shortest tour visiting all nodes.
Brute force:
search full tree
O(N!)
2
1
2 277
153 157
283
2 2 2 2
2
1
2
Bounding criterion 1
Best found so far
Best candidate: 28 B
6
A
4
2 5 G
C E
1 D
6 4
H
F
New so far: 32 17 B
A 15
G
C E
5! = 120 D
H combinations
F
Bounding criterion 2
Nearest neighbors
17 B
A
4
G
C E
4 D
1 1 3 3
H
F
16
4+1+1+3+3+4
Lower bound: 33
Branch and Bound Algorithm:
Scheduling Problem
Material by A.Mirhashemi
A number of resources
A B C
A number of tasks
1
Output of the problem: 2
A sequence of feeding the tasks to resources 3
to minimize the required processing time
4
Application 1
Digital processing:
Each resource is a processor. All tasks need to pass trough
all processors in the fix sequence A,B,C but depending on
the task it takes different time for each processor to
process them. For example :
Processor A: Scanning
Processor B: Making a PDF
Processor C: Exporting a PDF
Machine A: Solding
Machine B: Painting
Machine C: Packaging
N
P
3
4
4 2
3 1
2 1 4 3
Decision tree (Brute force)
Greedy Algorithm
A possible greedy algorithm might start with selecting
the fastest tasks for processor A.
A B C
1 7 6 7
2 5 5 2
3 6 4 1
4 3 4 3
A : 4 2 3 1
Greedy solution A B C
1 7 6 7
T(4,2,3,1) = 34 2 5 5 2
3 6 4 1
4 3 4 3
4 2 3 1
4 2 3 1
4 2 3 1
Optimal solution A B C
1 7 6 7
T(4,1,2,3) = 26 2 5 5 2
3 6 4 1
4 3 4 3
4 1 2 3
4 1 2 3
4 1 2 3
Branch and bound Algorithm
Define a bounding criteria for a minimum time
required by each branch of the decision tree
For level 1:
For level 2:
Level 1 A B C
1 7 6 7
2 5 5 2
3 6 4 1
4 3 4 3
b(1)= 7+(6+5+4+4)+1=27
b(2)= 5+(6+5+4+4)+1=25
b(3)= 6+(6+5+4+4)+2=27 Minimum
b(4)= 3+(6+5+4+4)+1=23 This next
1 7 6 7
2 5 5 2
3 6 4 1
4 3 4 3
b(4,1)= (3+7)+(6+5+4)+1=26
b(4,2)= (3+5)+(6+5+4)+1=24
b(4,3)= (3+6)+(6+5+4)+2=26 Minimum
This next
1 7 6 7
2 5 5 2
3 6 4 1
4 3 4 3
Tmin(4,2,x,x)= 29
Actual: T(4,2,1,3) = 29
T(4,2,3,1) = 34
Solve the branch 4-2-x-x A B C
1 7 6 7
2 5 5 2
3 6 4 1
4 3 4 3
Tmin(4,2,x,x)= 29
Tmin(4,1,x,x)= 26 Tmin(4,3,x,x)= 31
Actual:
T(4,1,2,3) = 26 Actual:
T(4,3,1,2) = 31
T(4,1,3,2) = 28 T(4,3,2,1) = 34
Solve the other branches A B C
1 7 6 7
2 5 5 2
3 6 4 1
4 3 4 3
Can be
skipped
b(2,1)= (5+7)+(6+4+4)+1=27 1 7 6 7
2 5 5 2
b(2,3)= (5+6)+(6+4+4)+3=28 6 4 1
3
b(2,4)= (5+3)+(6+4+4)+1=23 4 3 4 3
2 0
3 3
5 2 3 0
5 5 5 5
12 5 9 2 10 3 7 0
7 7 7 7
12 5 9 2 10 3 11 0
11 11 11
13 2 14 3 11 0
Traveling salesman problem
A
2 G 2
B D 3
4 6 7 6
D B G
C
8 6 9
E F 11 E G 9 C
12 11 13 11
13
F
F H D 15 C F 15 E
15 14 13 17
F 17 F
H F G 16 20
17 D H
H 20
G 22 22
20
G 24 27 G 24
D 23
A D A A
Traveling salesman problem
Input: graph (V,E)
Problem: Find shortest path via all nodes and
returning to start node.
B C
2
2 2
4 4
3 5 4
A D E F
3 3
2 3
2
G H
117
Just in case
if needed
216
110
246
199 182
170
121 315 231
142
79
242 136
191 148 78