meljun cortes algorithm_coping with the limitations of algorithm power_ii
TRANSCRIPT
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
1/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 1 of 47
The following are the topics to be discussed under
coping with the limitations of algorithm power:
Understand the idea of coping up with the
limitation of algorithm power
Understand the concept of Backtracking
algorithm design technique.
Understand the application of Backtrackingusing algorithm design technique N-queen
problem.
Know the definition of branch and bound
algorithm design technique.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
2/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 2 of 47
There are problems that are difficult to solve
where algorithms takes too much time for arbitrary
instances of problem.
To cope up with this, it is important to understand
what makes a problem difficult and makes a
problem easy.
Theoretically, a problem will turn out to be difficult
if there is only one instance of the problem that
demands an exponential time to solve by anyalgorithm.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
3/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 3 of 47
Problems can be solved using
back-tracking
branch-and-bound
Both strategies are improvements over exhaustive
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
4/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 4 of 47
Backtracking: is a refinement of the exhaustive
search strategy where solutions to a problem are
developed and evaluated one step
at a time.
Each partial solution is evaluated for feasibility
and is said to be feasible if it can be developed by
further choices without violating any of the
problem’s constraints.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
5/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 5 of 47
The following are the steps in evaluating a
problem thru backtracking:
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
6/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 6 of 47
Example: N-Queen problem
A standard chess board is an eight-by-eight array
consisting eight rows of eight columns each.
To further understand the constraints on thisproblem, we shall examine the simpler 4-queens
problem that is set on a four-by-four board.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
7/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 7 of 47
The possible moves for this queen are the
following:
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
8/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 8 of 47
Solution to the problem can be attained thru the
following:
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
9/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 9 of 47
It can be argued that other solutions can be
generated by symmetry arguments, once we have
one applicable solution we shall use symmetry to
get the others as illustrated below:
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
10/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 10 of 47
The empty board is considered as the root node of
the tree which is the starting position of the
problem. The figure below are the first two levels
of the tree:
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
11/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 11 of 47
Each of the two leaf nodes in the partial tree is the
root node of a tree with the following leaf count:
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
12/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 12 of 47
We now consider the subtree on the left and see
backtracking in action. Think an incorrect solution
that places another queen in position (2, 2) as
illustrated below:
You will observe that we have a diagonal conflict
since the first queen at position (1, 1) can attack
the second queen at position (2, 2) by using a
diagonal move.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
13/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 13 of 47
This method of stating every node in the subtree
to violate a constraint and therefore dropping the
set of solutions is called pruning the state tree.
It is simple to see that there are 6! = 720 trialsolutions with one queen at (1, 1) and the other at
(2, 2).
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
14/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 14 of 47
Again, we will look at the other subtree of the
solution space, beginning with the node illustrated
below:
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
15/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 15 of 47
Only possible placement is at (2, 4), Let’s follow
the search tree for the (2, 4) placement, then
again, we draw it horizontally as illustrated below:
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
16/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 16 of 47
Remember that there is only one alternative for
positioning the queen in the third column because
of the following reasons:
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
17/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 17 of 47
Alternative for placing the queen in the fourth
column since:
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
18/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 18 of 47
Branch and Bound is most commonly applied to
optimization problems.
Bounding solution does not satisfy the constraintsbut can be shown to be a bound for any optimal
solution.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
19/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 19 of 47
Assessing the Problem State Space Tree
Branch-and-bound algorithm design technique
is useful to a problem in which a solution can
be viewed as generating nodes in a state-space tree.
The leaf nodes can represent a solution to the
problem, which may not be a reasonable
solution.
Usually, the root node denotes the problem
prior to any decisions made, like the chessboard before any queens has been placed or
the job status before anybody has been
assigned a job.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
20/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 20 of 47
Usually, in the state-space tree the previously
generated node must be able to assess the node
and specifically we ask the following questions.
1. How does the partial solution compare to the
best existing solution?
2. Is the solution represented by this node a
feasible solution?
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
21/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 21 of 47
To make the branch-and-bound work, it is
necessary to assess each node just generated as
the root node of a tree that represents all
solutions that can be generated based on the
partial solution we have just generated.
Therefore, we “prune” the search tree if any of the
following holds:
1. It can prove that no solution in the subtree will
gratify the problem constraints.
2. It can prove that no solution in the subtree will
be better than the best solution produced
thus far.
3. The node created symbolizes an absolute
feasible solution that can be compared to the
best solution so far generated and possibly
replace it.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
22/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 22 of 47
Live node: is a node that can possibly represent a
partial solution leading to an optimal solution of
the whole problem.
If we can assess the live nodes as to the bestsolution that can be associated with the node’s
subtree, we can apply best first branch and bound
The key approach to branch-and-bound is to view
each newly generated node as the root node of a
subtree leading to a set of solutions.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
23/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 23 of 47
We first choose the assignment problem, which
amounts to assigning each of N workers to N jobs
so that the total costs of the jobs are minimized.
We are given an N-by-N matrix describing the costfor each worker to do each job
It should be noted that this method can be used to
assign N workers to M jobs, with M < N.
This is done by creating (N – M) dummy jobs, each
with a cost representing the expense of having a
worker do nothing.
We shall assume one job per worker.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
24/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 24 of 47
Consider the matrix of costs. Each row in the
matrix represents a worker and each column
represents a job. The constraints of a feasible
solution are:
1. We pick one entry from each row,
corresponding to the assignment of exactly
one worker to a job.
2. We pick one entry from each column, so that
each job has someone working on it.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
25/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 25 of 47
Set another method, a feasible solution
corresponds to the selection of one entry in each
row of the matrix so that no two selected elements
are in the same column.
An optimal solution is that feasible solution of
lowest cost.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
26/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 26 of 47
For the first bounding solution, find the minimum
cost per row and add it up.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
27/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 27 of 47
For the second bounding solution consider the
column minimum.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
28/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 28 of 47
We need something generated quickly and
guaranteed to be feasible, so we pick as follows,
just moving down the diagonal of the matrix.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
29/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 29 of 47
For the first bounding solution, find the minimum
cost per row and add it up.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
30/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 30 of 47
For the second bounding solution consider the
column minimum.
The total cost associated with this feasiblesolution is 9 + 4 + 1 + 4 = 18. Thus we know that
the limits on any optimal solution are 12 and 18
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
31/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 31 of 47
We need something generated quickly and
guaranteed to be feasible, so we pick as follows,
just moving down the diagonal of the matrix.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
32/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 32 of 47
We now generate a version of the search tree and
consider how to improve it.
We label each node with the total cost of the
allocation so far, here just the cost of the job.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
33/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 33 of 47
Let’s return to the examination of minimum costs
per row. The table is repeated here for easy
reference.
The lower bound for the rest of the workers, after
Worker A has been assigned a job, is 3 + 1 + 4 =
8.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
34/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 34 of 47
Thus, we may immediately generate a lower bound
on any partial solution:
The total cost of the partial solution plus the
minimum cost of the remaining assignments. With that in mind, we arrive at a new start to the
search tree.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
35/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 35 of 47
Here are the adjusted matrices to be used in
assessing the subtrees:
Here are the adjusted matrices to be used in
assessing the subtrees.
A gets job1 with cost = 9
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
36/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 36 of 47
A gets job 2 with cost = 2
The subtree assesses again at 8, so the total
lower limit is 10
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
37/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 37 of 47
A gets job 3 with cost = 7
Here we have a new assessment for the subtree –
a new lower limit of 13, so that the total lower limit
evaluation of the node is 20
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
38/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 38 of 47
A gets job 4 with cost = 8
Here we also have a new assessment for the
subtree – a new lower limit of 10, so that the totallower limit evaluation is 18.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
39/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 39 of 47
Given these more computationally intensive
calculations, we have the following for the
problem state-space tree.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
40/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 40 of 47
One of the nodes – “A gets job 3” – has a lower
bound exceeding the cost of a known feasible
solution.
For this reason it is pruned and the remaining treeis as follows.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
41/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 41 of 47
Here are the three possibilities for this subtree.
A gets job 2 B gets job 1
The remaining jobs assess at 5, so the node
assesses at a value of 13.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
42/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 42 of 47
A gets job 2 B gets job 3
The total cost is 2 + 3 = 5.
The matrix for the rest of the jobs and workers is
The remaining jobs assess at 9, so the node
assesses at a value of 14.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
43/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 43 of 47
A gets job 2 B gets job 4
The total cost is 2 + 7 = 9.
The matrix for the rest of the jobs and workers is
The remaining jobs assess at 8, so the node
assesses at a value of 17
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
44/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 44 of 47
Here is the state-tree after the node “A gets job 2”
has been expanded.
At this point, we have five live nodes to consider.These are labeled as
1) “A gets job 1”,
2) “B gets job 1”,
3) “B gets job 3”,
4) “B gets job 4”, and
5) “A gets job 4”.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
45/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 45 of 47
The best looking node is the one labeled “B gets
job 1” with a lower bound of 13.
We consider two possibilities for the subtree
rooted at this partial solution. Recall our matrix of choices for workers and D.
A gets job 2 B gets job 1
The total cost is 2 + 6 = 8. The matrix for workers
C and D is
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
46/47
Coping with the Limitations of algorithm Power
Design and Analysis of Algorithm
* Property of STI
Page 46 of 47
Here is the status: we have two feasible solutions,
one with total cost of 13.
We have four non-terminal live nodes, none of
which have a lower bound less than 14.
-
8/21/2019 MELJUN CORTES ALGORITHM_Coping With the Limitations of Algorithm Power_II
47/47
Design and Analysis of Algorithm
So we have a solution: A gets job 2, B gets job 1,
C gets job 3, and D gets job 4.
The solution generated 9 of the possible (4 + 12 +24) 40 nodes – an 75% saving.