Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysisService/HeuristicLab.Encodings.ParameterConfigurationTreeEncoding/3.3/ParameterConfigurations/SingleValuedParameterConfiguration.cs @ 11316

Last change on this file since 11316 was 7840, checked in by spimming, 13 years ago

#1853:

  • included files from metaopt branch
  • ignored mutation and crossover
  • updated plugin frame
File size: 4.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Encodings.ParameterConfigurationTreeEncoding {
29  [StorableClass]
30  public class SingleValuedParameterConfiguration : ParameterConfiguration {
31
32    #region Constructors and Cloning
33    [StorableConstructor]
34    protected SingleValuedParameterConfiguration(bool deserializing) : base(deserializing) { }
35    public SingleValuedParameterConfiguration(string parameterName, IValueParameter valueParameter)
36      : base(parameterName, valueParameter, false) {
37      this.Optimize = true;
38      base.PopulateValueConfigurations();
39      this.ValueConfigurations.Single().Optimize = true;
40    }
41    public SingleValuedParameterConfiguration(string parameterName, IValueConfiguration valueConfiguration) {
42      this.ParameterName = parameterName;
43      this.parameterDataType = valueConfiguration.ActualValue.ValueDataType;
44      this.valueDataType = valueConfiguration.ActualValue.ValueDataType;
45      this.discoverValidValues = false;
46      this.validValues = new ItemSet<IItem> { valueConfiguration.ActualValue.Value };
47      this.validTypes = new Type[] { valueConfiguration.ActualValue.ValueDataType };
48      this.isNullable = false;
49      this.itemImage = valueConfiguration.ItemImage;
50      this.ValueConfigurations = new CheckedValueConfigurationList { valueConfiguration };
51      this.ValueConfigurations.Single().Optimize = true;
52      valueConfiguration.ToStringChanged += new EventHandler(valueConfiguration_ToStringChanged);
53      this.ActualValue = new ConstrainedValue(
54        valueConfiguration.ActualValue.Value,
55        valueConfiguration.ActualValue.ValueDataType,
56        this.validValues,
57        this.IsNullable);
58    }
59    public SingleValuedParameterConfiguration() { }
60    protected SingleValuedParameterConfiguration(SingleValuedParameterConfiguration original, Cloner cloner)
61      : base(original, cloner) {
62    }
63    public override IDeepCloneable Clone(Cloner cloner) {
64      return new SingleValuedParameterConfiguration(this, cloner);
65    }
66    #endregion
67
68    protected override void PopulateValueConfigurations() {
69      // don't change valueconfigurations, since it only contains the one element specified in constructor
70    }
71
72    protected override void ClearValueConfigurations() {
73      // do nothing
74    }
75
76    public override string ToString() {
77      if (this.valueConfigurations.Single() is SymbolValueConfiguration) {
78        var syVc = (SymbolValueConfiguration)this.valueConfigurations.Single();
79        if (this.Optimize) {
80          return syVc.ToString() + " (Optimize)";
81        } else {
82          return ActualValue.ToString();
83        }
84      } else {
85        return base.ToString();
86      }
87    }
88
89    protected virtual void valueConfiguration_ToStringChanged(object sender, EventArgs e) {
90      OnToStringChanged();
91    }
92
93    public override string ParameterInfoString {
94      get {
95        if (this.Optimize) {
96          return string.Format("{0} ({1})", this.Name, this.ValueConfigurations.Single().ParameterInfoString);
97        } else {
98          return string.Empty;
99        }
100      }
101    }
102  }
103}
Note: See TracBrowser for help on using the repository browser.