Changes between Version 2 and Version 3 of Documentation/Howto/Implement Genetic Programming Problems


Ignore:
Timestamp:
04/06/12 19:22:38 (8 years ago)
Author:
gkronber
Comment:

restructuring

Legend:

Unmodified
Added
Removed
Modified
  • Documentation/Howto/Implement Genetic Programming Problems

    v2 v3  
    7676}}}
    7777
    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.
     78With 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.
    7979
    8080 
     
    8282The 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.
    8383
    84 Left.cs:
     84==== Basic implementation of {{{Left}}} ====
    8585{{{
    8686#!csharp
     
    107107Since 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.
    108108
    109 Cloning pattern for symbol {{{Left}}}
     109==== Cloning pattern for {{{Left}}} ====
    110110{{{
    111111#!csharp
     
    123123To 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.
    124124
    125 {{{Left.cs}}} including cloning pattern and storable pattern.
     125==== Full implementation of {{{Left}}} ====
     126The following source code is the full implemenation of the symbol {{{Left}}} including the cloning pattern and the persistence pattern.
    126127{{{
    127128#!csharp
     
    165166
    166167
    167 {{{Prog.cs}}}
     168==== {{{Prog}}} ====
    168169{{{
    169170#!csharp
     
    196197}}}
    197198
    198 {{{Sum.cs}}}
     199==== {{{Sum}}} ====
    199200{{{
    200201#!csharp
     
    226227}}}
    227228
    228 {{{Frog.cs}}}
     229==== {{{Frog}}} ====
    229230{{{
    230231#!csharp
     
    256257}}}
    257258
    258 {{{Forward.cs}}}
     259==== {{{Forward}}} ====
    259260{{{
    260261#!csharp
     
    286287}}}
    287288
    288 {{{Constant.cs}}}
     289==== {{{Constant}}} ====
    289290{{{
    290291#!csharp
     
    322323As 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.
    323324
    324 {{{ConstantTreeNode.cs}}}
     325==== {{{ConstantTreeNode}}} ====
    325326{{{
    326327#!csharp
     
    459460First 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.
    460461
    461 {{{Interpreter.cs}}}
     462==== {{{Interpreter}}} ====
    462463{{{
    463464#!csharp
     
    604605}}}
    605606
    606 
    607 {{{Evaluator.cs}}}
     607In !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
     609An 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
     611All 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}}} ====
    608614{{{
    609615#!csharp
     
    894900}}}
    895901
     902==== First test run ====
    896903[[Image(lawn mower problem parameters.png)]]
    897904
     
    10931100
    10941101=== Solution View Classes ===
    1095 {{{SolutionProgramView.cs}}}
     1102
     1103==== {{{SolutionProgramView}}} ====
    10961104{{{
    10971105#!csharp
     
    11441152}}}
    11451153
     1154==== Lawn mower program screenshot ====
    11461155[[Image(lawn mower program view.png)]]
    11471156
    1148 {{{SolutionLawnView.cs}}}
     1157==== {{{SolutionLawnView}}} ====
    11491158{{{
    11501159#!csharp
     
    12251234}}}
    12261235
     1236==== Lawn mower solution screenshot ====
    12271237[[Image(lawn mower solution view.png)]]
    12281238