Добавил:
ivanov666
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Fundamentals of Operations Research. A textbook
.pdf
Optimization Problems and
N P
-Hardness
21
Denition 2.11.
I P Π
mialp.
Remark
algorithm, unless
complete. But some number problems are strongly
It clearly follows from the reduction demonstrated in example 2.3 that TSP remains
complete even if all the distances are 1 or 2, and the bound on the tour's length isn. At the
same time, there are number problems which are
Problem is a good example.
for which
Problem
Apparently, any
Π P N PC
2.1.If a problem is strongly
2.4. Optimization Problems and
Now turn back to optimization problems.
Denition 2.12.
belong to
Denition 2.13.
time.
N P
Given a problemΠand a polynomialp. Denote as
NpI q ď ppLpIqq
is called
P “ N P
N P
-complete problem which is not a number problem is strongly
Class
.
Class
N PO
PO
.
strongly
.
consists of optimization problems decision versions of which
consists of optimization problems which are solvable in polynomial
N P
-complete if
N P
-complete, it cannot be solved by a pseudopolynomial
N P
N P
Πpis
N P
-complete as well: TSP is among them.
-complete, but not strongly: the Partition
-Hardness
ΠpĎ Π
N P
-complete for some polyno-
a set of instances
N P
N P
-
-
Denition 2.14.
complete. The problem is
N P
-complete.
Note that in practice the term is often used in a broader sense: a
said to be
(and cannot, therefore, be called
N P
-hard, if is decision version is
Since the complexity of an optimization problem is dened by the complexity of its decision
version, in the following discussion we often won't make a distinction between two versions of
the same problem and, for example, will use the same abbreviation TSP for both optimization
and decision Traveling Salesman Problems.
N P
have ecient
Remark
strongly
What about
gorithm that provides a feasible solution for each instance
algorithm and denote the value of the solution for instanceIas
instance is
distance between its solutions and the optimal solutions: the closer
I P Π
It turns out that for some of the hard problems even a good approximate solution cannot
be nd by means of polynomial-time algorithms.
N P
-completeness theory tells us that some optimization problems, most probably, don't
2.2.If
N P
OP T pIq
the better.
An optimization problem is called
strongly
-hard, if every problem
exact
-hard problem can be solved in pseudopolynomial time.
algorithms:
P ‰ N P
approximate
. The quality of an approximate algorithm is determined by the maximum
then no
solutions? LetΠbe an optimization problem andAbe an al-
N P
-hard
, if corresponding decision problem is strongly
Ψ P N P
N P
-complete). Also, an optimization problem is said to be
N P
-hard.
N P
-hard problem can be solved in polynomial time, and no
is reducible toΠ, butΠis not from
N P
-hard
, if its decision version is
I P Π
. We callAan
ApIq
N P
decision
. The optimal value for the
ApIqtoOP T pIq
problemΠis
N P
itself
approximate
for each
-

22
Computational Complexity
Theorem 2.2.IfP ‰ N P
, there is no polynomial-time approximation algorithmAfor the
Boolean Knapsack Problem (BKP) with integral parameters
n
ÿ
cixiÑ max
i“1
n
ÿ
xPB
,
n
aixiď A,
i“1
whose absolute accuracy is bounded by a constantQ:
|ApIq ´ OP T pIq| ď Q @I P BKP.
Proof.
instance
by
Suppose such algorithmAexists for someQ. That is
I P BKP
pQ ` 1q:c
• ApI1q
is a multiple of
• OP T pI1q “ pQ ` 1qOP T pIq
. Fix an instanceIand construct a new instance
1
“ pQ ` 1qci. ApplyAto
i
pQ ` 1q
I1. It is obvious that
,
.
From (2.5) follows
Q ě |ApI1q ´ OP T pI1q| “ |ApI1q ´ pQ ` 1qOP T pIq| “ pQ ` 1q
|ApIq ´ OP T pIq| ď Q
I1by multiplying the costs
ˇ
ˇ
ApI1q
ˇ
ˇ
Q ` 1
´ OP T pIq
(2.3)
(2.4)
(2.5)
for any
ˇ
ˇ
ˇ
,
ˇ
therefore
In view of integrality of the left side,
nds the exact solution of
contradicts the assumption
Theorem 2.3.IfP ‰ NP
ˇ
ˇ
ApI1q
ˇ
ˇ
Q ` 1
´ OP T pIq
ApI1q “ pQ ` 1qOP T pIq “ OP T pI1q
I1(and ofIas well) in polynomial time. Since BKP is
P ‰ N P
.
ˇ
ˇ
ˇ
ˇ
ď
Q
Q ` 1
ă 1.
. So the algorithm
N P
-hard, it
, there is no polynomial time approximation algorithmAfor TSP
the performance ratio of which is bounded by a given constantK:
ApIq ď K ¨ OP T pIq @I P T SP.
Proof.
Again, suppose that such an algorithm exists for some
of the Hamiltonian Cycle Problem construct an instance
a graph
G “ pV, Eq
is given,
|V | “ n
. In
I1, we have a set ofncities with distances
K ą 1
, and for some instance
I1of TSP in the following way. InI,
(2.6)
"
1, pi, jq P E,
Kn, pi, jq R E.
OP T pI1q “ n
, and (2.6) yields
. Thus the algorithm allows us to determine if
Apply
ApI1q ď Kn
A
to
I1. If
. If there is no hamiltonian cycle, the approximate solution must include at least
one edge of weight
cij“
G
possesses a hamiltonian cycle, then
Kn
, and
ApI1q ą Kn
a graph contains a hamiltonian cycle in polynomial time, which contradicts the assumption
P ‰ N P
.
I
Therefore, the existence ofK-approximate polynomial algorithms for TSP seems very un-
likely for any arbitrary
K ě 1
. But, as we'll see below, such algorithms exist for the
version of the problem, i.e., when distances satisfy the triangle inequality.
metric

Exercises
2.5. Exercises
2.1.
2.2.
Prove
Prove
N P
-hardness of the Boolean Knapsack Problem (2.3)(2.4).
N P
-completeness of the following problem.
23
Subgraph Isomorphism.
contains a subgraph that is isomorphic to
2.3.
Is the Facility Location Problem (example 1.3)
2.4.
Is the Set Cover Problem (example 1.5)
2.5.
The Partition Problem is known to be
Given graphs
G “ pV, Eq
and
G1“ pV1, E1q,|V1| ď |V |
. Does
G1?
N P
-hard?
N P
-hard?
N P
-complete. What can be said about the Balanced
G
Partition?
2n
Balanced Partition Problem.
is even. Is there a subset
S Ă A
:
ÿ
a “
aPS
2.6.
The Hamiltonian Cycle Problem is
AzS
Given a set
ÿ
a “ B{2
N P
A “ ta1, . . . , a2nu Ă Z`such that
and
|S| “ |AzS| “ n?
-complete. What can be said about the Hamil-
B “
ř
a
i“1
tonian Path (a simple path passing each node once) and Hamiltonian Circuit (version of the
problem for directed graphs) Problems?
i

Chapter 3.
s
p(v)
v
t
Dynamic Programming
Dynamic programming (DP) is a powerful algorithmic paradigm in which an optimization
problem is transformed into a sequence of simpler subproblems, optimum values of which are
related one with the other by recurrence relations. Subproblems are then subsequently solved in
an iterative manner until the optimum of the initial problem is found (this stage is sometimes
called the
construct the global solution using solutions of subproblems obtained during the forward pass.
forward pass
of DP algorithm). Afterwards, the
backward pass
is performed to
Example 3.1.
The Shortest Path Problem.
cijfor each
LetPbe a shortest path, and vertex
To illustrate the concept of DP approach consider the following problem.
pi, jq P A
Given a directed graph
, and a pair of vertices
v P P
s, t P V
. Find the shortest path fromstot.
. Note that the path's sections fromstovand
G “ pV, Aq
, non-negative arc lengths
fromvtotare themselves the shortest paths connecting these vertices. This observation allows
us to implement the following approach. Denote the length of the shortest path connecting
with
v P V
we can nd
Therefore, to nd the shortest
as
dpvq
, and
dpvq
using the relation:
Ipvq “ ti P V : pi, vq P Au
dpvq “ min
s´t
tdpiq ` civu “ dpppvqq ` c
iPIpvq
path, we should solve the same problem for each vertex
. If the values
dpiq
are known for all
.
ppvq,v
i P Ipvq
(3.1)
v P V
that may occur in the path. Since these vertices are not known until the path is constructed,
we have to nd the shortest paths fromsto
shortest paths
.
each
v P V
, that is, to construct
a tree of the
The tree can be built in iterative manner. First, the tree consists of single vertexs. Since
no vertex is connected tos, all the values
dpvq
equal8. Then, at each step, we add a vertexv,
which is the closest tosamong those that are not yet in the tree (3.1), and store its predecessor
ppvq
. The process nishes whentis adjoined. The shortest
s ´ t
path can be restored using
predecessors. This algorithm was devised by Edsger Dijkstra in 1950ies and bears his name.
s
,

Distribution Problem
25
Estimate its time complexity. In the worst case, we need to perform
connected to the tree after all the other vertices are), and at each step up to
are executed. That gives
path construction takes
The essential aspect of DP methodology is that problem solving is transformed into
stage decision-making process
through a number of
associated with a set of parameters, the same for all stages, the values of which describe
state
of the system at the stage. At each stage some of state parameters can be changed that
leads the system into another state, and the goal is to guide the system to the optimal state at
nal stage by a sequence of optimal decisions made at each stage.
The specication of stages and states of the system is the most important (and, often, the
most dicult) phase of constructing a DP model. In the example above, though, the choice is
quite straightforward: the stages are the sequence of expanding trees, the states are lengths of
the shortest paths to each vertex; at each stage we make a decision to attach a new vertex
to the tree and then update the length value from8to
For DP approach to be applicable, the problem must satisfy certain structural conditions,
known as
the Bellman's Principle of Optimality
¾An optimal policy has the property that whatever the initial state and initial
decisions are, the remaining decisions must constitute an optimal policy with regard
to the state resulting from the rst decisions.¿
Op|V |2q
Op|V |q
stages
operations at the stage of nding
operations. Thus, the algorithm's complexity is
. The problem is considered as a controllable system that passes
(which may or may not have time implication). Each stage is
dpvq
.
.
dpvq
|V |
iterations (vertextis
's and
p|V |´1q
ppvq
comparisons
's. Subsequent
Op|V |2q
.
multi-
the
v
Richard Bellman. The Theory of Dynamic Programming.
Otherwise the solution of the problem is unrelated to the solutions of its subproblems, and
the recursion is not possible. Applied to the Shortest Path Problem, the Principle says any
subpath of an optimal path is optimal itself.
Therefore, when setting up a DP model, one should take into account that
1. the states should convey enough information to make future decisions without regard to
how the system reached the current state;
2. optimal states at each stage must be related with one another in the way the Optimality
Principle prescribes them to be;
3. the number of stages and changeable state parameters should be small enough for DP
approach to be computationally eective.
In the following sections we demonstrate application of DP approach to several optimization
problems.
3.1. Distribution Problem
Consider the following problem. A manufacturer hasYunits of a resource to use in production
during the period ofnyears. The eect (return) of usexresource units in thet-th year is given
by the function
that maximizes the total return.
ftpxq
, which is assumed to be non-decreasing. Find the resource distribution

26
Dynamic Programming
Denote the amount of the resource used in thet-th year as
xt. The problem is formulated
as follows:
n
ÿ
ftpxtq Ñ max
t“1
n
ÿ
xtď Y,
t“1
xtě 0, t “ 1, 2, . . . , n.
txtu
,
(3.2)
(3.3)
(3.4)
Note that since the outcome functions do not decrease, the inequality in constraint (3.3) can
be replaced with the equality:
n
ÿ
t“1
xt“ Y.
(3.5)
To solve the problem (3.2), (3.5), (3.4), consider it within the family
Π “ txk, yy : k “ 1, . . . , n, 0 ď y ď Y u,
where
Denote the optimal value of this problem as
problem is
xk, yy
is a subproblem of optimal distribution ofyresource units during the rstkyears.
xn, Y y
, and its optimum is
Easy to see that values
Skpyq
Skpyq
. Obviously, in this notation the initial
SnpY q
.
are connected by the relations:
S1pyq “ f1pyq, 0 ď y ď Y ;
Skpyq “ max
0ďxďy
tS
py ´ xq ` fkpxqu, k “ 2, . . . , n, 0 ď y ď Y.
k´1
(3.6)
(3.7)
Denote the partial solutions as
xkpyq “ argmax
In the forward pass, the values
is nished, the optimum
SnpY q
0ďxďy
Skpyq
and partial solutions
and the last component of the solution
tS
py ´ xq ` fkpxqu.
k´1
xkpyq
(3.8)
are calculated. When the pass
˚
x
“ xnpY q
n
are known.
To nd the remaining components, use the relations of the backward pass:
yn“ Y, x
yk“ y
k`1
´ x
˚
k`1
˚
“ xnpynq;
n
˚
, x
“ xkpykq, k “ n ´ 1, 1.
k
For this approach to be applicable, each subproblem (3.7) must be solvable within reasonable
time. This condition holds, for example, when all the variables
xkand the boundYare integers.
In this case, the time and space complexities of DP algorithm are:
T “ OpnY2q, S “ OpnY q,
which means, the algorithm is pseudopolynomial.
Note that to calculate the values
can reduce the memory usage to
Skpyq
OpY q
, we only need to know values
S
k´1
pyq
. Therefore, we
by storing only current solutions and overwriting them
at each step. In this case, though, the backward pass cannot be executed, and to restore the
optimal distribution we must perform
and determine
˚
x
“ xnpY q
n
, then to nd
Thus, the time complexity rises up to
series of forward passes, is called a
pn ´ 1q
Opn2Y2q
forward passes: rst, to nd the optimum
S
n´1
pY ´ x
˚
q
and
n
. This approach, when a problem is solved by a
relaxation DP-algorithm
SnpY q
x
˚
n´1
“ x
n´1
pY ´ x
˚
q
, and so on.
n
.

Distribution Problem
27
Example 3.2.
storages. The capacity of thei-th storage is
storage is
storages to minimize the total expenses. Values
n “ 8
containers arrived to a railroad station and must be delivered to
vi, the cost of transportation one container to the
gi, and the cost of storingxcontainers is
gi,
cipxq
. Distribute the containers among the
vi, and functions
cipxq
Storages
1 2 3 4 5
g
0.5 1 1.2 1.5 2
i
v
2 3 3 5 5
i
x c1pxq c2pxq c3pxq c4pxq c5pxq
0 0 0 0 0 0
1 2 1.5 1 0.5 0.3
2 4 2 2 1 0.5
3 - 3 3 1.5 1
4 - - - 2 1.5
5 - - - 2.5 2
The expenses associated with placingxcontainers to thei-th storage are
x “ 0, . . . , vi,
i “ 1, . . . , m
.
x h1pxq h2pxq h3pxq h4pxq h5pxq
0 0 0 0 0 0
1 2.5 2.5 2.2 2 2.3
2 5 4 4.4 4 4.5
3 - 6 6.6 6 7
4 - - - 8 9.5
5 - - - 10 12
m “ 5
are given below.
hipxq “ gix ` cipxq
,
To solve this distribution problem we use the recurrence relations:
S1pyq “ h1pyq, y “ 0, 1, . . . , 8;
Skpyq “ min
0ďxďminty,vku
In the forward pass, we ll a table with values
tS
py ´ xq ` hkpxqu, k “ 2, . . . , 5, y “ 0, 1, . . . , 8.
k´1
Skpyq
and partial solutions
slash (/):
y S1pyq S2pyq S3pyq S4pyq S5pyq
0 0 0 0 0
1 2.5/1 2.5/0 2.2/1 2/1
2 5/2 4/2 4/0 4/0
3 - 6/3 6/0 6/0
4 - 8.5/3 8.2/1 8/1
5 - 11/3 10.4/2 10/2
6 - - 12.6/3 12/3
7 - - 15.1/3 14/4
8 - - 17.6/3 16/5 16/0
Make some explanation:
xkpyq
divided by a

28
•
the marks are placed in cells that correspond to infeasible parameters, these marks
Dynamic Programming
can be treated as innite values;
•
there may be more than one partial solution, any of them can be stored;
•
there is no need to calculate values
S5pyq
for
y ă 8
.
At the end of the forward pass we know the optimal value
containers delivered to the last storage,
˚
x
“ x5p8q “ 0
5
. Describe the backward pass.
S5p8q “ 16
, and the number of
Since no containers are to be delivered to the fth storage, all eight of them must be
distributed among the rst four facilities:
are shipped to the fourth storage in optimal solution,
containers are distributed among storages
storage, as we see from cell
p3, 3q
S4p8q “ 16
t1, 2, 3u
and
x4p8q “ 5
˚
x
“ x4p8q “ 5
4
. That means, ve containers
. The three remaining
, and none of them are sent to the third
of the table. Then we move to cell
p3, 2q
and see that
all three containers are sent to the second storage. That means, the optimal distribution is
x˚“ p0, 3, 0, 5, 0q
, and its cost if
S5p8q “ 16
.
The model (3.2)(3.4) admits generalizations. For example, the resource can be not injected
to the production directly, but (if it is money) used to buy some means or raw materials at
cost
ctpxq
forxunits in thet-th year. Also, it is quite reasonable to assume that the amounts
of resource and raw materials available each year are bounded from above. These assumptions
transform the initial model into the following.
n
ÿ
ftpxtq Ñ max
t“1
n
ÿ
txtu
,
ctpxtq ď Y,
t“1
ctpxtq ď dt, t “ 1, 2, . . . , n,
0 ď xtď at, t “ 1, 2, . . . , n,
where
atand
dtare given constants. Obviously, the problem above can also be solved using DP-
methodology, though the recurrence relations would look somewhat more sophisticated than
(3.6)(3.8).
Next we consider an important special case of the problem: the Knapsack Problem.
3.1.1. Knapsack Problem
0-1 Knapsack Problem
Recall the problem. Given a capacityAand a set ofnitems, each item possesses a value
and a weight
ai. Find the subset of items such that its total value is maximal and its weight
c
does not exceedA. The mathematical programming formulation of the problem is given below:
n
ÿ
cixiÑ max
i“1
n
ÿ
aixiď A,
i“1
xPB
,
n
(3.9)
(3.10)
i

Distribution Problem
29
where a boolean variable
xiindicates whether thei-th item is chosen (
Similar to the above, consider a family of problems
Skpλq “ max
xPB
k
ÿ
i“1
Note that:
•
when a single item is available,
S1pλq “ 0
otherwise;
•ifk ą 1
•ifk ą 1,akď λ
easily calculated by comparing
and
aką λ
then thek-th item cannot be picked up and
, and the values
S
S
k´1
pµq
k´1
pλq
(thek-th item is rejected) and
(the item is accepted).
xi“ 1
) or not (
txk, λy : k “ 1, . . . , n, 0 ď λ ď Au
k
ÿ
cixi,
k
i“1
aixiď λ.
, if the item's weight exceedsλ, and
are known for each
Skpλq “ S
µ ď λ
, then
k´1
Skpλq
S
pλ ´ akq ` c
k´1
xi“ 0
:
S1pλq “ c
pλq
;
can be
).
1
k
These observations give us the recurrence relations:
"
0,
if
λ ă a1, px1pλq “ 0q,
if
λ ě a1, px1pλq “ 1q;
tckx ` S
pλ ´ akxqu, k “ 2, n, λ ď A.
k´1
are calculated, the backward pass is executed:
“ xnpAq,
“ x
˜
A ´
k
n
ÿ
i“k`1
aix
¸
˚
, k “ n ´ 1, 1.
i
aks andAare integers (otherwise we
Skpλq
should be calculated). In this case the time complexity
n ˆ A
table, each element of which is calculated
(3.11)
(3.12)
After all the
S1pλq “
Skpλq “ max
Skpλq
and
c1,
xPt0,1u, akxďλ
xkpλq
˚
x
n
˚
x
k
Note that the algorithm above is applicable if all the
don't know weightsλfor which
of the algorithm is
OpnAq
: we need to ll a
in constant time. Thus, the algorithm is pseudopolynomial (that is not surprising in view of
N P
-hardness of the problem).
Example 3.3.
Solve the program:
Fill a table with
Skpλq
and
10x1` 7x2` 25x3` 24x4Ñ max
2x1` x2` 6x3` 5x4ď 7.
xkpλq
using (3.11)(3.12).
xPB
,
4

30
Dynamic Programming
λ S1{x1S2{x2S3{x3S4{x
4
0 0/0 0/0 0/0
1 0/0 7/1 7/0
2 10/1 10/0 10/0
3 10/1 17/1 17/0
4 10/1 17/1 17/0
5 10/1 17/1 17/0
6 10/1 17/1 25/1
7 10/1 17/1 32/1 34/1
So, the optimum is
the rst three items must be at most
items 2 and 3 are rejected, and item 1 is chosen. Thus,
S4p7q “ 34
and the fourth item is chosen,
7 ´ a4“ 2
. From cells
p2, 3q,p2, 2q
x˚“ p1, 0, 0, 1q
x4p7q “ 1
. Hence, the weight of
, and
p2, 1q
we see that
.
Unbounded Knapsack Problem
In the problem (3.9)(3.10) we have exactly one copy of each item to put (or not put) into the
knapsack. Now consider the problem wherentypes
more than one item of each type. This problem is often referred as
Problem
.
n
ÿ
cixiÑ max
i“1
n
ÿ
aixiď A,
i“1
of items are available and we can choose
the Unbounded Knapsack
,
n
xPZ
`
(3.13)
(3.14)
here an integer variable
xidenotes the number of items of thei-th type we put into the knapsack.
It's obvious that slight modication of (3.11)(3.12):
Z
gives a
with
OpnAq
family
^
λ
Opn2Aq
S1pλq “ c
Skpλq “ max
1
xPZ`, akxďλ
-time algorithm for (3.13)(3.14). But the problem can be solved much easier,
, x1pλq “
a
1
tckx ` S
complexity. Instead of the two-parameter family
txαy : 0 ď α ď Au
, where
xαy
is:
Spαq “ max
Z
λ
a
1
pλ ´ akxqu, k “ 2, n, λ ď A,
k´1
xPZ
n
ÿ
aixiď α.
i“1
Theorem 3.1.
For the problem
xαy
, the following relation holds:
#
0, α ă minkak,
Spαq “
max
k: akďα
tSpα ´ akq ` cku,
^
;
txk, λyu
n
ÿ
cixi,
n
`
i“1
otherwise
, consider a one-parameter
.
(3.15)
Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]
