KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgrapht > experimental > permutation > PermutationFactory


1 /* ==========================================
2  * JGraphT : a free Java graph-theory library
3  * ==========================================
4  *
5  * Project Info: http://jgrapht.sourceforge.net/
6  * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
7  *
8  * (C) Copyright 2003-2006, by Barak Naveh and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 of the License, or
13  * (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this library; if not, write to the Free Software Foundation,
22  * Inc.,
23  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
24  */

25 /* -----------------
26  * PermutationFactory.java
27  * -----------------
28  * (C) Copyright 2005-2006, by Assaf Lehr and Contributors.
29  *
30  * Original Author: Assaf Lehr
31  * Contributor(s): -
32  *
33  * $Id: PermutationFactory.java 504 2006-07-03 02:37:26Z perfecthash $
34  *
35  * Changes
36  * -------
37  */

38 package org.jgrapht.experimental.permutation;
39
40 /**
41  * Factory to create Permutations of several types and use them as Enumerations.
42  * Note that callers may use them directly if they need to use special concrete
43  * methods.
44  *
45  * <p>These types are:
46  *
47  * <p>
48  * <li>All elements are different. There are N! possible permutations.
49  *
50  * <p><i>example:</i> source=[1,2,3]
51  * result=[1,2,3][1,3,2][2,1,3][2,3,1][3,1,2][3,2,1]
52  *
53  * <p>
54  * <li>Some of the elements are the same.
55  *
56  * <p><i>example:</i> source=[1,1,2] result=[1,1,2][1,2,1][2,1,1]
57  *
58  * <p>
59  * <li>There are separate permutations groups, which are connected to one
60  * sequence. Permutations are allowed only inside the group. Possible sequences:
61  * product of factorial of each group. see example.
62  *
63  * <p><i>example:</i> assume source=the groups are sizes are : 1,2,2,5 elements
64  * will be created: (1),(2,3),(4,5).
65  *
66  * <p>result=[1,(2,3),(4,5)] [1,(2,3),(5,4)] [1,(3,2),(5,4)] [1,(3,2),(4,5)]. In
67  * this example the number of possiblities is 1! x 2! x 2! = 4
68  *
69  * @author Assaf Lehr
70  * @since Jun 3, 2005
71  */

72 public class PermutationFactory
73 {
74
75     //~ Methods ---------------------------------------------------------------
76

77     public static ArrayPermutationsIter createRegular(int [] permSourceArray)
78     {
79         IntegerPermutationIter regularPerm =
80             new IntegerPermutationIter(permSourceArray);
81         return regularPerm;
82     }
83
84     /**
85      * For efficiency, try putting the biggest groups at the beggining of the
86      * array.
87      *
88      * @param groupSizesArray . example [3,2] will create an array (0,1,2)(3,4)
89      */

90     public static ArrayPermutationsIter createByGroups(
91         int [] groupSizesArray)
92     {
93         CompoundPermutationIter complexPerm =
94             new CompoundPermutationIter(groupSizesArray);
95         return complexPerm;
96     }
97 }
98
Popular Tags