Changes between Version 2 and Version 3 of Documentation/Howto/Implement Genetic Programming Problems
- Timestamp:
- 04/06/12 19:22:38 (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Documentation/Howto/Implement Genetic Programming Problems
v2 v3 76 76 }}} 77 77 78 With the {{{Plugin}} attribute we can add a name an description for the plug-in that is shown in the !HeuristicLab plug-in manager. Next we declare which files belong to the plug-in. In our case the plug-in consists only of the assembly {{{HeuristicLab.Problems.LawnMower-1.0.dll}}}. The {{{PluginDependency}}} attributes declare dependencies for this plug-in which is necessary for plug-in management. Each !HeuristicLab assembly that is referenced in our project must also be included as a plug-in dependencies.78 With the {{{Plugin}}} attribute we can add a name an description for the plug-in that is shown in the !HeuristicLab plug-in manager. Next we declare which files belong to the plug-in. In our case the plug-in consists only of the assembly {{{HeuristicLab.Problems.LawnMower-1.0.dll}}}. The {{{PluginDependency}}} attributes declare dependencies for this plug-in which is necessary for plug-in management. Each !HeuristicLab assembly that is referenced in our project must also be included as a plug-in dependencies. 79 79 80 80 … … 82 82 The next step for implementing GP problems is the implementation of the symbol classes. Symbols include both function and terminal symbols that can be used in the evolved GP solutions. 83 83 84 Left.cs: 84 ==== Basic implementation of {{{Left}}} ==== 85 85 {{{ 86 86 #!csharp … … 107 107 Since instances of symbols must be cloned it is necessary to implement the cloning functionality. In !HeuristicLab a common pattern is used for cloning in all clonable classes. The pattern involves overriding the {{{Clone()}}} method and implementing a cloning constructor. 108 108 109 Cloning pattern for symbol {{{Left}}} 109 ==== Cloning pattern for {{{Left}}} ==== 110 110 {{{ 111 111 #!csharp … … 123 123 To make it possible to store trees containing symbols to a file it is necessary to make two additional changes to the implementation of the {{{Left}}} symbol. In !HeuristicLab the classes of instances which are storable must be marked with the {{{[StorableClass]}}} attribute. Additionally, a storable constructor must be implemented which is marked with the {{{[StorableConstructor]}}} attribute. Any field or property that should be stored must be marked with a {{{[Storable]}}} attribute. However, in the left symbol there are no data that need to be stored. 124 124 125 {{{Left.cs}}} including cloning pattern and storable pattern. 125 ==== Full implementation of {{{Left}}} ==== 126 The following source code is the full implemenation of the symbol {{{Left}}} including the cloning pattern and the persistence pattern. 126 127 {{{ 127 128 #!csharp … … 165 166 166 167 167 {{{Prog.cs}}} 168 ==== {{{Prog}}} ==== 168 169 {{{ 169 170 #!csharp … … 196 197 }}} 197 198 198 {{{Sum.cs}}} 199 ==== {{{Sum}}} ==== 199 200 {{{ 200 201 #!csharp … … 226 227 }}} 227 228 228 {{{Frog.cs}}} 229 ==== {{{Frog}}} ==== 229 230 {{{ 230 231 #!csharp … … 256 257 }}} 257 258 258 {{{Forward.cs}}} 259 ==== {{{Forward}}} ==== 259 260 {{{ 260 261 #!csharp … … 286 287 }}} 287 288 288 {{{Constant.cs}}} 289 ==== {{{Constant}}} ==== 289 290 {{{ 290 291 #!csharp … … 322 323 As you can see in the implementation of the class {{{Constant}}}, there is another override for the method {{{CreateTreeNode()}}}. This override is necessary because we want to create a specific kind of tree nodes ({{{ConstantTreeNode}}}), which will hold the random integer vector. This is the first class that holds data which must be marked with the {{{[Storable]}}} attribute and cloned in the cloning constructor. 323 324 324 {{{ConstantTreeNode.cs}}} 325 ==== {{{ConstantTreeNode}}} ==== 325 326 {{{ 326 327 #!csharp … … 459 460 First let's look at the implementation of the {{{Interpreter}}}. The {{{Interpreter}}} is at the core of the lawn mower problem as it exactly describes how solution candidates are executed and which results they produce. The {{{Interpreter}}} should be implemented in an efficient way because it will be called repeatedly for solution evaluation and thus is at the critical point for performance optimization. The {{{Interpreter}}} is a simple class and not derived from any framework classes. It contains only static methods for the interpretation of trees. Thus, it is not necessary to mark it as a {{{[StorableClass]}}} and it is not necessary to implement the cloning pattern or the persistence pattern. 460 461 461 {{{Interpreter.cs}}} 462 ==== {{{Interpreter}}} ==== 462 463 {{{ 463 464 #!csharp … … 604 605 }}} 605 606 606 607 {{{Evaluator.cs}}} 607 In !HeuristicLab each problem must supply a fitness evaluation operator. This operator must derive from {{{ISingleObjectiveEvaluator}}} and we can use the base class {{{SingleSuccessorOperator}}} for all operators that can have a successor. The {{{Item}}} attribute can be used to set a name and description for the operator that is shown in the GUI. All operators must have the {{{StorableClass}}} attribute. 608 609 An operator can have multiple input and output parameters and to implement the {{{ISingleObjectiveEvaluator}}} interface at least a {{{QualityParameter}}} must be implemented. The evaluator also needs the tree representing the lawn moower program that it should evaluate and the length and width of the lawn to calculate the quality of the tree. 610 611 All of these parameters must have the type {{{LookupParameter<T>}}} because the values of these parameters are looked up in the scope on which the parameter is applied. 612 613 ==== {{{Evaluator}}} ==== 608 614 {{{ 609 615 #!csharp … … 894 900 }}} 895 901 902 ==== First test run ==== 896 903 [[Image(lawn mower problem parameters.png)]] 897 904 … … 1093 1100 1094 1101 === Solution View Classes === 1095 {{{SolutionProgramView.cs}}} 1102 1103 ==== {{{SolutionProgramView}}} ==== 1096 1104 {{{ 1097 1105 #!csharp … … 1144 1152 }}} 1145 1153 1154 ==== Lawn mower program screenshot ==== 1146 1155 [[Image(lawn mower program view.png)]] 1147 1156 1148 {{{SolutionLawnView.cs}}} 1157 ==== {{{SolutionLawnView}}} ==== 1149 1158 {{{ 1150 1159 #!csharp … … 1225 1234 }}} 1226 1235 1236 ==== Lawn mower solution screenshot ==== 1227 1237 [[Image(lawn mower solution view.png)]] 1228 1238