Transcript Branch-and
Branch and bound
Pasi Fränti
30.9.2014
General search strategies
Backtracking
Explore all alternatives
•
•
•
•
Solution constructed by stepwise choices
Decision tree
Guarantees optimal solution
Exponential time (slow)
Depth-first search
•
•
Implement as stack (push, pop, isempty)
Linear time memory
Breadth-first search
•
Implemented by queue (enqueue, dequeue, isempty)
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
E
F
A
D
2
3
G
3
2
3
H
Traveling salesman problem
Input: graph (V,E)
Output: path (p1, p2, ..., pn, pn+1)
B
2
A
2
2
4
3
C
D
4
5
3
G
2
E
3
2
Solution = A-B-C-F-H-E-D-G-A
Length = 22
4
F
3
H
Traveling salesman problem
Knapsack problem
Problem definition
Input:
Weight of N items {w1, w2, ..., wn}
Cost of N items {c1, c2, ..., cn}
Knapsack limit S
Output: Selection for knapsack: {x1,x2,…xn}
where xi {0,1}.
Sample input:
wi={1,1,2,4,12}
ci ={1,2,2,10,4}
S=15
Knapsack problem
Simplified
Input:
Weight of N items {w1, w2, ..., wn}
Knapsack limit S
Output: Selection for knapsack: {x1,x2,…xn}
where xi {0,1}.
5
3
Sample input:
wi={2,3,5,7,11}
S=15
7
2
11
Max 15
Knapsack problem
wi={2,3,5,7,11}
Branch-and-bound
0
2
Max 15
2
3
3
5
2
5
3
5
12
5
2
5
10
7
5
0
5
9
7
12
0
3
7
7
7
9
2
13
3
10
11
14
0
11
11
11
2
0
3
11
0
Something here
When time
Plus the same for sorting decreasing order
wi={2,3,5,7,11}
S=15
Graph algorithms
117
216
110
246
199
121
79
182
315
142
170
242
191
148
231
136
78
120
126
149
89
116
234
170
51 112
79
131 109
86
73
163 143
72 63
90
53
191
178
59
58
116
105
135
27
C
A
B
Empty space for notes
Branch and Bound Algorithm:
Scheduling Problem
Material by A.Mirhashemi
Input of the problem:
A number of resources
A number of tasks
Output of the problem:
A sequence of feeding the tasks to resources
to minimize the required processing time
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
Task 1:
Task 2:
Task 3:
Task 4:
A one page plain text document
A 10 page document with pictures
A 5 page html document.
…
Application 2
Production line:
Each product (task) need to pass trough all machines
(resources) in the production line but, the time depends on
what kind of customization the customer has ordered for
that production. For example:
Machine A:
Machine B:
Machine C:
Solding
Painting
Packaging
Task 1:
Task 2:
Task 3:
Task 4:
A black car with airbag
A red car without airbag with CD player
A white car with leather seats
…
Different tasks take different time
to be processed in each resource
7
5
6
3
6
5
4
4
7
2
1
3
Tasks can be done in any order
N! Possible different sequences
Decision tree (Brute force)
Start
1
2
3
2
3
4
4
2
3
4
4
4
2
2
1
3
3
3
2
3
4
4
1
3
4
4
4
1
1
3
3
1
Start
3
1
2
2
4
4
4
1
2
4
4
4
1
1
1
2
2
2
1
2
3
3
1
2
3
3
3
1
1
2
2
1
Greedy Algorithm
A possible greedy algorithm might start with selecting
the fastest tasks for processor A.
7
6
7
5
5
2
6
4
1
3
4
3
:
Greedy solution
T(4,2,3,1) = 34
4
2
3
4
2
4
1
1
3
2
3
1
7
6
7
5
5
2
6
4
1
3
4
3
Optimal solution
T(4,1,2,3) = 26
1
4
1
4
6
7
5
5
2
6
4
1
3
4
3
3
2
4
7
2
3
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
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
b(4)= 3+(6+5+4+4)+1=23
7
6
7
5
5
2
6
4
1
3
4
3
Minimum
This next
Start
Bounds:
1
2
3
4
T ≥27
T ≥25
T ≥27
T ≥23
Level 2
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
7
6
7
5
5
2
6
4
1
3
4
3
Minimum
This next
Bounds:
T ≥26
T ≥24
T ≥26
Solve the branch 4-2-x-x
Bounds:
T ≥26
T ≥24
T ≥26
Tmin(4,2,x,x)= 29
Actual:
T(4,2,1,3) = 29
T(4,2,3,1) = 34
7
6
7
5
5
2
6
4
1
3
4
3
Solve the branch 4-2-x-x
Bounds:
T ≥26
T ≥24
7
6
7
5
5
2
6
4
1
3
4
3
T ≥26
Tmin(4,2,x,x)= 29
Tmin(4,1,x,x)= 26
Actual:
T(4,1,2,3) = 26
T(4,1,3,2) = 28
Tmin(4,3,x,x)= 29
Actual:
T(4,3,1,2) = 29
T(4,3,2,1) = 34
Solve the other branches
Can be
skipped
Bounds:
7
6
7
5
5
2
6
4
1
3
4
3
Start
1
2
3
4
T ≥27
T ≥25
T ≥27
T ≥23
T = 26
Actual Time:
Must be
solved
b(2,1)= (5+7)+(6+4+4)+1=27
b(2,3)= (5+6)+(6+4+4)+3=28
b(2,4)= (5+3)+(6+4+4)+1=23
7
6
7
5
5
2
6
4
1
3
4
3
The only candidate that can outperform
T(4,1,2,3) is T(2,4,…) so we calculate it:
Actual T(2,4,1,3) = 29
Actual T(2,4,3,1) = 34
So the best time is T(4,1,2,3) and
we don’t need to solve the
problem for any other branch
because we now their minimum
time, already.
7
6
7
5
5
2
6
4
1
3
4
3
Start
Bounds:
Actual Time:
1
2
3
4
T ≥27
T ≥25
T ≥27
T ≥23
T = 29
T = 26
Bounds greater than 26!
Summary
• Using only the first level criteria we reduce
the problem by 50% (omitting 2 main
branches).
• Using the second level criteria we can reduce
even more.
Empty space for notes