Source Code Cross Referenced for AntMap.java in  » Development » jgap » examples » gp » anttrail » 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.anttrail 
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.anttrail;
011:
012:        /**
013:         * Holds the map of the ant trail. Important: Clone intentionally not supported
014:         * here!
015:         *
016:         * @author Klaus Meffert
017:         * @since 3.01
018:         */
019:        public class AntMap {
020:            /** String containing the CVS revision. Read out via reflection!*/
021:            private final static String CVS_REVISION = "$Revision: 1.6 $";
022:
023:            // map point descriptions
024:            public static final int ERROR = 0;
025:
026:            public static final int FOOD = -1;
027:
028:            public static final int EMPTY = 1;
029:
030:            public static final int TRAIL = 2;
031:
032:            public static final int ATE = 3;
033:
034:            // orientations
035:            public static final int O_UP = 0;
036:
037:            public static final int O_LEFT = 1;
038:
039:            public static final int O_DOWN = 2;
040:
041:            public static final int O_RIGHT = 3;
042:
043:            private int m_orientation;
044:
045:            private int m_posx;
046:
047:            private int m_posy;
048:
049:            private int m_foodTaken;
050:
051:            /**
052:             * Number of moves proceeded.
053:             */
054:            private int m_moves;
055:
056:            /**
057:             * Width of map.
058:             */
059:            private int m_sizex;
060:
061:            /**
062:             * Height of map.
063:             */
064:            private int m_sizey;
065:
066:            /**
067:             * Holder of the trail's map.
068:             */
069:            private int[][] m_map;
070:
071:            /**
072:             * For displaying moves as a..za..z etc. (idea from ECJ).
073:             * Also see m_moveModUpper
074:             */
075:            private int m_moveMod;
076:
077:            /**
078:             * False: use lower case chars with m_moveMod. true: Use Upper case chars.
079:             */
080:            private boolean m_moveModUpper;
081:
082:            /**
083:             * Stores the moves done to display them later.
084:             */
085:            private int[][] m_movementMap;
086:
087:            /**
088:             * Maximum number of solutions allowed.
089:             */
090:            private int m_maxMoves;
091:
092:            public AntMap(final int[][] a_map, int a_maxMoves) {
093:                m_sizex = a_map.length;
094:                m_sizey = a_map[0].length;
095:                m_map = new int[m_sizex][m_sizey];
096:                for (int x = 0; x < m_sizex; x++) {
097:                    m_map[x] = (int[]) (a_map[x].clone());
098:                }
099:                m_movementMap = new int[m_sizex][m_sizey];
100:                /**@todo speedup possible by using string?*/
101:                m_orientation = O_RIGHT;
102:                m_posx = 0;
103:                m_posy = 0;
104:                m_moveMod = 0;
105:                m_moveModUpper = false;
106:                m_maxMoves = a_maxMoves;
107:                storeMove();
108:                m_moves = 0;
109:            }
110:
111:            public int[][] getMap() {
112:                return m_map;
113:            }
114:
115:            public int getFromMap(int a_x, int a_y) {
116:                return m_map[a_x][a_y];
117:            }
118:
119:            //  public void setInMap(int a_x, int a_y, int a_value) {
120:            //    m_map[a_x][a_y] = a_value;
121:            //  }
122:
123:            public int getPosX() {
124:                return m_posx;
125:            }
126:
127:            public int getPosY() {
128:                return m_posy;
129:            }
130:
131:            public void setPosX(int a_value) {
132:                m_posx = a_value;
133:                storeMove();
134:                checkFoodTaken();
135:            }
136:
137:            public void setPosY(int a_value) {
138:                m_posy = a_value;
139:                storeMove();
140:                checkFoodTaken();
141:            }
142:
143:            private void storeMove() {
144:                char c;
145:                if (!m_moveModUpper) {
146:                    c = (char) (m_moveMod + 'a');
147:                    if (m_moveMod++ >= 25) {
148:                        m_moveMod = 0;
149:                        m_moveModUpper = true;
150:                    }
151:                } else {
152:                    c = (char) (m_moveMod + 'A');
153:                    if (m_moveMod++ >= 25) {
154:                        m_moveMod = 0;
155:                        m_moveModUpper = false;
156:                    }
157:                }
158:                m_movementMap[m_posx][m_posy] = c;
159:            }
160:
161:            public int[][] getMovements() {
162:                return m_movementMap;
163:            }
164:
165:            private void checkFoodTaken() {
166:                if (m_map[m_posx][m_posy] == AntMap.FOOD) {
167:                    m_foodTaken++;
168:                    m_map[m_posx][m_posy] = AntMap.ATE;
169:                } else {
170:                    // Do nothing.
171:                    // -----------
172:                }
173:            }
174:
175:            public int getOrientation() {
176:                return m_orientation;
177:            }
178:
179:            public void setOrientation(int a_orientation) {
180:                m_orientation = a_orientation;
181:            }
182:
183:            public int getFoodTaken() {
184:                return m_foodTaken;
185:            }
186:
187:            public int getMoveCount() {
188:                return m_moves;
189:            }
190:
191:            public void IncrementMoveCounter() {
192:                m_moves++;
193:                if (m_moves > m_maxMoves) {
194:                    throw new IllegalStateException(
195:                            "Maximum number of moves exceeded");
196:                }
197:            }
198:
199:            public int getWidth() {
200:                return m_sizex;
201:            }
202:
203:            public int getHeight() {
204:                return m_sizey;
205:            }
206:
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.