COMPUTATION OF THE SECOND MAXIMUM PATH WEIGHT IN A MAX-PLUS MATRIX

The problem of efficient computation of all second maximum path weights for a given square matrix A of dimension n in max-plus algebra is solved by computing so-called double power sequence of a specific extension Ā of A. An algorithm using this method is presented, by which the second maximum cycle mean value λ2(A) can be computed in O(n4) time.


INTRODUCTION
Matrix computations using binary operations of maximum and plus, in analogy to operation plus and times known in classical linear algebra, are often involved in optimization problems, see [2-5, 11, 17].Max-plus matrices are important in the study of discrete events systems (DES), see [3,4,11].The steady states of DES correspond to eigenvectors of max-plus matrices, and the periodical behavior of DES is reflected by so-called linear periodicity of the power sequence of the transient max-plus matrix, see [6,7,14,15].The eigenvalues of max-plus matrices are closely connected with the maximum (or dually: minimum) cycle mean, see [10,12].It has been shown in [13,16] that the linear pre-period of a max-plus matrix can be arbitrary long, regardless of the matrix dimension.For the estimation of the linear pre-period length of a given matrix, the values of the maximum cycle mean and the second maximum cycle mean in the associated digraph are important, see [8,9].
Closely related question of efficient computation of all second maximum path weights for a given square matrix A of dimension n in max-plus algebra is considered in this paper.The main tool for solving the problem are so-called double matrices and their multiplication.An algorithm for computing the second maximum cycle mean value λ 2 (A) in O(n 4 ) time is described in the last section.Similar problems using different approach were considered in [1,5].

NOTIONS AND NOTATION
By max-plus algebra we understand the set R * of all real numbers with added element ε = −∞, together with binary operation of maximum denoted as ⊕, and the operation of addition denoted as ⊗ (clearly, the element −∞ is absorbing in respect to the operation ⊗).We remark that the results in this paper remain valid in more general situation, when R * is substituted by arbitrary linearly ordered commutative and divisible group G in additive notation, with the least element absorbing in respect to the group operation.Then ⊕ and ⊗ are the operation of maximum and the group operation on G , respectively.
For a fixed natural number n we denote N = {1, 2, . . ., n}.The set of all n × n matrices (n-dimensional vectors) over R * is denoted by R * (n, n) (R * (n)).Matrix operations over R * are performed with respect to operations ⊕, ⊗ formally in the same way as matrix operations over any field.Thus for A, B ∈ R * (m, n) we define the sum The edges in G (A) are evaluated by the weight function w defined by the formula w(i, j) = a i j , and the weight w(p) of a path p = (p 0 , p 1 , . . ., p r ) of length |p| = r in G (A) is defined as the sum of all weights w(p i−1 , p i ) for i = 1, 2, . . ., r.The weight mean w(p) is computed by the formula w(p) = w(p)/r, for paths of positive length.
It has been proved in [4] that the maximum weight of all paths connecting node i with node j of a given length r for a matrix A in max-plus algebra can be found by computing the r th formal power A (r) of the matrix A as illustrated in the following example.For instance, if we are interested in finding the maximum weight of a path of length r = 3 from the node i = 2 to the node j = 3, then the maximum weight is represented by the element a (3) 23 = 6 in A (3) ,

Example 2.1 Input matrix
It can be easily seen in this simple example that the corresponding path with the maximum weight is the path (2, 3, 5, 3) (marked in digraph G (A) below by printing the arcs of the path and their weights in bold).Similarly, we can easily see that the path of length r = 3 from the node i = 2 to the node j = 3 with the second maximum weight is the path (2,3,4,3).Now a natural question arises: how can be the second maximum weight of all paths of a given length connecting a given node with another given node computed in general situation?The second maximum cycle mean (as well as the maximum cycle mean) is, namely, one of the tools to estimate the length of the non-periodic parth (the so-called pre-period) of a linear periodic matrix in max-plus algebra.

DOUBLE MATRIX
To answer the question put at the end of the previous paragraph, we start with extending the operation of finding the maximum element of a subset of R * to finding the two largest values.Definition 3.1 Let S ⊆ R * be a finite set.We define max 2 S = (s 1 , s 2 ) by setting s 1 = max S and s 2 = max(S \ {s 1 }).Lemma 3.1 Let be S ⊆ R * , max 2 S = (s 1 , s 2 ).Then the following statements hold true Proof.All statements in the lemma follow directly from Definition 3.1 and from the fact that maximum of the empty subset in R * is ε (i.e. the least element in R * ).
Main tool for computing the second maximum cycle mean value λ 2 (A) of a given square matrix over max-plus algebra is the notion of double matrix with a special operation of double matrix multiplication introduced in this section.

Definition 3.2 An ordered pair of matrices
and if1 a i j > 2 a i j , or 1 a i j = 2 a i j = ε, holds true for any i, j ∈ N. 1 A is the left-hand matrix of A and 2 A is the righthand matrix of Ā.The set of all double matrices of a fixed dimension n is denoted as for any i, j ∈ N.
The double max-plus multiplication of two double matrices results in a double matrix, as illustrated in the next example and proved in the following lemma.
Let us find the double product of the given matrices Ā ⊗ B = C.Using formulas (3.1) and (3.2) from Definition 3.2 the elements of the resulting matrix C can be computed.
It is necessary to show that for any i, j ∈ N, the condition 1 c i j > 2 c i j , or 1 c i j = 2 c i j = ε holds true.The condition follows immediately from the statements of Lemma 3.1, if we put S = S i j ( Ā, B), Double powers of a double matrix Ā ∈ D(n, n) are defined by recursion The equations (3.1) and (3.2) from Definition 3.2 turn for any i, j ∈ N to for r = 1, 2, . . . .

MATRIX EXTENSION
The matrix extension of a matrix A to a double matrix Ā is introduced in this section.An interpretation of the sequence of double powers of the matrix extension Ā of a given matrix A is described.
Any matrix A ∈ R * (n, n) can be formally extended to a double matrix Ā = ( 1 A, 2 A) ∈ D(n, n) by setting 1 A = A and 2 A = E with all input values in E equal to ε.Clearly, the condition 1 a i j > 2 a i j , or 1 a i j = 2 a i j = ε, is fulfilled for any i, j ∈ N.
In the computation of the sequence of double powers of a matrix extension we can use the fact that the righthand matrix of the matrix extension Ā consists of the values 2 a k j = ε.Hence, for matrix extensions the computation can be simplified, in comparison with the definition above, as follows: for r = 1, 2, . . . .
Let us find the power sequence of length 5 of the extension Ā of the given matrix .
The successive powers of Ā will be computed according to (4.1) and (4.2).For r = 1 i j , 2 a (2) ik + 1 a k j ; k = 1, 2, . . ., 5 , i j , 2 a (3) i j is the maximum weight of all paths in G (A) from i to j, of length r, i j is the second maximum weight of all paths in G (A) from i to j, of length r, (iii) if 1 a (r) i j > ε and2 a (r) i j = ε, then there is no path in G (A) from i to j, with weight less than 1 a (r) i j = ε and there is no path in G (A) from i to j, of length r.
Proof.The proof proceeds on recursion with respect to r.For r = 1 and for any i, j ∈ N there is exactly one path of length 1 from i to j in digraph G (A), if a i j > ε, and there is no such path, if a i j = ε.In the first case, the unique path consists of the single arc (i, j) and its weight is a i j , which is the maximum weight, while the second maximum weight is ε (maximum of the empty set).In the second case, when there is no arc from i to j in G (A), both the maximum and the second maximum weight are equal to ε.Notice that 2 a i j = ε by the definition of formal extension Ā, for all i, j.
Thus the assuption 2 a (r) Let us assume by recursion, that the statements (i), (ii), (iii) and (iv) are satisfied for some fixed value r.We shall prove that the statements are fulfilled also when r is replaced by r + 1.
(i) By the recursion assumption and by the definition of formal extension Ā, the equalities 1 a (r) .
By the well-known properties of matrix powers in max-plus algebra, a (r+1) i j is the maximum weight of a path in G (A) from i to j, of length r + 1.
(ii) Let us suppose that 1 a (r+1) i j > ε.In view of the computation in the previous part of the proof, there is a non- Using the definition of Ā, we have 1 a k j = a k j for all k ∈ N, hence we get By recursion assumption (ii), we have 1 a In view of the statement (i) proved above, the assumption 1 a > ε, i.e. in G (A) there exists a path from i to j, of length r + 1, with the maximum weight a (r+1) i j . Let us consider a path p with the second maximum weight from i to j, of length r + 1 (if such a path exists in G (A)).The path p consists of two shorter paths: a sub-path p from node i to some node k ∈ N, of length r, and an arc (k, j).Then w(p) = w(p ) + a k j .Clearly, 1 a (r) By assumption 2 a ik + a k j > ε.This implies, in view of the recursion assumption, that there exists a path p from i to j, of length r + 1 in G (A), with 1 a . Hence p has the second maximum weight and the statement (ii) holds true for r + 1.
(iii) The proof goes similarly as above, only by assumption 2 a (r+1) i j = ε we get that there is no path p from i to j, of length r + 1 in G (A), with 1 a (r+1) i j

> w(p).
(iv) The statement follows directly from Lemma 3.1.Theorem 4.1 answers the question posed at the end of Section 2: how to compute the second maximum weight of all paths of a given length connecting a given node with another given node in the digraph corresponding to a given matrix?In the next example we will find the second maximum weight of all paths of length r = 3 connecting node Example 4.2 Input matrix A ∈ R * (n, n), with n = 5, According to Theorem 4.1 we shall use the third power of the matrix extension of the given matrix.Since the considered matrix has been extended to a double matrix and the mentioned power has already been computed in Example 4.1, we can immediately find the answer.The second maximum weight of all paths of length r = 3 connecting node 2 with node 3 is represented by the element2 a The corresponding path with the second maximum weight is the path (2, 3, 4, 3) (marked in digraph G (A) below by printing the arcs of the path and their weights in bold).Since the cycle mean of a cycle can not exceed the cycle mean of its elementary subcycles, and since the number of elementary cycles is finite, λ (A) always exists.If there is no cycle of positive length, then λ (A) = ε.
When considering cycles of arbitrary length, we can create combinations of cycles with the maximum cycle mean λ (A) with cycles of lower cycle mean, and the cycle mean value of such combinations can be made arbitrarily close to λ (A).Hence, strictly speaking, the second maximum cycle mean value does not exist for cycles of unrestricted length.For that reason we restrict our investigation to cycles in G (A) with lengths not exceeding the dimension of the given square matrix A (which includes all elementary cycles).
The second maximum cycle mean in G (A) is denoted by If there is no cycle of positive length with w(c) < λ (A), then λ 2 (A) = ε.
Theorem 5.1 There is an algorithm which for every A ∈ R * (n, n) computes the second maximum cycle mean value λ 2 (A) in O(n 4 ) time.
Step 3.For every r = 1, 2, . . ., n compute the maximum and the second maximum mean value for cycles of length r in G (A) by formulas Let us compute the second maximum cycle mean value of all cycles of length at most 5.In the first and the second step of the algorithm the matrix extension Ā and the first five consecutive powers of Ā should be computed.The results of these computations can be found in Example 4.1, hence we can pass directly to the third step of the algorithm and compute the maximum and second maximum cycle mean value for cycles of length r = 1, 2, . . . 5 using the formula λ 2 (A) = max 2 { 2, 1 } = (2, 1) , λ 1 (A), λ 1 (A), λ

.
Next theorem describes the properties of the sequence of double powers of the extension Ā of a matrix A.

5 .
THE SECOND MAXIMUM CYCLE MEANThe previous results will be used in this section for computing the second maximum cycle mean value.In accordance with the notation introduced in Section 2, the weight w(c) of a cycle c in digraph G (A) is defined as the sum of the weights of all arcs in c.If the length of c is positive, then the ratio w(c) := w(c)/| c | is called the cycle mean.The maximum cycle mean in G (A) is denoted by λ (A) := max { w(c); c cycle in G (A) } .

Step 4 .Example 5 . 1
Compute the maximum mean value for cycles of any length and the second maximum mean value for cycles of length at most n in G (A)λ (A), λ 2 (A) = max 2 λ ); r = 1, 2, . . ., n .It is easy to verify that the computational complexity forStep 1 is O(n 2 ), for Step 2 the complexity is O(n 4 ) and for Steps 3, 4 again O(n 2 ).Hence, the whole computation is performed in O(n 4 ) time.The correctness of the algorithm follows from Lemma 3.1 and Theorem 4.1.Below, the algorithm is demonstrated on the input matrix A used in the previous examples.Input matrix A ∈ R * (n, n), with n = 5, ) = max 2 { ε } = (ε, ε) , λ