Source Code Cross Referenced for ClientEvolveStrategy.java in  » Development » jgap » examples » grid » fitnessDistributed » 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.fitnessDistributed 
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 licensing 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.fitnessDistributed;
011:
012:        import org.homedns.dade.jcgrid.client.*;
013:        import org.jgap.*;
014:        import org.jgap.distr.grid.*;
015:
016:        /**
017:         * Sample implementation of a strategy for evolving a generation on the client.
018:         *
019:         * @author Klaus Meffert
020:         * @since 3.2
021:         */
022:        public class ClientEvolveStrategy implements  IClientEvolveStrategy {
023:            /** String containing the CVS revision. Read out via reflection!*/
024:            public final static String CVS_REVISION = "$Revision: 1.3 $";
025:
026:            //  private GridClient m_gc;
027:
028:            private Configuration m_config;
029:
030:            private IClientFeedback m_clientFeedback;
031:
032:            private final int m_maxEvolutions = 3;
033:
034:            private Population m_pop;
035:
036:            /**
037:             * Default constructor is necessary here as it will be called dynamically!
038:             * Don't declare any other constructor as it will not be called!
039:             */
040:            public ClientEvolveStrategy() {
041:            }
042:
043:            /**
044:             * Called at the very beginning and only once before distributed evolution
045:             * starts.
046:             *
047:             * @param a_gc GridClient
048:             * @param a_config Configuration
049:             * @param a_clientFeedback IClientFeedback
050:             * @throws Exception
051:             *
052:             * @author Klaus Meffert
053:             * @since 3.2
054:             */
055:            public void initialize(GridClient a_gc, Configuration a_config,
056:                    IClientFeedback a_clientFeedback) throws Exception {
057:                m_clientFeedback = a_clientFeedback;
058:                m_config = a_config;
059:                //    m_gc = a_gc;
060:                // Initialize population randomly.
061:                // -------------------------------
062:                Genotype gen = Genotype.randomInitialGenotype(a_config);
063:                m_pop = gen.getPopulation();
064:            }
065:
066:            public void afterWorkRequestsSent() throws Exception {
067:                m_pop = new Population(m_config, m_config.getPopulationSize());
068:            }
069:
070:            public boolean isEvolutionFinished(int a_evolutionsDone) {
071:                // Do the complete evolution cycle 3 times.
072:                // ----------------------------------------
073:                if (a_evolutionsDone > m_maxEvolutions) {
074:                    return true;
075:                } else {
076:                    return false;
077:                }
078:            }
079:
080:            public void onFinished() {
081:                IChromosome best = m_pop.determineFittestChromosome();
082:                m_clientFeedback.info("Best solution evolved: " + best);
083:            }
084:
085:            public void evolve() throws Exception {
086:                // Do the evolution locally.
087:                // Note: It would be easy to also distribute this task.
088:                // ----------------------------------------------------
089:                Genotype gen = new Genotype(m_config, m_pop);
090:                gen.evolve();
091:                // Get back the evolved population for further evolutions
092:                // (see beginning of the iteration).
093:                // ------------------------------------------------------
094:                m_pop = gen.getPopulation();
095:            }
096:
097:            public JGAPRequest[] generateWorkRequests(JGAPRequest m_workReq,
098:                    IRequestSplitStrategy m_splitStrategy, Object data)
099:                    throws Exception {
100:                // Calculate fitness values of chromosomes.
101:                // Let each worker compute one fitness value.
102:                // ------------------------------------------
103:                JGAPRequest[] workList;
104:                m_workReq.setPopulation(m_pop);
105:                workList = m_splitStrategy.split(m_workReq);
106:                return workList;
107:            }
108:
109:            public void resultReceived(JGAPResult a_result) throws Exception {
110:                m_pop.addChromosomes(a_result.getPopulation());
111:            }
112:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.