Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/SingleValuedParameterConfiguration.cs

Last change on this file was 16996, checked in by gkronber, 6 years ago

#2520 Update plugin dependencies and references for HL.MetaOptimization for new persistence

File size: 3.2 KB
Line 
1using System;
2using System.Linq;
3using HeuristicLab.Common;
4using HeuristicLab.Core;
5using HEAL.Attic;
6
7namespace HeuristicLab.Problems.MetaOptimization {
8  [StorableType("F44D48B3-6A35-4DF9-A660-CB654C573210")]
9  public class SingleValuedParameterConfiguration : ParameterConfiguration {
10
11    #region Constructors and Cloning
12    [StorableConstructor]
13    protected SingleValuedParameterConfiguration(StorableConstructorFlag _) : base(_) { }
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      : base() {
22      this.ParameterName = parameterName;
23      this.parameterDataType = valueConfiguration.ActualValue.ValueDataType;
24      this.valueDataType = valueConfiguration.ActualValue.ValueDataType;
25      this.discoverValidValues = false;
26      this.validValues = new ItemSet<IItem> { valueConfiguration.ActualValue.Value };
27      this.validTypes = new Type[] { valueConfiguration.ActualValue.ValueDataType };
28      this.isNullable = false;
29      this.itemImage = valueConfiguration.ItemImage;
30      this.ValueConfigurations = new CheckedValueConfigurationList { valueConfiguration };
31      this.ValueConfigurations.Single().Optimize = true;
32      valueConfiguration.ToStringChanged += new EventHandler(valueConfiguration_ToStringChanged);
33      this.ActualValue = new ConstrainedValue(
34        valueConfiguration.ActualValue.Value,
35        valueConfiguration.ActualValue.ValueDataType,
36        this.validValues,
37        this.IsNullable);
38    }
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.Single() is SymbolValueConfiguration) {
57        var syVc = (SymbolValueConfiguration)this.valueConfigurations.Single();
58        if (this.Optimize) {
59          return syVc.ToString() + " (Optimize)";
60        } else {
61          return ActualValue.ToString();
62        }
63      } else {
64        return base.ToString();
65      }
66    }
67
68    protected virtual void valueConfiguration_ToStringChanged(object sender, EventArgs e) {
69      OnToStringChanged();
70    }
71
72    public override string ParameterInfoString {
73      get {
74        if (this.Optimize) {
75          return string.Format("{0} ({1})", this.Name, this.ValueConfigurations.Single().ParameterInfoString);
76        } else {
77          return string.Empty;
78        }
79      }
80    }
81  }
82}
Note: See TracBrowser for help on using the repository browser.