• Nem Talált Eredményt

III. ORGANIZATION OF THE PACKAGE

2. SOME FAMOUS PROBLEMS

2.1 The shortest route problem

Let a graph F=(VaE) be given without loops and multiple edges, where V denotes the set of vertices and E is the set of the edges of F. The length of every edge is known. The problem is to find the shortest route in the graph between the vertices A and B.

One of the well-known methods to solve this problem is based on dynamic programming (Bellman [l]). If we have a

shortest route between A and B and this route goes through the vertices C and D, then the subroute with the endpoints C and D is a shortest route between C and D. We determine the shortest route from A to every vertex. Thus we shall have the desired route as well. Notice that in this way it is suffi­

cient to give to every vertex W the point from which we go to W. From this information every route can be reconstructed.

Assume that the graph has n vertices, denoted by the po­

sitive integers from 1 to n. The starting point is vertex 1.

Now the system of the routes can be given by an n dimensional vector V, where v . is the vertex in the route containing j just

11

before j. If v .=0 then we still have no route yet from 1 to j . Obviously the number of all possible vectors v is exp (n).

Let i and j be two vertices. If the (i3j) edge is in the graph then let c . . be the length of the edge. Let m be a

í-J

sufficiently large number, e.g.

m _> £ c . .+ 1

(i,j)9E

For a given vector v_ let k be the vector of costs of the routes. If v .=0 then k .=m. If (i.j)0E then let e.Fm. The

3 3 ^3

cost k. can be obtained trivially from the recursive formula:

k . = c . + k

3 V . 3 V .

Now we have to give the set S(v_) and the function g(v).

Let S(v_) be the set of such vectors which differs from v_ in only one component i.e.

S(v_) = f w_ :3 l<l<n;

w . = v Q0 1

3 3

' }

The number of the neighbours of an arbitrary vector v is (n-1)2.

We choose function g(v_) as the total cost of the route, i.e.

n

g (v J = Z k

..

3 = 2 J

In the definition of the set G we shall insist on the strict inequality

(2 ) g(w) < g(v_k)

as here we minimize the costs, therefore we minimize the function g(v_) 3 too. An arbitrary better solution will be

choosen from G. The starting point (i.e. STEP 1 of the method) is the following:

114

S T E P 1 : i f ( 1 3 j ) G E t h e n

3 > 2,

v .=1. otherwise v .=0

3 3

Remember that if (13q)0E then .=m and so U

k .

3 m,

too.

Condition (2) is used in the definition of the set G. It is equivalent to the following constraints:

(3) 3U,o)GE

(4) k . + a . . < k .

t ^3 3

Formally we do not need Constraint (3).

Namely if (i3j)0E3 then o . .=m and hence i'3

k • + c . . == k . + m > k ..

^ z = 3

If (4) is true then

v. 1 i.

Otherwise

k . + a . . — k + c . = k .

^ v. V .3 3

«7 J

The equivalence of Condition (2) and Constraints (3) and (4) are based on the well-known fact, that the numbers k. give

3

a decreasing sequence. Constraints (3) and (4) give the usual way of the definition of set G.

In this treatment of the method an administrative substep is necessary in STEP 3. Namely if we have an improvement in

k . for a certain j then it can give improvement at other

Johnson's method is the following:

Suppose, that we have already optimal starting and finishing subsequences, but there are jobs for which the optimal order first element of the finishing subsequence. Jonhson proved the optimality of the procedure in [3J .

From the proof it is obvious that in an arbitrary order we can exchange the order of two jobs which are after each other and their order relatively to each other is bad accor­

ding to Johnson's method. With the repeated application of this fact the position of certain jobs can be exchanged to many places. This gives the idea for the following treatment of the method. The points are the different orders of the n jobs. This set is denoted by P. The neighbourhood of a given order

- 116

0

S(0) = {R: RGP; '^(k3m) indices R = (i a.

J Zki m 'k+1■ J m-13% 1s -1 J m+13 "73 • • •3^3 )}

n Of course in the definition of S(0) we regard both of the cases

k<m and k>m . The number of neighbours of an arbitrary order 0 is n(n-l). The function g(0) is the total processing time. We want to minimize it, therefore we use in the definition of the set G the inequality

g(R) < g(0k)

The starting point is an arbitrary order: namely the ar- tifical order of the indices. Johnson's method gives a special rule for the choice of from G. But according to what we have said previously we need not know Johnson's result, the local optimum is a global optimum.

2.3 The greedy algorithm

Let J be a set of n elements and M a system of the subsets of N with the following property: for any AGM if B*^A then BGM.

Every element p of N has a positive value: v (p)_. The value of a set A is the sum of the value of its elements:

v(A) = E v(p).

pGA

The problem is to find the set in M with the greatest value.

To solve the problem we have the following heuristic method.

Suppose that the elements öf N are in such an order that v(p~) > v(pn) > ... > v(p )

r 1 = ^ 2 = = r n

Then the greedy method is as follows:

STEP 1: A=0 i—1

STEP 2: if A V i p ^ G M then A: = AV{p .}

STEP 3: i = i+1

The method is called greedy because in every step we choose the most valuable element of N that we are allowed to

From the properties of M it follows that if p was not good then we cannot choose it at all (keeping the previous elements of N in the set ,4). Therefore the algorithms has at most n steps.

It is very easy to see that the method is only a heuristic algorithm. For example the well-known knapsack problem belongs to this problem class. But it is well-known that if M is a matroid then the greedy method gives always an optimal solution.

On the other hand the method is based on the neighbour­

hood. The starting point is the empty set. The neighbours of the set A are the sets which contain A and have one element more than A. Finally the function g is defined by the func­

tion v in the following way:

if i = n then go to STEP 2 else the algorithm is finished.

choose.

CO if A0M

118