Source Code Cross Referenced for GPProblem.java in  » Development » jgap » org » jgap » gp » 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.gp 
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.gp;
011:
012:        import java.io.*;
013:
014:        import java.awt.*;
015:        import javax.swing.tree.*;
016:
017:        import org.jgap.*;
018:        import org.jgap.gp.function.*;
019:        import org.jgap.gp.impl.*;
020:        import org.jgap.util.tree.*;
021:
022:        /**
023:         * Abstract base class for all GP problems. See package examples.gp for sample
024:         * implementations.
025:         *
026:         * @author Klaus Meffert
027:         * @since 3.0
028:         */
029:        public abstract class GPProblem {
030:            /** String containing the CVS revision. Read out via reflection!*/
031:            private final static String CVS_REVISION = "$Revision: 1.6 $";
032:
033:            private GPConfiguration m_conf;
034:
035:            public GPProblem(GPConfiguration a_conf)
036:                    throws InvalidConfigurationException {
037:                if (a_conf == null) {
038:                    throw new InvalidConfigurationException(
039:                            "Configuration must not be null!");
040:                }
041:                m_conf = a_conf;
042:            }
043:
044:            /**
045:             * Default constructor for dynamic instantiation.
046:             *
047:             * @author Klaus Meffert
048:             * @since 3.2
049:             */
050:            public GPProblem() {
051:
052:            }
053:
054:            /**
055:             * @return newly created GPGenotype
056:             * @throws InvalidConfigurationException
057:             *
058:             * @author Klaus Meffert
059:             * @since 3.0
060:             */
061:            public abstract GPGenotype create()
062:                    throws InvalidConfigurationException;
063:
064:            /**
065:             * Creates a tree out of a given GP program and saves it to a file.
066:             *
067:             * @param a_prog the GP program to visualize a tree for
068:             * @param a_filename the name of the file to save the tree in
069:             * @throws InvalidConfigurationException
070:             *
071:             * @author Klaus Meffert
072:             * @since 3.0
073:             */
074:            public void showTree(IGPProgram a_prog, String a_filename)
075:                    throws InvalidConfigurationException {
076:                if (a_prog == null) {
077:                    return;
078:                }
079:                TreeNode myTree = createTree(a_prog);
080:                if (myTree == null) {
081:                    return;
082:                }
083:                TreeVisualizer tv = new TreeVisualizer();
084:                tv.setTreeBranchRenderer(new JGAPTreeBranchRenderer());
085:                tv.setTreeNodeRenderer(new JGAPTreeNodeRenderer());
086:                tv.setBranchStartWidth(18.0);
087:                tv.setArenaColor(Color.black);
088:                tv.setBkgndColor(Color.black); //new Color(10, 10, 10));
089:                tv.setRenderNodes(true);
090:                tv.setSide(1024);
091:                tv.setCircleDiminishFactor(0.5);
092:                tv.writeImageFile(tv.renderTree(myTree), new File(a_filename));
093:            }
094:
095:            /**
096:             * Creates a tree out of a given GP program and saves it to a file. Allows to
097:             * preset the tree renderers.
098:             *
099:             * @param a_prog the GP program to visualize a tree for
100:             * @param a_filename the name of the file to save the tree in
101:             * @param a_treeBranchRenderer renderer for the tree's branches
102:             * @param a_treeNodeRenderer renderer for the tree's nodes
103:             * @throws InvalidConfigurationException
104:             *
105:             * @author Klaus Meffert
106:             * @since 3.0
107:             */
108:            public void showTree(IGPProgram a_prog, String a_filename,
109:                    TreeBranchRenderer a_treeBranchRenderer,
110:                    TreeNodeRenderer a_treeNodeRenderer)
111:                    throws InvalidConfigurationException {
112:                TreeNode myTree = createTree(a_prog);
113:                if (myTree == null) {
114:                    return;
115:                }
116:                TreeVisualizer tv = new TreeVisualizer();
117:                tv.setTreeBranchRenderer(a_treeBranchRenderer);
118:                tv.setTreeNodeRenderer(a_treeNodeRenderer);
119:                tv.setBranchStartWidth(18.0);
120:                tv.setArenaColor(Color.black);
121:                tv.setBkgndColor(Color.black); //new Color(10, 10, 10));
122:                tv.setRenderNodes(true);
123:                tv.setSide(1024);
124:                tv.setCircleDiminishFactor(0.5);
125:                tv.writeImageFile(tv.renderTree(myTree), new File(a_filename));
126:            }
127:
128:            /**
129:             * Creates a tree out of a given GP program.
130:             *
131:             * @param a_prog the GPGenotype to visualize a tree for
132:             * @return the TreeNode object corresponding to the GP program
133:             * @throws InvalidConfigurationException
134:             *
135:             * @author Klaus Meffert
136:             * @since 3.0
137:             */
138:            public TreeNode createTree(IGPProgram a_prog)
139:                    throws InvalidConfigurationException {
140:                if (a_prog == null) {
141:                    return null;
142:                }
143:                ProgramChromosome master = new ProgramChromosome(m_conf);
144:                master.setIndividual(a_prog);
145:                TreeNode tree;
146:                if (a_prog.size() > 1) {
147:                    Class[] types = new Class[a_prog.size()];
148:                    for (int i = 0; i < a_prog.size(); i++) {
149:                        types[i] = CommandGene.VoidClass; //arbitrary
150:                    }
151:                    master.setGene(0, new SubProgram(m_conf, types));
152:                    int index = 1;
153:                    for (int i = 0; i < a_prog.size(); i++) {
154:                        ProgramChromosome child = a_prog.getChromosome(i);
155:                        for (int j = 0; j < child.size(); j++) {
156:                            master.setGene(index++, child.getGene(j));
157:                        }
158:                    }
159:                    master.redepth();
160:                    tree = new JGAPTreeNode(master, 0);
161:                } else {
162:                    tree = new JGAPTreeNode(a_prog.getChromosome(0), 0);
163:                }
164:                return tree;
165:            }
166:
167:            /**
168:             * @return the GPConfiguration set
169:             *
170:             * @author Klaus Meffert
171:             * @since 3.0
172:             */
173:            public GPConfiguration getGPConfiguration() {
174:                return m_conf;
175:            }
176:
177:            /**
178:             * Sets the configuration. Only use in case of dynamic instantiation (in case
179:             * constructor with parameter GPConfiguration is not used).
180:             *
181:             * @param a_conf the configuration to set
182:             *
183:             * @author Klaus Meffert
184:             * @since 3.2
185:             */
186:            protected void setGPConfiguration(GPConfiguration a_conf) {
187:                m_conf = a_conf;
188:            }
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.