Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/tools/Templates/HeuristicLabProblemTemplate/DefaultProblem.cs @ 4771

Last change on this file since 4771 was 4541, checked in by abeham, 14 years ago

#567

  • fixed minor oversight in problem
File size: 4.3 KB
Line 
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.Collections.Generic;
24using System.Drawing;
25using System.IO;
26using System.Linq;
27using HeuristicLab.Common;
28using HeuristicLab.Core;
29using HeuristicLab.Data;
30using HeuristicLab.Optimization;
31using HeuristicLab.Parameters;
32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
33using HeuristicLab.PluginInfrastructure;
34
35namespace $rootnamespace$ {
36  [Item("$problemName$", "$problemDescription$")]
37  [Creatable("Problems")]
38  [StorableClass]
39  public sealed class $safeitemname$ : ParameterizedNamedItem, $problemTypeImplementation$ {
40    public override Image ItemImage {
41      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Type; }
42    }
43
44    #region Parameter Properties
45    $problemSpecificParameterProperties$
46    $parameterProperties$
47    #endregion
48
49    #region Properties
50    $problemSpecificProperties$
51    $properties$
52    public IEnumerable<IOperator> Operators {
53      get { return operators; }
54    }
55    #endregion
56
57    [Storable]
58    private List<IOperator> operators;
59
60    [StorableConstructor]
61    private $safeitemname$(bool deserializing) : base(deserializing) { }
62    public $safeitemname$()
63      : base() {
64      // TODO: Create a new instance of evaluator and solution creator
65
66      $problemSpecificParameterInitializers$
67      $parameterInitializers$
68
69      ParameterizeSolutionCreator();
70      ParameterizeEvaluator();
71
72      InitializeOperators();
73      AttachEventHandlers();
74    }
75
76    public override IDeepCloneable Clone(Cloner cloner) {
77      $safeitemname$ clone = ($safeitemname$)base.Clone(cloner);
78      clone.operators = operators.Select(x => (IOperator)cloner.Clone(x)).ToList();
79      // TODO: Clone private fields here
80      clone.AttachEventHandlers();
81      return clone;
82    }
83
84    #region Events
85    public event EventHandler SolutionCreatorChanged;
86    private void OnSolutionCreatorChanged() {
87      EventHandler handler = SolutionCreatorChanged;
88      if (handler != null) handler(this, EventArgs.Empty);
89    }
90    public event EventHandler EvaluatorChanged;
91    private void OnEvaluatorChanged() {
92      EventHandler handler = EvaluatorChanged;
93      if (handler != null) handler(this, EventArgs.Empty);
94    }
95    public event EventHandler OperatorsChanged;
96    private void OnOperatorsChanged() {
97      EventHandler handler = OperatorsChanged;
98      if (handler != null) handler(this, EventArgs.Empty);
99    }
100    public event EventHandler Reset;
101    private void OnReset() {
102      EventHandler handler = Reset;
103      if (handler != null) handler(this, EventArgs.Empty);
104    }
105
106    // TODO: Add your event handlers here
107    #endregion
108
109    #region Helpers
110    [StorableHook(HookType.AfterDeserialization)]
111    private void AfterDeserializationHook() {
112      AttachEventHandlers();
113    }
114
115    private void AttachEventHandlers() {
116      // TODO: Add event handlers to the parameters here
117    }
118
119    private void InitializeOperators() {
120      operators = new List<IOperator>();
121      // TODO: Add custom problem analyzer to the list
122      // TODO: Add operators from the representation either by direct instantiation, or by using ApplicationManager.Manger.GetInstances<T>().Cast<IOperator>()
123    }
124    private void ParameterizeSolutionCreator() {
125      // TODO: Set the parameters of the solution creator
126    }
127    private void ParameterizeEvaluator() {
128      // TODO: Set the parameters of the evaluator
129    }
130    #endregion
131  }
132}
Note: See TracBrowser for help on using the repository browser.