1 | using System;
|
---|
2 | using System.Linq;
|
---|
3 | using HeuristicLab.Common;
|
---|
4 | using HeuristicLab.Core;
|
---|
5 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
6 |
|
---|
7 | namespace 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 | }
|
---|