Source Code Cross Referenced for MultiDimensionalSort.java in  » Science » weka » weka » classifiers » misc » monotone » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » weka » weka.classifiers.misc.monotone 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    This program is free software; you can redistribute it and/or modify
003:         *    it under the terms of the GNU General Public License as published by
004:         *    the Free Software Foundation; either version 2 of the License, or
005:         *    (at your option) any later version.
006:         *
007:         *    This program is distributed in the hope that it will be useful,
008:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
009:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
010:         *    GNU General Public License for more details.
011:         *
012:         *    You should have received a copy of the GNU General Public License
013:         *    along with this program; if not, write to the Free Software
014:         *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
015:         */
016:
017:        /*
018:         *    MultiDimensionalSort.java
019:         *    Copyright (C) 2004 Stijn Lievens
020:         *
021:         */
022:
023:        package weka.classifiers.misc.monotone;
024:
025:        import java.util.Arrays;
026:        import java.util.Comparator;
027:
028:        /** 
029:         * Class for doing multidimensional sorting, using an array of
030:         * <code> Comparator. </code>
031:         * The goal is to sort an array topologically.  If <code> o1 </code>
032:         * and <code> o2 </code> are two objects of the array <code> a, </code>
033:         * and for all valid indices <code> i </code> in the array <code> c </code>
034:         * if holds that <code> c[i].compare(o1,o2) &lt; 0 </code> then
035:         * <code> o1 </code> comes before <code> o2 </code> in the sorted array.
036:         * <p>
037:         * A typical is the sorting of vectors in an n-dimensional space,
038:         * where the ordering is determined by the product ordering.
039:         * </p>
040:         * <p>
041:         * This implementation is part of the master's thesis: "Studie
042:         * en implementatie van instantie-gebaseerde algoritmen voor gesuperviseerd
043:         * rangschikken", Stijn Lievens, Ghent University, 2004. 
044:         * </p>
045:         * 
046:         * @author Stijn Lievens (stijn.lievens@ugent.be)
047:         * @version $Revision: 1.1 $
048:         */
049:        public class MultiDimensionalSort {
050:
051:            /** 
052:             * Sort an array using different comparators.
053:             *
054:             * @param a the array to be sorted.  The sorted array is returned 
055:             * in the array <code> a </code> itself.
056:             * @param c an array holding the different comparators
057:             */
058:            public static void multiDimensionalSort(Object[] a, Comparator[] c) {
059:                multiDimensionalSort(a, 0, a.length, c);
060:            }
061:
062:            /** 
063:             * Sort part of an array using different comparators.
064:             * 
065:             * @param a the array to be sorted, the indicated part of the array will
066:             * be replaced by the sorted elements
067:             * @param fromIndex index of the first element to be sorted (inclusive)
068:             * @param toIndex index of the last element to be sorted (exclusive)
069:             * @param c array holding the different comparators
070:             * @throws IllegalArgumentException if <code> fromIndex &gt; toIndex </code>
071:             */
072:            public static void multiDimensionalSort(Object[] a, int fromIndex,
073:                    int toIndex, Comparator[] c)
074:                    throws IllegalArgumentException {
075:
076:                if (fromIndex > toIndex) {
077:                    throw new IllegalArgumentException(
078:                            "Illegal range: fromIndex can be at most toIndex");
079:                }
080:                multiDimensionalSort(a, fromIndex, toIndex, c, 0);
081:            }
082:
083:            /**
084:             * Do the actual sorting in a recursive way.
085:             * 
086:             * @param a the array to be sorted, the indicated part of the array will
087:             * be replaced by the sorted elements
088:             * @param fromIndex index of the first element to be sorted (inclusive)
089:             * @param toIndex index of the last element to be sorted (exclusive)
090:             * @param c array holding the different comparators
091:             * @param depth the index of the comparator to use
092:             */
093:            private static void multiDimensionalSort(Object[] a, int fromIndex,
094:                    int toIndex, Comparator[] c, int depth) {
095:
096:                if (depth == c.length) {
097:                    return; // maximum depth reached
098:                }
099:
100:                Comparator comp = c[depth]; // comparator to use
101:                Arrays.sort(a, fromIndex, toIndex, comp); // sort part of the array 
102:
103:                // look for breakpoints in the array and sort recursively
104:                int mark = fromIndex;
105:                for (int i = fromIndex + 1; i < toIndex; i++) {
106:                    if (comp.compare(a[i - 1], a[i]) != 0) {
107:                        // a[i] is different from a[i-1], breakpoint detected
108:                        multiDimensionalSort(a, mark, i, c, depth + 1);
109:                        mark = i;
110:                    }
111:                }
112:                // sort the last part 
113:                multiDimensionalSort(a, mark, toIndex, c, depth + 1);
114:            }
115:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.