[5927] | 1 | using System;
|
---|
| 2 | using System.Linq;
|
---|
[5665] | 3 | using HeuristicLab.Common;
|
---|
| 4 | using HeuristicLab.Core;
|
---|
| 5 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[16574] | 6 | using HEAL.Attic;
|
---|
[5665] | 7 |
|
---|
| 8 | namespace HeuristicLab.Problems.MetaOptimization {
|
---|
[16574] | 9 | [StorableType("F44D48B3-6A35-4DF9-A660-CB654C573210")]
|
---|
[5665] | 10 | public class SingleValuedParameterConfiguration : ParameterConfiguration {
|
---|
[8087] | 11 |
|
---|
[5665] | 12 | #region Constructors and Cloning
|
---|
| 13 | [StorableConstructor]
|
---|
[16574] | 14 | protected SingleValuedParameterConfiguration(StorableConstructorFlag _) : base(_) { }
|
---|
[5665] | 15 | public SingleValuedParameterConfiguration(string parameterName, IValueParameter valueParameter)
|
---|
| 16 | : base(parameterName, valueParameter, false) {
|
---|
| 17 | this.Optimize = true;
|
---|
[5927] | 18 | base.PopulateValueConfigurations();
|
---|
[5665] | 19 | this.ValueConfigurations.Single().Optimize = true;
|
---|
| 20 | }
|
---|
[8087] | 21 | public SingleValuedParameterConfiguration(string parameterName, IValueConfiguration valueConfiguration)
|
---|
| 22 | : base() {
|
---|
[5927] | 23 | this.ParameterName = parameterName;
|
---|
| 24 | this.parameterDataType = valueConfiguration.ActualValue.ValueDataType;
|
---|
| 25 | this.valueDataType = valueConfiguration.ActualValue.ValueDataType;
|
---|
| 26 | this.discoverValidValues = false;
|
---|
| 27 | this.validValues = new ItemSet<IItem> { valueConfiguration.ActualValue.Value };
|
---|
[6018] | 28 | this.validTypes = new Type[] { valueConfiguration.ActualValue.ValueDataType };
|
---|
[6197] | 29 | this.isNullable = false;
|
---|
[5927] | 30 | this.itemImage = valueConfiguration.ItemImage;
|
---|
| 31 | this.ValueConfigurations = new CheckedValueConfigurationList { valueConfiguration };
|
---|
| 32 | this.ValueConfigurations.Single().Optimize = true;
|
---|
| 33 | valueConfiguration.ToStringChanged += new EventHandler(valueConfiguration_ToStringChanged);
|
---|
| 34 | this.ActualValue = new ConstrainedValue(
|
---|
| 35 | valueConfiguration.ActualValue.Value,
|
---|
| 36 | valueConfiguration.ActualValue.ValueDataType,
|
---|
| 37 | this.validValues,
|
---|
| 38 | this.IsNullable);
|
---|
| 39 | }
|
---|
[5665] | 40 | protected SingleValuedParameterConfiguration(SingleValuedParameterConfiguration original, Cloner cloner)
|
---|
| 41 | : base(original, cloner) {
|
---|
| 42 | }
|
---|
| 43 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 44 | return new SingleValuedParameterConfiguration(this, cloner);
|
---|
| 45 | }
|
---|
| 46 | #endregion
|
---|
[5927] | 47 |
|
---|
| 48 | protected override void PopulateValueConfigurations() {
|
---|
| 49 | // don't change valueconfigurations, since it only contains the one element specified in constructor
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | protected override void ClearValueConfigurations() {
|
---|
| 53 | // do nothing
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | public override string ToString() {
|
---|
[6197] | 57 | if (this.valueConfigurations.Single() is SymbolValueConfiguration) {
|
---|
| 58 | var syVc = (SymbolValueConfiguration)this.valueConfigurations.Single();
|
---|
[5927] | 59 | if (this.Optimize) {
|
---|
| 60 | return syVc.ToString() + " (Optimize)";
|
---|
| 61 | } else {
|
---|
[6197] | 62 | return ActualValue.ToString();
|
---|
[5927] | 63 | }
|
---|
| 64 | } else {
|
---|
| 65 | return base.ToString();
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[6197] | 69 | protected virtual void valueConfiguration_ToStringChanged(object sender, EventArgs e) {
|
---|
[5927] | 70 | OnToStringChanged();
|
---|
| 71 | }
|
---|
[6018] | 72 |
|
---|
| 73 | public override string ParameterInfoString {
|
---|
| 74 | get {
|
---|
| 75 | if (this.Optimize) {
|
---|
| 76 | return string.Format("{0} ({1})", this.Name, this.ValueConfigurations.Single().ParameterInfoString);
|
---|
| 77 | } else {
|
---|
| 78 | return string.Empty;
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
[5665] | 82 | }
|
---|
| 83 | }
|
---|