1. Trang chủ
  2. » Thể loại khác

DSpace at VNU: Parallel generation of permutations by inversion vectors

4 70 1

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 4
Dung lượng 220,31 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

The first one is tasks dividing: 1 finding an inversion vector, and 2 determining a permutation from the just found inversion vector.. Based on the notion of inversion of a permutation

Trang 1

Parallel Generation of Permutations by Inversion Vectors

Hoang Chi Thanh Department of Computer Science VNU University of Science

334 - Nguyen Trai Rd., Thanh Xuan, Hanoi, Vietnam

Abstract: Permutations of a set are used in many practical problems

There are some algorithms for generating permutations of a set, e.g

a reverse alphabetical order algorithm, an algorithm based on

adjacent transpositions, an algorithm determining permutations

from their reductions… But these algorithms are rather long and

difficult to parallelize

In this paper we point out that the set of all permutations

of a set is isomorphic to the set of their inversion vectors Thus, we

construct a new algorithm determining permutations from their

inversion vectors The algorithm is simpler and shorter than

existing ones Furthermore, this algorithm is easy to parallelize

We parallelize the proposed algorithm by one of two

methods The first one is tasks dividing: 1) finding an inversion

vector, and 2) determining a permutation from the just found

inversion vector Two these tasks are performed in parallel with

equal computing amounts The second parallelizing method is based

on splitting the sequence of all desirable permutations into

subsequences and then concurrently generating the subsequences

Keywords: algorithm, inversion, parallel computing, permutation

I INTRODUCTION Permutations of a finite set are applied in many

areas of sciences and technologies, for example, the

scheduling problems, the control problems and the path

finding problems So modifying an exciting algorithm or

constructing a new algorithm to generate permutations are

attracted many researches [1-5,7-9] There are some

algorithms to generate permutations of a set, e.g a

reverse alphabetical order algorithm, an algorithm based

on adjacent transpositions…[2,4,8] Recently, J Ginsburg

constructed a method determining a permutation from its

set of reductions [1], M Monks reconstructed

permutations from cycle minors [4] and T Kuo proposed

a new method for generating permutations based on

factorial digits [3] But the above algorithms are rather

long and difficult to parallelize

Based on the notion of inversion of a

permutation [5], we propose a notion of inversion vector

and show that the inversion vector becomes a good

representation of permutations We construct a novel

algorithm generating permutations of a finite set by

inversion vectors The algorithm is short, simple and

highly possible to parallelize

We parallelize the proposed algorithm by one of

two methods The first one is tasks dividing: 1) finding an

inversion vector, and 2) determining a permutation from

the just found inversion vector Two these tasks are

performed in parallel with equal computing amounts The

second parallelizing method is based on splitting the

sequence of all desirable permutations into subsequences

and then generating the subsequences concurrently as

presented in [9-10] The obtained results take part in

developing the theory of computational combinatorics

and applying in practice

The organization of the rest of the paper is as

follows: In part 2 we recall the permutation problem,

propose a notion of inversion vector and consider the relationship between permutations and inversion vectors

A new algorithm generating permutations by inversion vector is constructed in the part 3 The part 4 is devoted two techniques for parallelizing the above presented algorithm Some developing directions are proposed in conclusion

II PERMUTATIONS OF A SET

Let X be a finite set A permutation of the set X

is a checklist of its all elements It is easy to see that each

permutation of the set X is a bijection from X to itself

2.1 Permutation problem

Given an n-element set X Find all permutations

of the set X

It is easy to show that the number of solutions is

n! The number of elements n is as big as great the time to find all solutions of the problem Identify X ≡ {1, 2, …, n} Let denote S n the set of all permutations of the n-element set X A permutation f ∈ S n can be represented by

a positive integer sequence of the length n as follows:

f = < f(1) f(2) … f(n) >, where f(i) ∈ X and f(i) ≠ f(j),

1 ≤ i ≠ j ≤ n For simplicity, the above sequence can be written as:

f = < a1 a2 a n >, where a i = f(i) , i = 1, 2, , n

In the sequence there is a pair of integers, the preceding is greater than following one Such a pair is an inversion of the permutation

Definition 2.1: A pair (a i , a j ), where i < j is called an inversion of the permutation < a1 a2 a n > iff a i > a j

The notion of inversion is used to determine the sign of a permutation [5,8] We use it to generate permutations

2.2 Inversion vector of a permutation

An inversion vector of a permutation is defined

as follows:

Definition 2.2: An n-dimension vector (d1, d2, , d n) is

called an inversion vector of the permutation < a1 a2

a n > iff d j = |{ i | i < j , a i > a j }| , j = 1, 2, , n

By definition, the coordinator d j is indeed the

number of components of the permutation, greater than a j

and to its left Note that following components do not effect the number of inversions of preceding ones

Example 2.3: The sequences of permutations and

inversion vectors of an 3-element set

No Permutations Inversion vectors

Trang 2

By Definition 2.2, the first coordinator d1 of an

inversion vector of any permutation always equals 0 (one

choice), the second coordinator d2 equals 0 or 1 (two

choices) H:

0 ≤ d j ≤ j - 1 , where j = 1, 2, , n (2.1)

Let denote N the set of all positive integers Set:

V n = { (d1, d2, , d n ) | d j ∈ N , 0 ≤ dj ≤ j - 1 ,

j = 1, 2, , n }

This is the set of all n-dimension integer vectors

satisfying (2.1) Of course: | V n | = n!

The relationship between the set of permutations

S n and the set of vectors V n is pointed out by the following

theorem

Theorem 2.1: The set S n is isomorphic to the set V n

Proof: Construct a mapping T : S n → Vn as follows:

∀ f = < a1 a2 a n > ∈ S n , T(f) = (d1, d2, , d n),

where (d1, d2, , d n) is the inversion vector of the

permutation <a1 a2 a n>

We show that the mapping T is a bijection

Because two sets S n and V n are finite and have

the same cardinality, so we show only that the mapping T

is injective

Assume that two following permutations have

the same inversion vector:

∃ < a1 a2 a n > , < b1 b2 b n > ∈ Sn :

(d1, d2, , d n ) = (d1, d2, , d n)

Due to d n = d n so both a n and b n are less than d n

elements in X Thus, a n = b n (= n - d n)

Remove a n and b nin the above permutations, we

get two permutations < a1 a2 a n-1 > , < b1 b2 b n-1 > of

the n-1 element set X \ {a n} that have the same inversion

vector (d1, d2, , d n-1 a) Repeat the above reasoning we

have: a n-1 = b n-1

Analogously, we show that: < a1 a2 a n > =

< b1 b2 b n > The two permutations are identical So the

mapping T is an injection

Thus, the number of inversion vectors of

permutations of a set is equal to the number of the

permutations In other words, each vector belonging to V n

is indeed an inversion vector of some permutation in S n

One used to represent a permutation of an

n-element set by a matrix of 2 rows and n columns or an

integer sequence with the length of n or a directed graph

of n nodes Theorem 2.1 points out that inversion vector

is a good representation of permutations

III PERMUTATIONS GENERATION

BY INVERSION VECTORS

Based on Theorem 2.1 we are able to construct a

new algorithm consisting of two steps, to generate all

permutations of an n-element set as follows:

1) Consequently generating inversion vectors in the

set V n

2) Determining a permutation corresponding to the

just found inversion vector

3.1 Generating inversion vectors

To perform the step 1 we consider each

inversion vector (d1, d2, , d n ) in the set V n as a word

d1 d2 d n on the alphabet N We sort these words in ascending by the alphabetical order (see Example 2.3)

So,

- The first inversion vector (the least) is

0 0 0 0 0, corresponding to the identical permutation

< 1 2 3 n-1 n >

- The last inversion vector (the most) is

0 1 2 n-2 n-1, corresponding to the permutation

< n n-1 n-2 2 1 >, that is the reverse of the identical

permutation

Assume that d = (d1, d2, , d n) is an inversion

vector We have to find an inversion vector d' = (d'1, d'2,

, d' n) next to the above inversion vector in the sorted sequence

By the alphabetical order, the vector d' is inherited a left part as long as possible of the vector d from the coordinator indexed 1 to the coordinator indexed k-1, where: k = max { j ⏐ d j < j - 1 } Then the coordinators indexed from 1 to k-1 are unchanged:

d' i = d i , i = 1, 2, , k-1;

The coordinators indexed from k to the last are determined as follows: d' k = d k + 1,

and d' i = 0 , i = k+1, k+2, , n

The step 1 terminates when all inversion vectors in V n

have been generated It means, when the last inversion

vector 0 1 2 n-2 n-1 was generated At that time, the variable: k = 0

This is a termination condition of this algorithm

3.2 Determining permutation from inversion vector

Let (d1, d2, , d n) be an inversion vector We

have to find a permutation < a1 a2 a n >, whose inversion

vector is the above vector All components a i (i = 1, 2, , n) of the permutation belong to the set X = {1, 2, …, n}

In order to determine the components, we use a list XS

represented by an integer array, that contains remaining

elements of the set X after each component selection Elements in the list XS are sorted in ascending First,

XS[i] = i , i = 1, 2, , n

As a n is less than d n elements in the list XS so:

a n = XS[n - d n]

Remove a n from XS and gather the list, we get a new n-1 element list Then, a n-1 = XS[n-1 - d n-1]

Repeat the above process until the list XS

becomes empty, we find all components of the

permutation < a1 a2 a n >

3.3 Algorithm generating permutation from inversion vector

Use an integer array D[1 n] to contain inversion vectors, an integer array F[1 n] for permutations and an integer variable l for the current length of the list XS

As the above analysis we construct a detail algorithm to generate permutations from inversion vectors

as follows

Algorithm 3.1 (Generating permutation from inversion

vector):

Input: A positive integer n

Output: A sequence of all permutations of the set {1, 2,

…, n}, their inversion vectors are sorted by ascending in

the alphabetical order

Trang 3

1 Begin

2 D[1 n] ← 0 ;

3 repeat

4 FIND_PER();

5 k ← n ;

6 while D[k] = k -1 do { D[k] ← 0 ; k ← k - 1 } ;

7 if k ≥ 2 then D[k] ← D[k] +1 ;

8 until k = 0 ;

9 End

10 Procedure FIND_PER() ;

11 begin

12 for i ← 1 to n do XS[i]  ← i ;

13 l ← n ;

14 for i ← n downto 1 do

15 { j ← l - D[i] ;

16 F[i] ← XS[j] ;

17 l ← l - 1 ;

18 for i ← j to l do XS[i] ← XS[i+1] ; }

19 print F[1 n] ;

20 end ;

Complexity of the algorithm:

To generate an inversion vector, the algorithm

executes two following steps:

- Instructions 5) - 7) determine a changing

position k and generates an inversion vector with the

complexity of O(n)

- Procedure FIND_PER() in instructions 10) -

20) determines and prints the corresponding permutation

by the procedure call 4) with the complexity of O(n.lg n)

So the complexity of a permutation generation is

O(n.lg n) The total complexity of Algorithm 3.1 is

O(n!.n.lg n)

The complexities of Algorithm 3.1, the reverse

alphabetical order algorithm and the algorithm based on

adjacent transpositions presented in [4,8] are the same

But Algorithm 3.1 is more simpler

IV PARALLEL ALGORITHM

FOR PERMUTATIONS GENERATION

Algorithm 3.1 may be parallelized by one of the

two following methods

4.1 Tasks dividing

Algorithm 3.1 consists of a main program and a

procedure FIND_PER() The execution of the procedure

does not depend on computation in the main program So,

the algorithm may be parallelized by dividing whole

computation into two parts (tasks), each part is executed

by a processor A processor P1 calculates the part

generating an inversion vector whilst another processor

P2 calculates the part determining a permutation from the

just found inversion vector

P1

1 Begin

2 D[1 n] ← 0 ;

3 repeat

4 FIND_PER();

5 k ← n ;

6 while D[k] = k -1 do

{ D[i] ← 0 ; k ← k -1 } ;

7 if k ≥ 2 then D[k] ← D[k] +1 ;

8 until k = 0 ;

9 End

P2

10 Procedure FIND_PER() ;

11 begin

12 for i ← 1 to n do XS[i] ← i ;

13 l ← n ;

14 for i ← n downto 1 do

15 { j ← l - D[i] ;

16 F[i] ← XS[j] ;

17 l ← l - 1 ;

18 for i ← j to l do

XS[i] ← XS[i+1] ; }

19 print F[1 n] ;

29 end ;

Communication between two processors P1 and

P2 is done by procedure call FIND_PER() in the

instruction 4) The two parts are executed in parallel on

two processors P1 and P2 The time for finding all permutations of a set reduces to a half

4.2 Splitting the sequence of inversion vectors

In order to execute the algorithm in parallel, we split the sequence of all desirable permutations into subsequences The number of subsequences depends on the number of calculating processors Let us split the

sequence of all permutations into m subsequences (m ≥ 2) The scheme of the parallel computing organization to find all permutations of a finite set is illustrated as the following figure

Fig 4.1 The scheme of the parallel computing organization to find

a set's permutations

In order to make the parallel computing organization realistic and optimal, the subsequences of permutations should be satisfied two following criteria: 1) It is easy to determine the input and the termination condition for the computing process of each subsequence

2) The difference of lengths of the subsequences is the less, the better

Of course, the input 1 is indeed the input of the problem and the last termination condition is the termination condition of the algorithm

The first criterion ensures that the splitting of permutations sequence is realistic In many cases, we can use (a part of) the input of the computing process for the

Trang 4

next subsequence as the termination condition of the

computing process for the previous subsequence The

second criterion implements the balance of computing to

processors Then the parallel computing processes

become optimal

To parallelize the new sequential algorithm

above presented for the permutation problem, we split the

sequence of all desirable inversion vectors into two

subsequences (m = 2) The pivot chosen as the inversion

vector at the beginning of the second subsequence is:

0 1 0 0 0 0 0 (4.1)

So, the last inversion vector of the first subsequence is:

0 0 2 3 4 n-2 n-1 (4.2)

It is easy to see that, the first subsequence

consists of all inversion vectors in V n, where two first

coordinators are 0 0, whilst the second one consists of all

inversion vectors in V n, where two first coordinators are

0 1 So these two subsequences have the same length

(n!/2) Thus, the length of subsequences of corresponding

permutations are equal

The instructions 5) - 6) determine a changing

position k on the inversion vector (4.2) at the end of the

first subsequence to be 2 So the termination condition for

the first computing process is:

k = 2 (instruction 8*)

The input for the second computing process is the

inversion vector (4.1) So we have to add an instruction:

2') D[2] ← 1 ;

Two following computing processes are

executed in parallel on two processors P1 and P2

1 Begin

2 D[1 n] ← 0 ;

3 repeat

4 FIND_PER();

5 k ← n ;

6 while D[k] = k -1 do

{ D[i] ← 0 ; k ← k -1 } ;

7 if k ≥ 2 then

D[k] ← D[k] +1 ;

8* until k = 2 ;

9 End

10 Procedure

FIND_PER() ;

11 begin

12 for i ← 1 to n do

XS[i] ← i ;

13 l ← n ;

14 for i ← n downto 1 do

15 { j ← l - D[i] ;

16 F[i] ← XS[j] ;

17 l ← l - 1 ;

18 for i ← j to l do

XS[i] ← XS[i+1] ; }

19 print F[1 n] ;

20 end ;

1 Begin

2 D[1 n] ← 0 ;

2' D[2] ← 1 ;

3 repeat

4 FIND_PER();

5 k ← n ;

6 while D[k] = k -1 do

{D[i] ← 0 ; k ← k -1} ;

7 if k ≥ 2 then

D[k] ← D[k] +1 ;

8 until k = 0 ;

9 End

10 Procedure

FIND_PER() ;

11 begin

12 for i ← 1 to n do XS[i] ← i ;

13 l ← n ;

14 for i ← n downto 1 do

15 { j ← l - D[i] ;

16 F[i] ← XS[j] ;

17 l ← l - 1 ;

18 for i ← j to l do

XS[i] ← XS[i+1] ; }

19 print F[1 n] ;

20 end ;

Generating permutations

of the first subsequence

Generating permutations

of the second subsequence

Thus, the time for finding all permutations of a set reduces to a half

The experimental results show that the above presented techniques have high performance These results take part in development of combinatorial computations and may be applied in practice

V CONCLUSION

In this paper, we propose a new algorithm to generate permutations of a finite set by inversion vectors

We also organize parallel computing for this algorithm by tasks dividing or splitting the sequence of all inversion vectors into subsequences as our new approach presented

in [9-10] Therefore, the amount of time required for finding all the permutations will be drastically decreased

by the number of subsequences The computing organization is an association of the bottom-up design and the divide and conquer one

The technique may be applied well in some other problems and algorithms We keep developing the parallelizing technique for those problems with a huge computing amount

The author would like to thank the Asia Research Center and the Korea Foundation for Advanced Studies as the sponsors for the research project

REFERENCES [1] J Ginsburg, Determining a permutation from its set of

reductions, Ars Combinatoria, No 82, 2007, pp 55-57

[2] S.M Johnson, Generation of permutations by adjacent

transpositions, Mathematics of Computation, No 17 (83),

1963, pp 282-285

[3] T Kuo, A new method for generating permutations in

lexicographic order, Journal of Science and Engineering

Technology, Vol 5, No 4, 2009, pp 21-20

[4] M Monks, Reconstructing permutations from cycle

minors, The Electronic Journal of Combinatorics, No 16,

2009, #R19

[5] W Lipski, Kombinatoryka dla programistów, WNT, Warszawa, 1982

[6] W Reisig, Petri Nets: An Introduction, Springer-Verlag,

1985

[7] J Steinhardt, Permutations with ascending and descending

blocks, The Electronic Journal of Combinatorics, No 17,

2010, #R14

[8] H.C Thanh, Combinatorics, VNU Hanoi Press,1999 (in Vietnamese)

[9] H.C Thanh, V.T Que, N.D Ham and D.T Ha, Parallelizing computation based on segments of solutions,

Proceedings of the 12 Vietnam National Conference on Information Technology, Natural Sciences and

Technology Press, Hanoi - 2010, pp 413-425

[10] H.C Thanh and N.Q Thanh, An efficient parallel

algorithm for the set partition problem, In "New

Challenges for Intelligent Information and Database Systems" (ACIIDS'2011, Daegu, Eds: N T Nguyen, B

Trawinski and J J Jung), Springer-Verlag, 2011, pp 25-32

Ngày đăng: 16/12/2017, 00:10