Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/tools/Templates/HeuristicLabAlgorithmTemplate/DefaultAlgorithm.cs @ 9674

Last change on this file since 9674 was 5912, checked in by abeham, 14 years ago

#567

  • updated problem and algorithm
  • reverted plugin wizard
File size: 4.6 KB
RevLine 
[4176]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-$year$ Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Linq;
24using HeuristicLab.Analysis;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Optimization;
29using HeuristicLab.Optimization.Operators;
30using HeuristicLab.Parameters;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
32using HeuristicLab.PluginInfrastructure;
33using HeuristicLab.Random;
34
35namespace $rootnamespace$ {
36  /// <summary>
37  /// A genetic algorithm.
38  /// </summary>
39  [Item("$algorithmName$", "$algorithmDescription$")]
40  [Creatable("Algorithms")]
41  [StorableClass]
42  public sealed class $safeitemname$ : EngineAlgorithm {
43    #region Problem Properties
44    $problemType$
45    #endregion
46
47    #region Parameter Properties
[4187]48    $parameterProperties$
[4176]49    #endregion
50
51    #region Properties
[4187]52    $properties$
53    private RandomCreator RandomCreator {
54      get { return (RandomCreator)OperatorGraph.InitialOperator; }
[4176]55    }
56    #endregion
57
58    [StorableConstructor]
59    private $safeitemname$(bool deserializing) : base(deserializing) { }
[5912]60    private $safeitemname$($safeitemname$ original, Cloner cloner)
61      : base(original, cloner) {
62      // TODO: clone your private fields here
63      AttachEventHandlers();
64    }
[4176]65    public $safeitemname$()
66      : base() {
[4187]67      $parameterInitializers$
[4176]68     
[4187]69      RandomCreator randomCreator = new RandomCreator();
70      OperatorGraph.InitialOperator = randomCreator;
[4176]71
[4187]72      randomCreator.RandomParameter.ActualName = "Random";
73      randomCreator.SeedParameter.ActualName = SeedParameter.Name;
74      randomCreator.SeedParameter.Value = null;
75      randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
76      randomCreator.SetSeedRandomlyParameter.Value = null;
[5912]77      randomCreator.Successor = null;
[4187]78
79      // TODO: Create further operators and build operator graph
[4176]80     
[4187]81      UpdateAnalyzers();
[4176]82      AttachEventHandlers();
83    }
84
85    public override IDeepCloneable Clone(Cloner cloner) {
[5912]86      return new $safeitemname$(this, cloner);
[4176]87    }
88
89    public override void Prepare() {
90      if (Problem != null) base.Prepare();
91    }
92
93    #region Events
94    protected override void OnProblemChanged() {
95      // TODO: Initialize and parameterize operators
[4187]96      UpdateAnalyzers();
[4176]97      base.OnProblemChanged();
98    }
99
100    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
101      // TODO: Parameterize operators
102      base.Problem_SolutionCreatorChanged(sender, e);
103    }
104    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
105      // TODO: Parameterize operators
106      base.Problem_EvaluatorChanged(sender, e);
107    }
108    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
109      // TODO: Parameterize operators
[4187]110      UpdateAnalyzers();
[4176]111      base.Problem_OperatorsChanged(sender, e);
112    }
113    #endregion
114
115    #region Helpers
116    [StorableHook(HookType.AfterDeserialization)]
117    private void AttachEventHandlers() {
118      // TODO: Attach event handlers to local parameters
119      if (Problem != null) {
120        // TODO: Attach event handlers to problem parameters
121      }
122    }
123    private void UpdateAnalyzers() {
124      Analyzer.Operators.Clear();
125      if (Problem != null) {
126        foreach (IAnalyzer analyzer in Problem.Operators.OfType<IAnalyzer>()) {
127          foreach (IScopeTreeLookupParameter param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
128            param.Depth = 1; // TODO: 0 when GlobalScope = Solution, 1 when GlobalScope = Population, 2 when GlobalScope = MetaPopulation (Islands)
129          Analyzer.Operators.Add(analyzer);
130        }
131      }
132      // TODO: Add your own algorithm specific analyzer here (problem analyzer should be added/executed first)
133    }
134    #endregion
135  }
136}
Note: See TracBrowser for help on using the repository browser.