Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ParameterConfiguration.cs @ 4771

Last change on this file since 4771 was 4525, checked in by cneumuel, 14 years ago

implemented basic crossover operator for ParameterSets. MetaOptimization is now functional on a basic level (Configuration and Crossing only works for IntValue Parameters) (#1215)

File size: 2.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Common;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8
9namespace HeuristicLab.Problems.MetaOptimization {
10  [StorableClass]
11  public abstract class ParameterConfiguration : IParameterConfiguration {
12    [Storable]
13    public IParameter Parameter { get; set; }
14
15    [Storable]
16    public string Category { get; set; }
17
18    public ParameterConfiguration() { }
19   
20    [StorableConstructor]
21    protected ParameterConfiguration(bool deserializing) { }
22
23    public ParameterConfiguration(IParameter parameter, string category) {
24      this.Parameter = parameter;
25      this.Category = category;
26      Parameter.NameChanged += this.NameChanged;
27      Parameter.NameChanging += this.NameChanging;
28      Parameter.DescriptionChanged += this.DescriptionChanged;
29      Parameter.ItemImageChanged += this.ItemImageChanged;
30      parameter.ToStringChanged += this.ToStringChanged;
31    }
32
33    public bool CanChangeDescription {
34      get { return false; }
35    }
36
37    public bool CanChangeName {
38      get { return false; }
39    }
40
41    public string Description {
42      get { return Parameter.Description; }
43      set { throw new NotSupportedException(); }
44    }
45    public string Name {
46      get { return Parameter.Name; }
47      set { throw new NotSupportedException(); }
48    }
49
50    public string ItemDescription {
51      get { return Parameter.ItemDescription; }
52    }
53
54    public System.Drawing.Image ItemImage {
55      get { return Parameter.ItemImage; }
56    }
57
58    public string ItemName {
59      get { return Parameter.ItemName; }
60    }
61
62    public Version ItemVersion {
63      get { return Parameter.ItemVersion; }
64    }
65
66    #region Events
67    public virtual event EventHandler NameChanged;
68    public virtual event EventHandler<CancelEventArgs<string>> NameChanging;
69    public virtual event EventHandler DescriptionChanged;
70    public virtual event EventHandler ItemImageChanged;
71    public virtual event EventHandler ToStringChanged;
72
73    protected virtual void OnToStringChanged() {
74      var handler = ToStringChanged;
75      if (handler != null) handler(this, EventArgs.Empty);
76    }
77    #endregion
78
79    #region Cloning
80    public virtual IDeepCloneable Clone(Cloner cloner) {
81      ParameterConfiguration clone = (ParameterConfiguration)Activator.CreateInstance(this.GetType(), true);
82      cloner.RegisterClonedObject(this, clone);
83      clone.Parameter = (IParameter)cloner.Clone(this.Parameter);
84      clone.Category = this.Category;
85      return clone;
86    }
87
88    public object Clone() {
89      return Clone(new Cloner());
90    }
91    #endregion
92
93    public override string ToString() {
94      return string.Format("{0}.{1}", Category, Parameter.Name);
95    }
96   
97    public abstract void SetParameterWithRandomValue(IRandom random);
98
99  }
100}
Note: See TracBrowser for help on using the repository browser.