#region License Information
/* HeuristicLab
* Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Linq;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Encodings.ParameterConfigurationTreeEncoding {
[StorableClass]
public class SingleValuedParameterConfiguration : ParameterConfiguration {
#region Constructors and Cloning
[StorableConstructor]
protected SingleValuedParameterConfiguration(bool deserializing) : base(deserializing) { }
public SingleValuedParameterConfiguration(string parameterName, IValueParameter valueParameter)
: base(parameterName, valueParameter, false) {
this.Optimize = true;
base.PopulateValueConfigurations();
this.ValueConfigurations.Single().Optimize = true;
}
public SingleValuedParameterConfiguration(string parameterName, IValueConfiguration valueConfiguration) {
this.ParameterName = parameterName;
this.parameterDataType = valueConfiguration.ActualValue.ValueDataType;
this.valueDataType = valueConfiguration.ActualValue.ValueDataType;
this.discoverValidValues = false;
this.validValues = new ItemSet { valueConfiguration.ActualValue.Value };
this.validTypes = new Type[] { valueConfiguration.ActualValue.ValueDataType };
this.isNullable = false;
this.itemImage = valueConfiguration.ItemImage;
this.ValueConfigurations = new CheckedValueConfigurationList { valueConfiguration };
this.ValueConfigurations.Single().Optimize = true;
valueConfiguration.ToStringChanged += new EventHandler(valueConfiguration_ToStringChanged);
this.ActualValue = new ConstrainedValue(
valueConfiguration.ActualValue.Value,
valueConfiguration.ActualValue.ValueDataType,
this.validValues,
this.IsNullable);
}
public SingleValuedParameterConfiguration() { }
protected SingleValuedParameterConfiguration(SingleValuedParameterConfiguration original, Cloner cloner)
: base(original, cloner) {
}
public override IDeepCloneable Clone(Cloner cloner) {
return new SingleValuedParameterConfiguration(this, cloner);
}
#endregion
protected override void PopulateValueConfigurations() {
// don't change valueconfigurations, since it only contains the one element specified in constructor
}
protected override void ClearValueConfigurations() {
// do nothing
}
public override string ToString() {
if (this.valueConfigurations.Single() is SymbolValueConfiguration) {
var syVc = (SymbolValueConfiguration)this.valueConfigurations.Single();
if (this.Optimize) {
return syVc.ToString() + " (Optimize)";
} else {
return ActualValue.ToString();
}
} else {
return base.ToString();
}
}
protected virtual void valueConfiguration_ToStringChanged(object sender, EventArgs e) {
OnToStringChanged();
}
public override string ParameterInfoString {
get {
if (this.Optimize) {
return string.Format("{0} ({1})", this.Name, this.ValueConfigurations.Single().ParameterInfoString);
} else {
return string.Empty;
}
}
}
}
}