Source Code Cross Referenced for MyRequestSplitStrategy.java in  » Development » jgap » examples » grid » mathProblemDistributed » 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 » Development » jgap » examples.grid.mathProblemDistributed 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is part of JGAP.
003:         *
004:         * JGAP offers a dual license model containing the LGPL as well as the MPL.
005:         *
006:         * For licencing information please see the file license.txt included with JGAP
007:         * or have a look at the top of class org.jgap.Chromosome which representatively
008:         * includes the JGAP license policy applicable for any file delivered with JGAP.
009:         */
010:        package examples.grid.mathProblemDistributed;
011:
012:        import org.jgap.*;
013:        import org.jgap.gp.*;
014:        import org.jgap.gp.impl.*;
015:        import org.jgap.distr.grid.gp.*;
016:
017:        /**
018:         * Sample implementation of IRequestSplitStrategy to split a single request
019:         * into multiple requests for workers.
020:         *
021:         * @author Klaus Meffert
022:         * @since 3.2
023:         */
024:        public class MyRequestSplitStrategy implements  IRequestSplitStrategyGP {
025:            /** String containing the CVS revision. Read out via reflection!*/
026:            private final static String CVS_REVISION = "$Revision: 1.3 $";
027:
028:            private GPConfiguration m_config;
029:
030:            public MyRequestSplitStrategy(GPConfiguration a_config) {
031:                m_config = a_config;
032:            }
033:
034:            public GPConfiguration getConfiguration() {
035:                return m_config;
036:            }
037:
038:            /**
039:             * Creates single requests to be sent to workers. Here, each request consists
040:             * of a number of chromosome from the original population (determined here)
041:             * plus the rest of the chromosomes to be initialized randomly at each worker.
042:             *
043:             * @param a_request the request to split
044:             * @return single requests to be computed by workers
045:             * @throws Exception
046:             *
047:             * @author Klaus Meffert
048:             * @since 3.2
049:             */
050:            public JGAPRequestGP[] split(JGAPRequestGP a_request)
051:                    throws Exception {
052:                GPPopulation pop = a_request.getPopulation();
053:                // Is evolution started the first time?
054:                // ------------------------------------
055:                boolean firstTime;
056:                if (pop == null || pop.size() < 1) {
057:                    firstTime = true;
058:                } else {
059:                    firstTime = false;
060:                }
061:                if (!firstTime) {
062:                    // Sort population to have the fittest individuals at the beginning.
063:                    // -----------------------------------------------------------------
064:                    pop.sortByFitness();
065:                }
066:                // Generate 20 work requests.
067:                // --------------------------
068:                int requests = 20; // number of requests to create
069:                JGAPRequestGP[] result = new JGAPRequestGP[requests];
070:                // Only send 10% of the population to the workers.
071:                // -----------------------------------------------
072:                int count = getConfiguration().getPopulationSize() / 10;
073:                for (int j = 0; j < requests; j++) {
074:                    result[j] = (JGAPRequestGP) a_request.newInstance(
075:                            "Population " + j, j);
076:                    // Setup JGAP configuration for worker.
077:                    // ------------------------------------
078:                    GPConfiguration config = getConfiguration().newInstanceGP(
079:                            j + "", "population " + j);
080:                    // Assemble population for one request.
081:                    // ------------------------------------
082:                    RandomGenerator rand = getConfiguration()
083:                            .getRandomGenerator();
084:                    GPPopulation workPop = new GPPopulation(config, count);
085:                    if (!firstTime) {
086:                        for (int i = 0; i < count; i++) {
087:                            IGPProgram chrom;
088:                            if (rand.nextDouble() > 0.2d) {
089:                                // Take one of the best chromosomes.
090:                                // ---------------------------------
091:                                chrom = pop.getGPProgram(i);
092:                            } else {
093:                                // Take one of the ordinary chromosomes.
094:                                // -------------------------------------
095:                                chrom = pop.getGPProgram(i + count);
096:                            }
097:                            workPop.setGPProgram(i, chrom);
098:                        }
099:                    }
100:                    result[j].setPopulation(workPop);
101:                }
102:                return result;
103:            }
104:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.