Source Code Cross Referenced for EvolveJob.java in  » Development » jgap » org » jgap » impl » job » 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 » org.jgap.impl.job 
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 org.jgap.impl.job;
011:
012:        import org.jgap.*;
013:        import org.jgap.*;
014:        import java.util.*;
015:
016:        /**
017:         * A job that evolves a population. The evolution takes place as given by the
018:         * configuration. It operates on a population also provided.
019:         * This class utilizes sub jobs to perform its sub-tasks. Each sub job may
020:         * either be a local implementation satisfying the IJob interface. Or it may be
021:         * a job that eventually is put onto the grid and returns with a result!
022:         *
023:         * @author Klaus Meffert
024:         * @since 3.2
025:         */
026:        public class EvolveJob extends JobBase implements  IEvolveJob {
027:            /** String containing the CVS revision. Read out via reflection!*/
028:            private final static String CVS_REVISION = "$Revision: 1.12 $";
029:
030:            public EvolveJob(JobData a_data) {
031:                super (a_data);
032:            }
033:
034:            /**
035:             * Execute the evolution via JGAP.
036:             *
037:             * @param a_data input parameter of type EvolveData
038:             * @return result of the evolution
039:             *
040:             * @throws Exception in case of any error
041:             *
042:             * @author Klaus Meffert
043:             * @since 3.2
044:             */
045:            public JobResult execute(JobData a_data) throws Exception {
046:                EvolveData data = (EvolveData) a_data;
047:                return evolve(data);
048:            }
049:
050:            /**
051:             * Does the genetic evolution.
052:             *
053:             * @param a_evolveData parameters for the evolution
054:             * @return result of the evolution
055:             *
056:             * @author Klaus Meffert
057:             * @since 3.2
058:             */
059:            public EvolveResult evolve(EvolveData a_evolveData) {
060:                EvolveResult result = new EvolveResult();
061:                Configuration config = a_evolveData.getConfiguration();
062:                result.setConfiguration(config);
063:                Population pop = a_evolveData.getPopulation();
064:                // Breed a new population by performing evolution.
065:                // -----------------------------------------------
066:                IBreeder breeder = a_evolveData.getBreeder();
067:                pop = breeder.evolve(pop, config);
068:                //
069:                result.setPopulation(pop);
070:                return result;
071:            }
072:
073:            /**
074:             * Applies all NaturalSelectors registered with the Configuration.
075:             *
076:             * @param a_processBeforeGeneticOperators true apply NaturalSelectors
077:             * applicable before GeneticOperators, false: apply the ones applicable
078:             * after GeneticOperators
079:             *
080:             * @author Klaus Meffert
081:             * @since 3.2
082:             */
083:            protected Population applyNaturalSelectors(Configuration a_config,
084:                    Population a_pop, boolean a_processBeforeGeneticOperators) {
085:                /**@todo optionally use working pool*/
086:                try {
087:                    // Process all natural selectors applicable before executing the
088:                    // genetic operators (reproduction, crossing over, mutation...).
089:                    // -------------------------------------------------------------
090:                    int selectorSize = a_config
091:                            .getNaturalSelectorsSize(a_processBeforeGeneticOperators);
092:                    if (selectorSize > 0) {
093:                        int m_population_size = a_config.getPopulationSize();
094:                        int m_single_selection_size;
095:                        Population new_population = new Population(a_config,
096:                                m_population_size);
097:                        NaturalSelector selector;
098:                        // Repopulate the population of chromosomes with those selected
099:                        // by the natural selector. Iterate over all natural selectors.
100:                        // ------------------------------------------------------------
101:                        for (int i = 0; i < selectorSize; i++) {
102:                            selector = a_config.getNaturalSelector(
103:                                    a_processBeforeGeneticOperators, i);
104:                            if (i == selectorSize - 1 && i > 0) {
105:                                // Ensure the last NaturalSelector adds the remaining Chromosomes.
106:                                // ---------------------------------------------------------------
107:                                m_single_selection_size = m_population_size
108:                                        - a_pop.size();
109:                            } else {
110:                                m_single_selection_size = m_population_size
111:                                        / selectorSize;
112:                            }
113:                            // Do selection of chromosomes.
114:                            // ----------------------------
115:                            /**@todo utilize jobs: integrate job into NaturalSelector!*/
116:                            selector.select(m_single_selection_size, a_pop,
117:                                    new_population);
118:                            // Clean up the natural selector.
119:                            // ------------------------------
120:                            selector.empty();
121:                        }
122:                        //        Population result = new Population(a_config);
123:                        //        result.addChromosomes(new_population);
124:                        return new_population;
125:                    } else {
126:                        return a_pop;
127:                    }
128:                } catch (InvalidConfigurationException iex) {
129:                    // This exception should never be reached
130:                    throw new IllegalStateException(iex.getMessage());
131:                }
132:            }
133:
134:            /**
135:             * Applies all GeneticOperators registered with the Configuration.
136:             *
137:             * @author Klaus Meffert
138:             * @since 3.2
139:             */
140:            protected void applyGeneticOperators(Configuration a_config,
141:                    Population a_pop) {
142:                List geneticOperators = a_config.getGeneticOperators();
143:                Iterator operatorIterator = geneticOperators.iterator();
144:                while (operatorIterator.hasNext()) {
145:                    GeneticOperator operator = (GeneticOperator) operatorIterator
146:                            .next();
147:                    /**@todo utilize jobs: integrate job into GeneticOperator*/
148:                    operator.operate(a_pop, a_pop.getChromosomes());
149:                }
150:            }
151:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.