Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/SingleValuedParameterConfiguration.cs @ 6017

Last change on this file since 6017 was 5927, checked in by cneumuel, 14 years ago

#1215

  • worked on configurability of SymbolicExpressionGrammar
File size: 2.9 KB
Line 
1using System;
2using System.Linq;
3using HeuristicLab.Common;
4using HeuristicLab.Core;
5using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
6
7namespace HeuristicLab.Problems.MetaOptimization {
8  [StorableClass]
9  public class SingleValuedParameterConfiguration : ParameterConfiguration {
10
11    #region Constructors and Cloning
12    [StorableConstructor]
13    protected SingleValuedParameterConfiguration(bool deserializing) : base(deserializing) { }
14    public SingleValuedParameterConfiguration(string parameterName, IValueParameter valueParameter)
15      : base(parameterName, valueParameter, false) {
16      this.Optimize = true;
17      base.PopulateValueConfigurations();
18      this.ValueConfigurations.Single().Optimize = true;
19    }
20    public SingleValuedParameterConfiguration(string parameterName, IValueConfiguration valueConfiguration) {
21      this.ParameterName = parameterName;
22      this.parameterDataType = valueConfiguration.ActualValue.ValueDataType;
23      this.valueDataType = valueConfiguration.ActualValue.ValueDataType;
24      this.discoverValidValues = false;
25      this.validValues = new ItemSet<IItem> { valueConfiguration.ActualValue.Value };
26      this.validTypes = new Type[] {valueConfiguration.ActualValue.ValueDataType};
27      this.IsNullable = false;
28      this.itemImage = valueConfiguration.ItemImage;
29      this.ValueConfigurations = new CheckedValueConfigurationList { valueConfiguration };
30      this.ValueConfigurations.Single().Optimize = true;
31      valueConfiguration.ToStringChanged += new EventHandler(valueConfiguration_ToStringChanged);
32      this.ActualValue = new ConstrainedValue(
33        valueConfiguration.ActualValue.Value,
34        valueConfiguration.ActualValue.ValueDataType,
35        this.validValues,
36        this.IsNullable);
37    }
38    public SingleValuedParameterConfiguration() { }
39    protected SingleValuedParameterConfiguration(SingleValuedParameterConfiguration original, Cloner cloner)
40      : base(original, cloner) {
41    }
42    public override IDeepCloneable Clone(Cloner cloner) {
43      return new SingleValuedParameterConfiguration(this, cloner);
44    }
45    #endregion
46
47    protected override void PopulateValueConfigurations() {
48      // don't change valueconfigurations, since it only contains the one element specified in constructor
49    }
50
51    protected override void ClearValueConfigurations() {
52      // do nothing
53    }
54
55    public override string ToString() {
56      if (this.valueConfigurations.First() is SymbolValueConfiguration) {
57        var syVc = (SymbolValueConfiguration)this.valueConfigurations.First();
58        if (this.Optimize) {
59          return syVc.ToString() + " (Optimize)";
60        } else {
61          return syVc.ToString();
62        }
63      } else {
64        return base.ToString();
65      }
66    }
67
68    private void valueConfiguration_ToStringChanged(object sender, EventArgs e) {
69      OnToStringChanged();
70    }
71  }
72}
Note: See TracBrowser for help on using the repository browser.