Free cookie consent management tool by TermsFeed Policy Generator

Changes between Version 5 and Version 6 of Documentation/Howto/Implement a Basic Algorithm


Ignore:
Timestamp:
03/21/12 14:12:16 (13 years ago)
Author:
ascheibe
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Documentation/Howto/Implement a Basic Algorithm

    v5 v6  
    1414The last operator is the !ResultsCollector which collects the value of our !ResultValue. This value can then be viewed in !HeuristicLab Optimizer in the results tab.
    1515
    16 It is often a good idea to model algorithms first graphically in !HeuristicLab because it is easier and allows for more flexibility to play around with different ideas. You can find the HL file for this graphically modeled algorithm in the attachment section of this page. Have a look at the Operator Graph view and you will find the operator graph from the screenshot above. You can now simply click the Play button and it will give you a random number in the results tab.
     16It is often a good idea to model algorithms first graphically in !HeuristicLab because it is easier and allows for more flexibility when playing around with different ideas. You can find the HL file for this graphically modeled algorithm in the attachment section of this page. Have a look at the Operator Graph view and you will find the operator graph from the screenshot above. You can now simply click the Play button and it will give you a random number in the Results tab.
    1717
    1818=== Implementation ===
    19 Because we want create the same algorithm now in code, we create a new class in your !HeuristicLab plugin and call it {{{RandomAlgorithm}}}.
     19Because we want to roughly create the same algorithm now in code, we create a new class in your !HeuristicLab plugin and call it {{{RandomAlgorithm}}}.
    2020Before we can actually implement our algorithm, we have to first add references to some plugins that we need. Add the following references (just as you added the reference to Plugin Infrastructure):
    2121
     
    5050}}}
    5151
    52 Now we can start implementing the algorithm. The first thing that we do is inherit {{{RandomAlgorithm}}} from {{{EngineAlgorithm}}}. There are various base classes for different types of algorithm, e.g. a special type for heuristic algorithms. As we are not writing a new meta-heuristic, {{{EngineAlgorithm}}} should be sufficient. We also add two attributes to our class: The Item attribute contains some meta information about our algorithm, the Creatable attribute is the category of the class we are writing. This attribute is later responsible that we see our algorithm in the File->New dialog in HL. Here is the code so far:
     52Now we can start implementing the algorithm. The first thing that we do is inherit {{{RandomAlgorithm}}} from {{{EngineAlgorithm}}}. There are various base classes for different types of algorithms, e.g. there is a special type for heuristic algorithms. As we are not writing a new meta-heuristic, {{{EngineAlgorithm}}} should be sufficient. We also add two attributes to our class: The Item attribute contains some meta information about our algorithm, the Creatable attribute is the category of the class we are writing. This attribute is later responsible that we see our algorithm in the File->New dialog in HL. Here is the code so far:
    5353
    5454{{{#!csharp
     
    9999}}}
    100100
    101 The name for our variable is now {{{value}}} as the !UniformRandomizer saves its result by default in this variable and therefore we simply use this default name.
    102 What is still missing and what would be nice is a way for the user to configure our algorithm in the parameters tab in the HL Optimizer. This can be done by adding parameters to the parameter collection:
     101The name for our variable is now {{{Value}}} as the !UniformRandomizer saves its result by default in this variable and therefore we simply use this default name.
     102What is still missing and what would be nice is a way for the user to configure our algorithm in the Parameters tab in the HL Optimizer. This can be done by adding parameters to the parameter collection:
    103103
    104104{{{#!csharp
     
    107107}}}
    108108
    109 The 2 parameters we add here are so called !ValueParameters. This are parameters which contain a value, in contrast to a !LookUpParameter which has no value but looks up values of e.g. !ValueParameters. We call these 2 parameters Min and Max, as the !UniformRandomizer looks for theses two parameters and uses them as the lower and upper bound for generating random numbers. We also initialize them with default values which the user will later be able to edit in !HeuristicLab. An thats all we need for our !RandomAlgorithm. You can now compile and start !HeuristicLab. When you click on File->New, you should now see the algorithm in the dialog:
     109The 2 parameters we add here are so called !ValueParameters. This are parameters which contain a value, in contrast to a !LookUpParameter, which has no value but looks up values of e.g. !ValueParameters. We call these 2 parameters Min and Max, as the !UniformRandomizer looks for theses two parameters and uses them as the lower and upper bound for generating random numbers. We also initialize them with default values which the user will later be able to edit in !HeuristicLab. An that's all we need to do for our !RandomAlgorithm. You can now compile and start !HeuristicLab. When you click on File->New, you should now see the algorithm in the dialog:
    110110
    111111[[Image(filenew.PNG)]]
     
    119119[[Image(results.PNG)]]
    120120
    121 You can find the source file in the attachments section of this page.
     121You can find the source file of the algorithm in the attachments section of this page.
    122122
    123123