[5927] | 1 | using System;
|
---|
| 2 | using System.Linq;
|
---|
[5665] | 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 {
|
---|
[8087] | 10 |
|
---|
[5665] | 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;
|
---|
[5927] | 17 | base.PopulateValueConfigurations();
|
---|
[5665] | 18 | this.ValueConfigurations.Single().Optimize = true;
|
---|
| 19 | }
|
---|
[8087] | 20 | public SingleValuedParameterConfiguration(string parameterName, IValueConfiguration valueConfiguration)
|
---|
| 21 | : base() {
|
---|
[5927] | 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 };
|
---|
[6018] | 27 | this.validTypes = new Type[] { valueConfiguration.ActualValue.ValueDataType };
|
---|
[6197] | 28 | this.isNullable = false;
|
---|
[5927] | 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 | }
|
---|
[5665] | 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
|
---|
[5927] | 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() {
|
---|
[6197] | 56 | if (this.valueConfigurations.Single() is SymbolValueConfiguration) {
|
---|
| 57 | var syVc = (SymbolValueConfiguration)this.valueConfigurations.Single();
|
---|
[5927] | 58 | if (this.Optimize) {
|
---|
| 59 | return syVc.ToString() + " (Optimize)";
|
---|
| 60 | } else {
|
---|
[6197] | 61 | return ActualValue.ToString();
|
---|
[5927] | 62 | }
|
---|
| 63 | } else {
|
---|
| 64 | return base.ToString();
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[6197] | 68 | protected virtual void valueConfiguration_ToStringChanged(object sender, EventArgs e) {
|
---|
[5927] | 69 | OnToStringChanged();
|
---|
| 70 | }
|
---|
[6018] | 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 | }
|
---|
[5665] | 81 | }
|
---|
| 82 | }
|
---|