Source Code Cross Referenced for GameNodeValidator.java in  » Development » jgap » examples » gp » tictactoe » 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.gp.tictactoe 
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.gp.tictactoe;
011:
012:        import org.jgap.gp.impl.*;
013:        import org.jgap.gp.*;
014:        import org.jgap.gp.function.*;
015:
016:        /**
017:         * Validates evolved nodes for the Tic Tac Toe problem.
018:         *
019:         * @author Klaus Meffert
020:         * @since 3.2
021:         */
022:        public class GameNodeValidator implements  INodeValidator {
023:            /**
024:             * Validates a_node in the context of a_chrom during evolution. Considers the
025:             * recursion level (a_recursLevel), the type needed (a_type) for the node, the
026:             * functions available (a_functionSet) and the depth of the whole chromosome
027:             * needed (a_depth), and whether grow mode is used (a_grow is true) or not.
028:             *
029:             * @param a_chrom the chromosome that will contain the node, if valid (ignored
030:             * in this implementation)
031:             * @param a_node the node selected and to be validated
032:             * @param a_rootNode the root node of a_node, may be null for top nodes
033:             * @param a_tries number of times the validator has been called, useful for
034:             * stopping by returning true if the number exceeds a limit
035:             * @param a_num the chromosome's index in the individual of this chromosome
036:             * @param a_recurseLevel level of recursion, i.e. the depth of a node
037:             * @param a_type the return type of the node needed
038:             * @param a_functionSet the array of available functions (ignored in this
039:             * implementation)
040:             * @param a_depth the allowed remaining depth of the program chromosome
041:             * @param a_grow true: use grow mode, false: use full mode (ignored in this
042:             * implementation)
043:             * @param a_childIndex index of the child in the parent node to which it
044:             * belongs (-1 if node is root node)
045:             * @param a_fullProgram true: full program is available for evaluation
046:             * @return true: node is valid; false: node is invalid
047:             *
048:             * @author Klaus Meffert
049:             * @since 3.2
050:             */
051:            public boolean validate(ProgramChromosome a_chrom,
052:                    CommandGene a_node, CommandGene a_rootNode, int a_tries,
053:                    int a_num, int a_recurseLevel, Class a_type,
054:                    CommandGene[] a_functionSet, int a_depth, boolean a_grow,
055:                    int a_childIndex, boolean a_fullProgram) {
056:                // Guard to avoid endless validation.
057:                // ----------------------------------
058:                if (a_tries > 10) {
059:                    return true;
060:                }
061:                if (a_fullProgram) {
062:                    return true;
063:                }
064:                // Chromosome 1.
065:                // -------------
066:                if (a_num == 1) {
067:                    // Program must start with a loop.
068:                    // -------------------------------
069:                    if (a_recurseLevel == 0 && a_node.getClass() != Loop.class) {
070:                        return false;
071:                    }
072:                    if (a_recurseLevel == 1
073:                            && a_node.getClass() != EvaluateBoard.class) {
074:                        return false;
075:                    }
076:                }
077:                // Chromosome 2.
078:                // -------------
079:                if (a_num == 2) {
080:                    // SubProgram needed as root
081:                    if (a_recurseLevel == 0
082:                            && a_node.getClass() != SubProgram.class) {
083:                        return false;
084:                    }
085:                    // SubProgram forbidden other than at beginning
086:                    //      if (a_recurseLevel > 1 && a_node.getClass() == SubProgram.class) {
087:                    //        return false;
088:                    //      }
089:                    // EvaluateBoard forbidden other than under root node and as not-first
090:                    // child
091:                    if (a_recurseLevel > 1
092:                            && a_node.getClass() == EvaluateBoard.class
093:                            && a_childIndex > 0) {
094:                        return false;
095:                    }
096:                    if (a_recurseLevel == 1 && a_childIndex == 0
097:                            && a_node.getClass() != EvaluateBoard.class) {
098:                        return false;
099:                    }
100:                    if (a_rootNode != null
101:                            && a_rootNode.getClass() != SubProgram.class
102:                            && a_rootNode.getClass() != IfElse.class
103:                            && a_node.getClass() == IfElse.class
104:                            && a_childIndex <= 1) {
105:                        return false;
106:                    }
107:                    if (a_rootNode != null
108:                            && a_rootNode.getClass() != IfElse.class
109:                            && a_node.getClass() != Equals.class) {
110:                        return false;
111:                    }
112:                    // CountStones forbidden other than under SubProgram
113:                    //      if ( (a_rootNode == null || a_rootNode.getClass() != SubProgram.class) &&
114:                    //          a_node.getClass() == CountStones.class) {
115:                    //        return false;
116:                    //      }
117:                    // CountStones needed one under root
118:                    //      if (a_recurseLevel == 1 && a_node.getClass() != CountStones.class) {
119:                    //        return false;
120:                    //      }
121:                }
122:                // Chromosome 3.
123:                // -------------
124:                if (a_num == 3) {
125:                    if (a_recurseLevel == 0
126:                            && a_node.getClass() != PutStone1.class) {
127:                        return false;
128:                    }
129:                    if (a_recurseLevel == 1
130:                            && a_node.getClass() != ReadTerminalIndexed.class) {
131:                        return false;
132:                    }
133:                }
134:                return true;
135:            }
136:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.