Changeset 8535 for branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding
- Timestamp:
- 08/29/12 09:22:21 (12 years ago)
- Location:
- branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/AlgorithmProblemItem.cs
r8517 r8535 41 41 [StorableConstructor] 42 42 protected AlgorithmProblemItem(bool deserializing) : base(deserializing) { } 43 public AlgorithmProblemItem() { 43 protected AlgorithmProblemItem(AlgorithmProblemItem original, Cloner cloner) : base(original, cloner) { } 44 public AlgorithmProblemItem() 45 : base() { 44 46 this.Parameters.Add(new ValueParameter<IAlgorithm>("Algorithm")); 45 47 this.Parameters.Add(new ValueParameter<IProblem>("Problem")); 46 }47 protected AlgorithmProblemItem(AlgorithmProblemItem original, Cloner cloner)48 : base(original, cloner) {49 48 } 50 49 public override IDeepCloneable Clone(Cloner cloner) { -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ConstrainedItemList.cs
r8517 r8535 1 using System; 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 22 using System; 2 23 using HeuristicLab.Common; 3 24 using HeuristicLab.Core; … … 19 40 } 20 41 21 public ConstrainedItemList() { 22 Type = typeof(T); 23 } 42 #region Constructors and Cloning 24 43 [StorableConstructor] 25 44 protected ConstrainedItemList(bool deserializing) : base(deserializing) { } … … 28 47 this.Type = original.Type; 29 48 } 49 public ConstrainedItemList() 50 : base() { 51 Type = typeof(T); 52 } 30 53 public override IDeepCloneable Clone(Cloner cloner) { 31 54 return new ConstrainedItemList<T>(this, cloner); 32 55 } 56 #endregion 33 57 } 34 58 } -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ConstrainedTypeValue.cs
r8517 r8535 1 using System; 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 22 using System; 2 23 using System.Collections.Generic; 3 24 using System.Linq; … … 11 32 [StorableClass] 12 33 public class ConstrainedTypeValue : TypeValue { 13 14 34 private IEnumerable<Type> validTypes; 15 35 public IEnumerable<Type> ValidTypes { … … 25 45 } 26 46 47 #region Constructors and Cloning 48 [StorableConstructor] 49 protected ConstrainedTypeValue(bool deserializing) : base(deserializing) { } 50 protected ConstrainedTypeValue(ConstrainedTypeValue original, Cloner cloner) 51 : base(original, cloner) { 52 if (original.validTypes != null) 53 this.validTypes = new List<Type>(original.validTypes); 54 } 27 55 public ConstrainedTypeValue() 28 56 : base() { … … 33 61 this.Value = value; 34 62 } 35 36 [StorableConstructor]37 protected ConstrainedTypeValue(bool deserializing) : base(deserializing) { }38 protected ConstrainedTypeValue(ConstrainedTypeValue original, Cloner cloner)39 : base(original, cloner) {40 if (original.validTypes != null)41 this.validTypes = new List<Type>(original.validTypes);42 }43 63 public override IDeepCloneable Clone(Cloner cloner) { 44 64 return new ConstrainedTypeValue(this, cloner); 45 65 } 66 #endregion 46 67 } 47 68 … … 49 70 [StorableClass] 50 71 public class ConstrainedTypeValue<T> : ConstrainedTypeValue where T : class, IItem { 51 72 [StorableConstructor] 73 protected ConstrainedTypeValue(bool deserializing) 74 : base(deserializing) { 75 if (deserializing) { 76 this.ValidTypes = ApplicationManager.Manager.GetTypes(typeof(T), true).ToList(); 77 } 78 } 79 protected ConstrainedTypeValue(ConstrainedTypeValue original, Cloner cloner) : base(original, cloner) { } 52 80 public ConstrainedTypeValue() 53 81 : base() { … … 60 88 this.Value = value; 61 89 } 62 63 [StorableConstructor]64 protected ConstrainedTypeValue(bool deserializing)65 : base(deserializing) {66 if (deserializing) {67 this.ValidTypes = ApplicationManager.Manager.GetTypes(typeof(T), true).ToList();68 }69 }70 71 protected ConstrainedTypeValue(ConstrainedTypeValue original, Cloner cloner) : base(original, cloner) { }72 90 public override IDeepCloneable Clone(Cloner cloner) { 73 91 return new ConstrainedTypeValue<T>(this, cloner); -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/Interfaces/IOptimizable.cs
r8517 r8535 42 42 event EventHandler IsOptimizableChanged; 43 43 event EventHandler OptimizeChanged; 44 event EventHandler CombinationsCountChanged; 44 45 45 46 /// <summary> -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/Interfaces/IValueConfiguration.cs
r8517 r8535 28 28 29 29 event EventHandler ValueChanged; 30 31 //void Parameterize(IParameterizedItem item);32 30 } 33 31 } -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/NullValue.cs
r8517 r8535 27 27 [StorableClass] 28 28 public class NullValue : ValueTypeValue<int> { 29 30 public NullValue() { }31 29 [StorableConstructor] 32 30 protected NullValue(bool deserializing) : base(deserializing) { } 33 protected NullValue(NullValue original, Cloner cloner) 34 : base(original, cloner) { 35 } 31 protected NullValue(NullValue original, Cloner cloner) : base(original, cloner) { } 32 public NullValue() : base() { } 36 33 public override IDeepCloneable Clone(Cloner cloner) { 37 34 return new NullValue(this, cloner); -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ParameterConfigurationTree.cs
r8524 r8535 37 37 [StorableClass] 38 38 public class ParameterConfigurationTree : ParameterizedValueConfiguration, IEnumerable { 39 [Storable] 40 private long combinationsCount; 41 public long CombinationsCount { 42 get { return combinationsCount; } 43 private set { 44 if (combinationsCount != value) { 45 combinationsCount = value; 46 OnCombinationsCountChanged(); 47 } 48 } 49 } 50 39 51 [Storable] 40 52 private DoubleValue quality; … … 213 225 this.Name = algorithm.ItemName; 214 226 215 var alg problemitem = new AlgorithmProblemItem();216 alg problemitem.AlgorithmParameter.Value = algorithm;217 alg problemitem.ProblemParameter.Value = problem;227 var algProblemItem = new AlgorithmProblemItem(); 228 algProblemItem.AlgorithmParameter.Value = algorithm; 229 algProblemItem.ProblemParameter.Value = problem; 218 230 this.discoverValidValues = false; 219 231 220 this.parameterConfigurations.Add(new SingleValuedParameterConfiguration("Algorithm", algproblemitem.AlgorithmParameter)); 221 this.parameterConfigurations.Add(new SingleValuedParameterConfiguration("Problem", algproblemitem.ProblemParameter)); 232 var algConfig = new SingleValuedParameterConfiguration("Algorithm", algProblemItem.AlgorithmParameter); 233 var problemConfig = new SingleValuedParameterConfiguration("Problem", algProblemItem.ProblemParameter); 234 235 algConfig.CombinationsCountChanged += new EventHandler(UpdateConfigurationsCount); 236 problemConfig.CombinationsCountChanged += new EventHandler(UpdateConfigurationsCount); 237 238 this.parameterConfigurations.Add(algConfig); 239 this.parameterConfigurations.Add(problemConfig); 222 240 223 241 // problems can be modified in the list of problem instances, so the parameters which are not Optimize=true, 224 242 // must not be modifiable in the parameter configuration tree. otherwise the parameter values would be ambiguous 225 243 ProblemConfiguration.ValuesReadOnly = true; 244 245 CombinationsCount = GetCombinationCount(0); 226 246 } 227 247 … … 233 253 private void AfterDeserialization() { 234 254 if (ProblemConfiguration != null) ProblemConfiguration.ValuesReadOnly = true; 255 CombinationsCount = GetCombinationCount(0); 235 256 } 236 257 #endregion … … 265 286 private void Quality_ValueChanged(object sender, EventArgs e) { 266 287 OnQualityChanged(); 288 } 289 290 private void UpdateConfigurationsCount(object sender, EventArgs e) { 291 CombinationsCount = GetCombinationCount(0); 267 292 } 268 293 -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ParameterConfigurations/ParameterConfiguration.cs
r8517 r8535 57 57 } 58 58 OnOptimizeChanged(); 59 OnCombinationsCountChanged(); 59 60 OnToStringChanged(); 61 } 62 } 63 } 64 65 [Storable] 66 protected long combinationsCount; 67 public virtual long CombinationsCount { 68 get { return combinationsCount; } 69 set { 70 if (combinationsCount != value) { 71 combinationsCount = value; 72 OnCombinationsCountChanged(); 60 73 } 61 74 } … … 179 192 180 193 #region Constructors and Cloning 181 public ParameterConfiguration(string parameterName, IValueParameter valueParameter, bool discoverValidValues) { 194 public ParameterConfiguration(string parameterName, IValueParameter valueParameter, bool discoverValidValues) 195 : base() { 182 196 this.AutoPopulateValueConfigurations = true; 183 197 this.ParameterName = parameterName; … … 202 216 } 203 217 } 204 public ParameterConfiguration(string parameterName, Type type, IItem actualValue, IEnumerable<IValueConfiguration> valueConfigurations) { 218 public ParameterConfiguration(string parameterName, Type type, IItem actualValue, IEnumerable<IValueConfiguration> valueConfigurations) 219 : base() { 205 220 this.AutoPopulateValueConfigurations = false; 206 221 this.ParameterName = parameterName; … … 211 226 this.validTypes = new Type[] { type }; 212 227 this.IsNullable = false; 213 this.itemImage = valueConfigurations. Count() > 0 ? valueConfigurations.FirstOrDefault().ItemImage : null;228 this.itemImage = valueConfigurations.Any() ? valueConfigurations.First().ItemImage : null; 214 229 this.ValueConfigurations = new CheckedValueConfigurationList(valueConfigurations); 215 230 this.ActualValue = new ConstrainedValue(actualValue, type, CreateValidValues(), this.IsNullable); 216 231 } 217 public ParameterConfiguration(string parameterName, Type type, IItem actualValue) { 232 public ParameterConfiguration(string parameterName, Type type, IItem actualValue) 233 : base() { 218 234 this.AutoPopulateValueConfigurations = true; 219 235 this.ParameterName = parameterName; … … 231 247 } 232 248 } 233 protected ParameterConfiguration() { }249 protected ParameterConfiguration() : base() { } 234 250 [StorableConstructor] 235 251 protected ParameterConfiguration(bool deserializing) { } 236 237 252 protected ParameterConfiguration(ParameterConfiguration original, Cloner cloner) 238 253 : base(original, cloner) { … … 316 331 } 317 332 } 333 valueConfiguration.CombinationsCountChanged += (sender, args) => OnCombinationsCountChanged(); 318 334 this.ValueConfigurations.Add(valueConfiguration, true); 319 335 } … … 357 373 return new List<Type> { parameter }; 358 374 359 // TODO: not sure if this ifmakes sense; maybe only leave else branch here375 // TODO: check if this makes sense; maybe only leave else branch here 360 376 if (IsSubclassOfRawGeneric(typeof(OptionalConstrainedValueParameter<>), parameter.GetType())) { 361 377 // use existing validvalues if known … … 391 407 392 408 // copy value from ValidValues; this ensures that previously set ActualNames for a type are kept 393 IItem value = this.validValues. Where(v => v.GetType() == type).SingleOrDefault();409 IItem value = this.validValues.SingleOrDefault(v => v.GetType() == type); 394 410 if (value != null) 395 411 return value; … … 425 441 private void ValueConfigurations_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) { 426 442 OnToStringChanged(); 443 OnCombinationsCountChanged(); 427 444 KeepActualValueConfigurationIndexConsistent(); 428 445 } … … 430 447 private void ValueConfigurations_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) { 431 448 OnToStringChanged(); 449 OnCombinationsCountChanged(); 432 450 KeepActualValueConfigurationIndexConsistent(); 433 451 } 434 452 private void ValueConfigurations_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) { 435 453 OnToStringChanged(); 454 OnCombinationsCountChanged(); 436 455 KeepActualValueConfigurationIndexConsistent(); 437 456 } … … 451 470 public virtual bool CanChangeName { 452 471 get { return false; } 453 }454 public override string ItemDescription {455 get { return base.ItemDescription; }456 }457 public override string ItemName {458 get { return base.ItemName; }459 472 } 460 473 #endregion … … 494 507 protected virtual void OnOptimizeChanged() { 495 508 var handler = OptimizeChanged; 509 if (handler != null) handler(this, EventArgs.Empty); 510 } 511 512 public event EventHandler CombinationsCountChanged; 513 protected void OnCombinationsCountChanged() { 514 var handler = CombinationsCountChanged; 496 515 if (handler != null) handler(this, EventArgs.Empty); 497 516 } -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ParameterConfigurations/SingleValuedParameterConfiguration.cs
r8517 r8535 29 29 [StorableClass] 30 30 public class SingleValuedParameterConfiguration : ParameterConfiguration { 31 32 31 #region Constructors and Cloning 33 32 [StorableConstructor] 34 33 protected SingleValuedParameterConfiguration(bool deserializing) : base(deserializing) { } 34 protected SingleValuedParameterConfiguration(SingleValuedParameterConfiguration original, Cloner cloner) : base(original, cloner) { } 35 35 public SingleValuedParameterConfiguration(string parameterName, IValueParameter valueParameter) 36 36 : base(parameterName, valueParameter, false) { … … 57 57 this.validValues, 58 58 this.IsNullable); 59 }60 protected SingleValuedParameterConfiguration(SingleValuedParameterConfiguration original, Cloner cloner)61 : base(original, cloner) {62 59 } 63 60 public override IDeepCloneable Clone(Cloner cloner) { -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/RangeConstraints/ConstrainedValue.cs
r8517 r8535 86 86 } 87 87 88 #region constructors and cloning 89 public ConstrainedValue() { } 88 #region Constructors and Cloning 90 89 [StorableConstructor] 91 90 protected ConstrainedValue(bool deserializing) : base(deserializing) { } 92 public ConstrainedValue(IItem value, Type valueDataType, IItemSet<IItem> validValues, bool isNullable) {93 this.Value = value;94 this.ValueDataType = valueDataType;95 this.ValidValues = validValues;96 this.isNullable = isNullable;97 }98 91 protected ConstrainedValue(ConstrainedValue original, Cloner cloner) 99 92 : base(original, cloner) { … … 103 96 this.isNullable = original.isNullable; 104 97 } 105 public override IDeepCloneable Clone(Cloner cloner) { 106 return new ConstrainedValue(this, cloner); 98 public ConstrainedValue() : base() { } 99 public ConstrainedValue(IItem value, Type valueDataType, IItemSet<IItem> validValues, bool isNullable) 100 : base() { 101 this.Value = value; 102 this.ValueDataType = valueDataType; 103 this.ValidValues = validValues; 104 this.isNullable = isNullable; 107 105 } 108 106 [StorableHook(HookType.AfterDeserialization)] 109 107 private void AfterDeserialization() { 110 108 if (this.value != null) RegisterEvents(); 109 } 110 public override IDeepCloneable Clone(Cloner cloner) { 111 return new ConstrainedValue(this, cloner); 111 112 } 112 113 #endregion -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/RangeConstraints/DoubleValueRange.cs
r8517 r8535 30 30 [StorableClass] 31 31 public class DoubleValueRange : Range<DoubleValue> { 32 33 public override DoubleValue LowerBound { 34 get { 35 return base.LowerBound; 36 } 37 set { 38 base.LowerBound = value; 39 } 40 } 41 42 public DoubleValueRange(DoubleValue lowerBound, DoubleValue upperBound, DoubleValue stepSize) : base(lowerBound, upperBound, stepSize) { } 32 #region Constructors and Cloning 43 33 [StorableConstructor] 44 34 protected DoubleValueRange(bool deserializing) : base(deserializing) { } 45 35 protected DoubleValueRange(DoubleValueRange original, Cloner cloner) : base(original, cloner) { } 36 public DoubleValueRange(DoubleValue lowerBound, DoubleValue upperBound, DoubleValue stepSize) : base(lowerBound, upperBound, stepSize) { } 46 37 public override IDeepCloneable Clone(Cloner cloner) { 47 38 return new DoubleValueRange(this, cloner); 48 39 } 40 #endregion 49 41 50 42 protected override DoubleValue GetRandomSample(IRandom random) { -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/RangeConstraints/IntValueRange.cs
r8517 r8535 30 30 [StorableClass] 31 31 public class IntValueRange : Range<IntValue> { 32 33 public IntValueRange(IntValue lowerBound, IntValue upperBound, IntValue stepSize) : base(lowerBound, upperBound, stepSize) { } 32 #region Constructors and Cloning 34 33 [StorableConstructor] 35 34 protected IntValueRange(bool deserializing) : base(deserializing) { } 36 35 protected IntValueRange(IntValueRange original, Cloner cloner) : base(original, cloner) { } 36 public IntValueRange(IntValue lowerBound, IntValue upperBound, IntValue stepSize) : base(lowerBound, upperBound, stepSize) { } 37 37 public override IDeepCloneable Clone(Cloner cloner) { 38 38 return new IntValueRange(this, cloner); 39 39 } 40 #endregion 40 41 41 42 protected override IntValue GetRandomSample(IRandom random) { -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/RangeConstraints/PercentValueRange.cs
r8517 r8535 30 30 [StorableClass] 31 31 public class PercentValueRange : Range<PercentValue> { 32 33 public PercentValueRange(PercentValue lowerBound, PercentValue upperBound, PercentValue stepSize) : base(lowerBound, upperBound, stepSize) { } 32 #region Constructors and Cloning 34 33 [StorableConstructor] 35 34 protected PercentValueRange(bool deserializing) : base(deserializing) { } 36 35 protected PercentValueRange(PercentValueRange original, Cloner cloner) : base(original, cloner) { } 36 public PercentValueRange(PercentValue lowerBound, PercentValue upperBound, PercentValue stepSize) : base(lowerBound, upperBound, stepSize) { } 37 37 public override IDeepCloneable Clone(Cloner cloner) { 38 38 return new PercentValueRange(this, cloner); 39 39 } 40 #endregion 40 41 41 42 protected override PercentValue GetRandomSample(IRandom random) { -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/RangeConstraints/Range.cs
r8517 r8535 38 38 if (lowerBound != value) { 39 39 if (lowerBound != null) { 40 lowerBound.ValueChanged -= new EventHandler(lowerBound_ValueChanged); 40 41 lowerBound.ValueChanged -= new EventHandler(lowerBound_ToStringChanged); 41 42 } 42 43 lowerBound = value; 43 44 if (lowerBound != null) { 45 lowerBound.ValueChanged += new EventHandler(lowerBound_ValueChanged); 44 46 lowerBound.ValueChanged += new EventHandler(lowerBound_ToStringChanged); 45 47 } … … 56 58 if (upperBound != value) { 57 59 if (upperBound != null) { 60 upperBound.ValueChanged -= new EventHandler(upperBound_ValueChanged); 58 61 upperBound.ValueChanged -= new EventHandler(upperBound_ToStringChanged); 59 62 } 60 63 upperBound = value; 61 64 if (upperBound != null) { 65 upperBound.ValueChanged += new EventHandler(upperBound_ValueChanged); 62 66 upperBound.ValueChanged += new EventHandler(upperBound_ToStringChanged); 63 67 } … … 74 78 if (stepSize != value) { 75 79 if (stepSize != null) { 80 stepSize.ValueChanged -= new EventHandler(stepSize_ValueChanged); 76 81 stepSize.ValueChanged -= new EventHandler(stepSize_ToStringChanged); 77 82 } 78 83 stepSize = value; 79 84 if (stepSize != null) { 85 stepSize.ValueChanged += new EventHandler(stepSize_ValueChanged); 80 86 stepSize.ValueChanged += new EventHandler(stepSize_ToStringChanged); 81 87 } … … 101 107 102 108 #region Constructors and Cloning 103 public Range(T lowerBound, T upperBound, T stepSize) {104 this.LowerBound = lowerBound;105 this.UpperBound = upperBound;106 this.StepSize = stepSize;107 }108 109 109 [StorableConstructor] 110 110 protected Range(bool deserializing) : base(deserializing) { } … … 115 115 this.StepSize = cloner.Clone(original.StepSize); 116 116 } 117 117 public Range(T lowerBound, T upperBound, T stepSize) 118 : base() { 119 this.LowerBound = lowerBound; 120 this.UpperBound = upperBound; 121 this.StepSize = stepSize; 122 } 118 123 [StorableHook(HookType.AfterDeserialization)] 119 124 private void AfterDeserialization() { 120 125 if (lowerBound != null) { 126 lowerBound.ValueChanged += new EventHandler(lowerBound_ValueChanged); 121 127 lowerBound.ValueChanged += new EventHandler(lowerBound_ToStringChanged); 122 128 } 123 129 if (upperBound != null) { 130 upperBound.ValueChanged += new EventHandler(upperBound_ValueChanged); 124 131 upperBound.ValueChanged += new EventHandler(upperBound_ToStringChanged); 125 132 } 126 133 if (stepSize != null) { 134 stepSize.ValueChanged += new EventHandler(stepSize_ValueChanged); 127 135 stepSize.ValueChanged += new EventHandler(stepSize_ToStringChanged); 128 136 } … … 131 139 132 140 #region Events 141 private void lowerBound_ValueChanged(object sender, EventArgs e) { 142 OnLowerBoundChanged(); 143 } 144 private void upperBound_ValueChanged(object sender, EventArgs e) { 145 OnUpperBoundChanged(); 146 } 147 private void stepSize_ValueChanged(object sender, EventArgs e) { 148 OnStepSizeChanged(); 149 } 133 150 private void lowerBound_ToStringChanged(object sender, EventArgs e) { 134 151 OnToStringChanged(); … … 189 206 } 190 207 public bool Validate(string value, out string errorMessage) { 191 // TODO: check that upper is larger than lower and that stepsize < upper-lower208 // TODO: check that stepsize < upper - lower 192 209 T lower = (T)lowerBound.Clone(); 193 210 T upper = (T)upperBound.Clone(); … … 206 223 upperBound.SetValue(parts2[1]) && 207 224 stepSize.SetValue(parts1[1])) { 225 if (Comparer<T>.Default.Compare(lowerBound, upperBound) >= 0) { 226 errorMessage = "Invalid bounds. (Lower >= Upper)"; return false; 227 } 208 228 errorMessage = string.Empty; return true; 209 229 } else { -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/SymbolicExpressionGrammar/SymbolValueConfiguration.cs
r8517 r8535 43 43 [StorableConstructor] 44 44 protected SymbolValueConfiguration(bool deserializing) : base(deserializing) { } 45 protected SymbolValueConfiguration(SymbolValueConfiguration original, Cloner cloner) 46 : base(original, cloner) { 47 RegisterInitialFrequencyEvents(); 48 this.parentOptimizable = cloner.Clone(original.parentOptimizable); 49 } 45 50 public SymbolValueConfiguration(Symbol symbol) 46 51 : base() { … … 50 55 this.ActualValue = new ConstrainedValue(symbol, symbol.GetType(), new ItemSet<IItem> { symbol }, false); 51 56 } 52 protected SymbolValueConfiguration(SymbolValueConfiguration original, Cloner cloner)53 : base(original, cloner) {57 [StorableHook(HookType.AfterDeserialization)] 58 private void AfterDeserialization() { 54 59 RegisterInitialFrequencyEvents(); 55 this.parentOptimizable = cloner.Clone(original.parentOptimizable);56 60 } 57 61 public override IDeepCloneable Clone(Cloner cloner) { 58 62 return new SymbolValueConfiguration(this, cloner); 59 }60 [StorableHook(HookType.AfterDeserialization)]61 private void AfterDeserialization() {62 RegisterInitialFrequencyEvents();63 63 } 64 64 #endregion -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/SymbolicExpressionGrammar/SymbolicExpressionGrammarValueConfiguration.cs
r8517 r8535 29 29 [StorableClass] 30 30 public class SymbolicExpressionGrammarValueConfiguration : ParameterizedValueConfiguration { 31 32 31 #region Constructors and Cloning 33 32 [StorableConstructor] 34 33 protected SymbolicExpressionGrammarValueConfiguration(bool deserializing) : base(deserializing) { } 34 protected SymbolicExpressionGrammarValueConfiguration(SymbolicExpressionGrammarValueConfiguration original, Cloner cloner) : base(original, cloner) { } 35 35 public SymbolicExpressionGrammarValueConfiguration() : base() { } 36 public SymbolicExpressionGrammarValueConfiguration(ISymbolicExpressionGrammar grammar) { 36 public SymbolicExpressionGrammarValueConfiguration(ISymbolicExpressionGrammar grammar) 37 : base() { 37 38 this.IsOptimizable = true; 38 39 this.ActualValue = new ConstrainedValue(grammar, grammar.GetType(), new ItemSet<IItem> { grammar }, false); 39 }40 protected SymbolicExpressionGrammarValueConfiguration(SymbolicExpressionGrammarValueConfiguration original, Cloner cloner)41 : base(original, cloner) {42 40 } 43 41 public override IDeepCloneable Clone(Cloner cloner) { -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/TypeValue.cs
r8517 r8535 1 using System; 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 22 using System; 2 23 using System.Drawing; 3 24 using HeuristicLab.Common; … … 32 53 } 33 54 55 #region Constructors and Cloning 56 [StorableConstructor] 57 protected TypeValue(bool deserializing) : base(deserializing) { } 58 protected TypeValue(TypeValue original, Cloner cloner) 59 : base(original, cloner) { 60 this.value = original.value; 61 this.readOnly = original.readOnly; 62 } 34 63 public TypeValue() 35 64 : base() { … … 41 70 this.readOnly = false; 42 71 } 43 [StorableConstructor]44 protected TypeValue(bool deserializing) : base(deserializing) { }45 protected TypeValue(TypeValue original, Cloner cloner)46 : base(original, cloner) {47 this.value = original.value;48 this.readOnly = original.readOnly;49 }50 72 public override IDeepCloneable Clone(Cloner cloner) { 51 73 return new TypeValue(this, cloner); 52 74 } 75 #endregion 53 76 54 77 public virtual TypeValue AsReadOnly() { -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ValueConfigurations/CheckedValueConfigurationCollection.cs
r8517 r8535 28 28 29 29 namespace HeuristicLab.Encodings.ParameterConfigurationEncoding { 30 // todo: check that at least 1 elementsneeds to be selected31 // todo: control creatable item types30 // TODO: check that at least 1 element needs to be selected 31 // TODO: control creatable item types 32 32 [StorableClass] 33 33 public class CheckedValueConfigurationList : CheckedItemList<IValueConfiguration>, ICheckedValueConfigurationList { … … 44 44 } 45 45 46 public CheckedValueConfigurationList(IItemSet<IItem> validValues) { 47 this.validValues = validValues; 48 RegisterEvents(); 49 } 50 public CheckedValueConfigurationList(IEnumerable<IValueConfiguration> collection) 51 : base(collection) { 52 validValues = null; 53 // event wiring not needed 54 } 55 public CheckedValueConfigurationList() { 56 RegisterEvents(); 57 } 46 #region Constructors and Cloning 58 47 [StorableConstructor] 59 48 protected CheckedValueConfigurationList(bool deserializing) … … 67 56 RegisterEvents(); 68 57 } 69 58 public CheckedValueConfigurationList(IItemSet<IItem> validValues) 59 : base() { 60 this.validValues = validValues; 61 RegisterEvents(); 62 } 63 public CheckedValueConfigurationList(IEnumerable<IValueConfiguration> collection) 64 : base(collection) { 65 validValues = null; 66 // event wiring not needed 67 } 68 public CheckedValueConfigurationList() 69 : base() { 70 RegisterEvents(); 71 } 70 72 public override IDeepCloneable Clone(Cloner cloner) { 71 73 return new CheckedValueConfigurationList(this, cloner); … … 75 77 RegisterEvents(); 76 78 } 79 #endregion 77 80 78 81 private void RegisterEvents() { 79 82 this.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsAdded); 80 this.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsRemoved);81 83 } 82 84 83 85 private void DeregisterEvents() { 84 this.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsRemoved);85 86 this.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<IValueConfiguration>>(CheckedValueConfigurationList_ItemsAdded); 86 87 } … … 95 96 } 96 97 } 97 98 private void CheckedValueConfigurationList_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) {99 // auch collectionreset gehört berücksichtigt100 // funktioniert so nicht ganz, weil die view das hinzufügen nicht mitkriegt101 //if (this.Count < minItemCount) {102 // foreach (var item in e.Items) {103 // if (this.Count >= minItemCount)104 // break;105 // this.Add(item);106 // }107 //}108 }109 110 98 } 111 99 } -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ValueConfigurations/NullValueConfiguration.cs
r8517 r8535 28 28 [StorableClass] 29 29 public class NullValueConfiguration : ValueConfiguration { 30 31 public NullValueConfiguration() { 32 this.ActualValue = new ConstrainedValue(null, null, null, true); 33 this.IsOptimizable = false; 34 } 30 #region Constructors and Cloning 35 31 [StorableConstructor] 36 32 protected NullValueConfiguration(bool deserializing) : base(deserializing) { } … … 38 34 : base(original, cloner) { 39 35 } 36 public NullValueConfiguration() 37 : base() { 38 this.ActualValue = new ConstrainedValue(null, null, null, true); 39 this.IsOptimizable = false; 40 } 40 41 public override IDeepCloneable Clone(Cloner cloner) { 41 42 return new NullValueConfiguration(this, cloner); 42 43 } 44 #endregion 43 45 44 46 public override string ToString() { -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ValueConfigurations/ParameterizedValueConfiguration.cs
r8517 r8535 83 83 [StorableConstructor] 84 84 protected ParameterizedValueConfiguration(bool deserializing) : base(deserializing) { } 85 public ParameterizedValueConfiguration() { 85 protected ParameterizedValueConfiguration(ParameterizedValueConfiguration original, Cloner cloner) 86 : base(original, cloner) { 87 this.discoverValidValues = original.discoverValidValues; 88 this.ParameterConfigurations = cloner.Clone(original.parameterConfigurations); 89 } 90 public ParameterizedValueConfiguration() 91 : base() { 86 92 this.ParameterConfigurations = new ItemList<IParameterConfiguration>(); 87 93 } … … 89 95 : base(value, valueDataType) { 90 96 this.discoverValidValues = discoverValidValues; 91 }92 protected ParameterizedValueConfiguration(ParameterizedValueConfiguration original, Cloner cloner)93 : base(original, cloner) {94 this.discoverValidValues = original.discoverValidValues;95 this.ParameterConfigurations = cloner.Clone(original.parameterConfigurations);96 97 } 97 98 public override IDeepCloneable Clone(Cloner cloner) { … … 107 108 if (valueParameter != null) { 108 109 var pc = new ParameterConfiguration(valueParameter.Name, valueParameter, discoverValidValues); 110 pc.CombinationsCountChanged += (sender, args) => OnCombinationsCountChanged(); 109 111 this.parameterConfigurations.Add(pc); 110 112 } -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ValueConfigurations/RangeValueConfiguration.cs
r8517 r8535 46 46 [StorableConstructor] 47 47 protected RangeValueConfiguration(bool deserializing) : base(deserializing) { } 48 public RangeValueConfiguration() {49 50 }51 48 protected RangeValueConfiguration(RangeValueConfiguration original, Cloner cloner) 52 49 : base(original, cloner) { … … 54 51 RegisterRangeConstraintEvents(); 55 52 } 53 public RangeValueConfiguration() : base() { } 56 54 public RangeValueConfiguration(IItem value, Type valueDataType) 57 55 : base(value, valueDataType) { … … 68 66 } 69 67 } 70 public override IDeepCloneable Clone(Cloner cloner) {71 return new RangeValueConfiguration(this, cloner);72 }73 68 [StorableHook(HookType.AfterDeserialization)] 74 69 private void AfterDeserialization() { 75 70 RegisterRangeConstraintEvents(); 76 71 } 72 public override IDeepCloneable Clone(Cloner cloner) { 73 return new RangeValueConfiguration(this, cloner); 74 } 77 75 #endregion 78 76 79 77 private void RegisterRangeConstraintEvents() { 80 if (this.RangeConstraint != null) this.RangeConstraint.ToStringChanged += new EventHandler(RangeConstraint_ToStringChanged); 78 if (this.RangeConstraint != null) { 79 this.RangeConstraint.ToStringChanged += new EventHandler(RangeConstraint_ToStringChanged); 80 this.RangeConstraint.LowerBoundChanged += new EventHandler(RangeConstraintParametersChanged); 81 this.RangeConstraint.UpperBoundChanged += new EventHandler(RangeConstraintParametersChanged); 82 this.RangeConstraint.StepSizeChanged += new EventHandler(RangeConstraintParametersChanged); 83 } 81 84 } 85 82 86 private void DeregisterRangeConstraintEvents() { 83 if (this.RangeConstraint != null) this.RangeConstraint.ToStringChanged -= new EventHandler(RangeConstraint_ToStringChanged); 87 if (this.RangeConstraint != null) { 88 this.RangeConstraint.ToStringChanged -= new EventHandler(RangeConstraint_ToStringChanged); 89 this.RangeConstraint.LowerBoundChanged -= new EventHandler(RangeConstraintParametersChanged); 90 this.RangeConstraint.UpperBoundChanged -= new EventHandler(RangeConstraintParametersChanged); 91 this.RangeConstraint.StepSizeChanged -= new EventHandler(RangeConstraintParametersChanged); 92 } 84 93 } 85 94 … … 119 128 OnToStringChanged(); 120 129 } 130 private void RangeConstraintParametersChanged(object sender, EventArgs e) { 131 OnCombinationsCountChanged(); 132 } 121 133 #endregion 122 134 } -
branches/ParameterConfigurationEncoding/HeuristicLab.Encodings.ParameterConfigurationEncoding/3.3/ValueConfigurations/ValueConfiguration.cs
r8524 r8535 61 61 optimize = value; 62 62 OnOptimizeChanged(); 63 OnCombinationsCountChanged(); 63 64 OnToStringChanged(); 64 65 } … … 117 118 } 118 119 protected ValueConfiguration() : base() { } 119 protected ValueConfiguration(IItem value, Type valueDataType) { 120 protected ValueConfiguration(IItem value, Type valueDataType) 121 : base() { 120 122 this.ActualValue = new ConstrainedValue(value, valueDataType, new ItemSet<IItem> { value }, false); 121 123 this.IsOptimizable = true; … … 168 170 if (handler != null) handler(this, EventArgs.Empty); 169 171 } 172 173 public event EventHandler CombinationsCountChanged; 174 protected void OnCombinationsCountChanged() { 175 var handler = CombinationsCountChanged; 176 if (handler != null) handler(this, EventArgs.Empty); 177 } 170 178 #endregion 171 179
Note: See TracChangeset
for help on using the changeset viewer.