Changes between Version 5 and Version 6 of Documentation/Howto/Implement a Basic Algorithm
- Timestamp:
- 03/21/12 14:12:16 (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Documentation/Howto/Implement a Basic Algorithm
v5 v6 14 14 The 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. 15 15 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.16 It 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. 17 17 18 18 === 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}}}.19 Because we want to roughly create the same algorithm now in code, we create a new class in your !HeuristicLab plugin and call it {{{RandomAlgorithm}}}. 20 20 Before 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): 21 21 … … 50 50 }}} 51 51 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: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 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: 53 53 54 54 {{{#!csharp … … 99 99 }}} 100 100 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: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: 103 103 104 104 {{{#!csharp … … 107 107 }}} 108 108 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 needfor our !RandomAlgorithm. You can now compile and start !HeuristicLab. When you click on File->New, you should now see the algorithm in the dialog: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 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: 110 110 111 111 [[Image(filenew.PNG)]] … … 119 119 [[Image(results.PNG)]] 120 120 121 You can find the source file in the attachments section of this page.121 You can find the source file of the algorithm in the attachments section of this page. 122 122 123 123