Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ParameterConfigurations/SingleValuedParameterConfiguration.cs @ 15737

Last change on this file since 15737 was 8535, checked in by jkarder, 12 years ago

#1853:

  • enhanced combinations count calculation
  • restructured code
  • minor code improvements
  • added license information
File size: 4.0 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.ParameterConfigurationEncoding {
29  [StorableClass]
30  public class SingleValuedParameterConfiguration : ParameterConfiguration {
31    #region Constructors and Cloning
32    [StorableConstructor]
33    protected SingleValuedParameterConfiguration(bool deserializing) : base(deserializing) { }
34    protected SingleValuedParameterConfiguration(SingleValuedParameterConfiguration original, Cloner cloner) : base(original, cloner) { }
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      : base() {
43      this.ParameterName = parameterName;
44      this.parameterDataType = valueConfiguration.ActualValue.ValueDataType;
45      this.valueDataType = valueConfiguration.ActualValue.ValueDataType;
46      this.discoverValidValues = false;
47      this.validValues = new ItemSet<IItem> { valueConfiguration.ActualValue.Value };
48      this.validTypes = new Type[] { valueConfiguration.ActualValue.ValueDataType };
49      this.isNullable = false;
50      this.itemImage = valueConfiguration.ItemImage;
51      this.ValueConfigurations = new CheckedValueConfigurationList { valueConfiguration };
52      this.ValueConfigurations.Single().Optimize = true;
53      valueConfiguration.ToStringChanged += new EventHandler(valueConfiguration_ToStringChanged);
54      this.ActualValue = new ConstrainedValue(
55        valueConfiguration.ActualValue.Value,
56        valueConfiguration.ActualValue.ValueDataType,
57        this.validValues,
58        this.IsNullable);
59    }
60    public override IDeepCloneable Clone(Cloner cloner) {
61      return new SingleValuedParameterConfiguration(this, cloner);
62    }
63    #endregion
64
65    protected override void PopulateValueConfigurations() {
66      // don't change valueconfigurations, since it only contains the one element specified in constructor
67    }
68
69    protected override void ClearValueConfigurations() {
70      // do nothing
71    }
72
73    public override string ToString() {
74      if (this.valueConfigurations.Single() is SymbolValueConfiguration) {
75        var syVc = (SymbolValueConfiguration)this.valueConfigurations.Single();
76        if (this.Optimize) {
77          return syVc.ToString() + " (Optimize)";
78        } else {
79          return ActualValue.ToString();
80        }
81      } else {
82        return base.ToString();
83      }
84    }
85
86    protected virtual void valueConfiguration_ToStringChanged(object sender, EventArgs e) {
87      OnToStringChanged();
88    }
89
90    public override string ParameterInfoString {
91      get {
92        if (this.Optimize) {
93          return string.Format("{0} ({1})", this.Name, this.ValueConfigurations.Single().ParameterInfoString);
94        } else {
95          return string.Empty;
96        }
97      }
98    }
99  }
100}
Note: See TracBrowser for help on using the repository browser.