- Timestamp:
- 11/28/10 23:58:59 (14 years ago)
- Location:
- branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ParameterConfigurations/ParameterConfiguration.cs
r4982 r4984 9 9 namespace HeuristicLab.Problems.MetaOptimization { 10 10 [StorableClass] 11 public class ParameterConfiguration : DeepCloneable, IParameterConfiguration, IStorableContent { 11 public class ParameterConfiguration : Item, IParameterConfiguration, IStorableContent { 12 public bool IsOptimizable { 13 get { return true; } 14 } 15 12 16 [Storable] 13 17 public string Filename { get; set; } … … 26 30 } 27 31 OnOptimizeChanged(); 32 OnToStringChanged(); 28 33 } 29 34 } … … 37 42 if (parameterName != value) { 38 43 parameterName = value; 44 OnToStringChanged(); 39 45 } 40 46 } … … 65 71 public ICheckedValueConfigurationCollection ValueConfigurations { 66 72 get { return this.valueConfigurations; } 67 protected set { this.valueConfigurations = value; } 73 protected set { 74 if (this.valueConfigurations != value) { 75 if (this.valueConfigurations != null) DeregisterValueConfigurationEvents(); 76 this.valueConfigurations = value; 77 if (this.valueConfigurations != null) RegisterValueConfigurationEvents(); 78 } 79 } 68 80 } 69 81 … … 116 128 #endregion 117 129 130 private void RegisterValueConfigurationEvents() { 131 this.ValueConfigurations.CheckedItemsChanged += new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(ValueConfigurations_CheckedItemsChanged); 132 this.ValueConfigurations.ItemsAdded += new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(ValueConfigurations_ItemsAdded); 133 this.ValueConfigurations.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(ValueConfigurations_ItemsRemoved); 134 } 135 136 private void DeregisterValueConfigurationEvents() { 137 this.ValueConfigurations.CheckedItemsChanged -= new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(ValueConfigurations_CheckedItemsChanged); 138 this.ValueConfigurations.ItemsAdded -= new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(ValueConfigurations_ItemsAdded); 139 this.ValueConfigurations.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<IValueConfiguration>(ValueConfigurations_ItemsRemoved); 140 } 141 118 142 private void PopulateValueConfigurations() { 119 143 foreach (IItem validValue in this.validValues) { … … 132 156 } 133 157 134 //void ValidValues_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<IItem>> e) { 135 // var oldItems = e.OldItems.Select(x => x.Value); 136 // var newItems = e.Items.Select(x => x.Value); 137 // var intersection = oldItems.Intersect(newItems); 138 // var removedItems = oldItems.Where(x => !intersection.Contains(x)); 139 // var addedItems = newItems.Where(x => !intersection.Contains(x)); 140 141 // foreach (var item in removedItems) { 142 // RemoveValueConfiguration(item); 143 // } 144 // foreach (var item in addedItems) { 145 // this.ValueConfigurations.Add(new ValueConfiguration(item, item.GetType())); 146 // } 147 //} 148 149 //private void RemoveValueConfiguration(IItem item) { 150 // IValueConfiguration vc = this.ValueConfigurations.Single(x => x.ValueDataType == item.GetType()); 151 // this.ValueConfigurations.Remove(vc); 152 //} 158 void ValueConfigurations_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IValueConfiguration> e) { 159 OnToStringChanged(); 160 } 161 void ValueConfigurations_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IValueConfiguration> e) { 162 OnToStringChanged(); 163 } 164 void ValueConfigurations_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IValueConfiguration> e) { 165 OnToStringChanged(); 166 } 153 167 154 168 #region INamedItem Properties … … 167 181 get { return false; } 168 182 } 169 public virtual string ItemDescription { 170 get { return parameter.Description; } 171 } 172 public virtual System.Drawing.Image ItemImage { 173 get { return parameter.ItemImage; } 174 } 175 public virtual string ItemName { 176 get { return parameter.ItemName; } 177 } 178 public virtual Version ItemVersion { 179 get { return parameter.ItemVersion; } 183 public override string ItemDescription { 184 get { return parameter != null ? parameter.Description : base.ItemDescription; } 185 } 186 public override System.Drawing.Image ItemImage { 187 get { return parameter != null ? parameter.ItemImage : base.ItemImage; } 188 } 189 public override string ItemName { 190 get { return parameter != null ?parameter.ItemName : base.ItemName; } 180 191 } 181 192 #endregion … … 199 210 if (handler != null) handler(sender, e); 200 211 } 201 202 public virtual event EventHandler ItemImageChanged; 203 protected virtual void OnItemImageChanged(object sender, EventArgs e) { 204 var handler = ItemImageChanged; 205 if (handler != null) handler(sender, e); 206 } 207 208 public virtual event EventHandler ToStringChanged; 209 protected virtual void OnStringChanged(object sender, EventArgs e) { 210 var handler = ToStringChanged; 211 if (handler != null) handler(this, e); // important to set 'this' as sender 212 213 public virtual event EventHandler IsOptimizableChanged; 214 private void OnIsOptimizableChanged() { 215 var handler = IsOptimizableChanged; 216 if (handler != null) handler(this, EventArgs.Empty); 212 217 } 213 218 … … 220 225 221 226 public override string ToString() { 222 return string.Format("{0}: {1}", ParameterName, ConstrainedValue.Value); 227 if (Optimize) { 228 return string.Format("{0}: (Optimize: {1})", ParameterName, ValueConfigurations.CheckedItems.Count()); 229 } else { 230 return string.Format("{0}: {1}", ParameterName, ConstrainedValue.Value); 231 } 223 232 } 224 233 … … 226 235 if (parameter is IValueParameter) { 227 236 IValueParameter valueParameter = parameter as IValueParameter; 228 229 237 return new ParameterConfiguration(parameter.Name, valueParameter); 230 238 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ValueConfigurations/ValueConfiguration.cs
r4982 r4984 10 10 // TODO: ItemName/Descr, storability 11 11 public class ValueConfiguration : Item, IValueConfiguration { 12 protected bool isOptimizable; 13 public bool IsOptimizable { 14 get { return isOptimizable; } 15 set { 16 if (this.isOptimizable != value) { 17 this.isOptimizable = value; 18 OnIsOptimizableChanged(); 19 } 20 } 21 } 22 12 23 protected bool optimize; 13 24 public bool Optimize { … … 52 63 get { return rangeConstraint; } 53 64 } 54 65 55 66 #region Constructors and Cloning 56 67 public ValueConfiguration(IItem value, Type valueDataType) { 57 68 this.ParameterConfigurations = new ItemList<IParameterConfiguration>(); 58 69 this.ConstrainedValue = new ConstrainedValue(value, valueDataType); 70 this.IsOptimizable = true; 59 71 if (constrainedValue.ValueDataType == typeof(IntValue)) { 60 72 rangeConstraint = new Range<IntValue>(new IntValue(0), (IntValue)value, new IntValue(1)); 61 73 } else if (constrainedValue.ValueDataType == typeof(DoubleValue)) { 62 rangeConstraint = new Range<DoubleValue>(new DoubleValue(0), (DoubleValue)value, new DoubleValue(0.1)); 74 rangeConstraint = new Range<DoubleValue>(new DoubleValue(0), (DoubleValue)value, new DoubleValue(0.01)); 75 } else if (constrainedValue.ValueDataType == typeof(PercentValue)) { 76 rangeConstraint = new Range<PercentValue>(new PercentValue(0), new PercentValue(1), new PercentValue(0.001)); 77 } else if (constrainedValue.ValueDataType == typeof(BoolValue)) { 78 this.IsOptimizable = false; // there is nothing to configure for bools 63 79 } else { 64 80 rangeConstraint = null; … … 74 90 this.ConstrainedValue = cloner.Clone(original.ConstrainedValue); 75 91 this.rangeConstraint = cloner.Clone(original.RangeConstraint); 92 this.IsOptimizable = original.IsOptimizable; 76 93 RegisterEvents(); 77 94 } … … 131 148 } 132 149 150 public virtual event EventHandler IsOptimizableChanged; 151 private void OnIsOptimizableChanged() { 152 var handler = IsOptimizableChanged; 153 if (handler != null) handler(this, EventArgs.Empty); 154 } 155 133 156 public virtual event EventHandler OptimizeChanged; 134 157 protected virtual void OnOptimizeChanged() { … … 140 163 public override string ToString() { 141 164 if (ConstrainedValue != null && ConstrainedValue.Value != null) { 142 if(Optimize) { 143 return string.Format("{0}: {1}", ConstrainedValue.Value.ItemName, RangeConstraint); 165 if (ConstrainedValue.Value is IParameterizedItem) { 166 if (Optimize) { 167 return string.Format("{0} (Optimize)", ConstrainedValue.Value.ItemName); 168 } else { 169 return string.Format("{0}", ConstrainedValue.Value.ItemName); 170 } 144 171 } else { 145 return string.Format("{0}: {1}", ConstrainedValue.Value.ItemName, ConstrainedValue.Value); 146 } 172 if (Optimize) { 173 return string.Format("{0} (Optimize: {1})", ConstrainedValue.Value.ItemName, RangeConstraint); 174 } else { 175 return string.Format("{0}: {1}", ConstrainedValue.Value.ItemName, ConstrainedValue.Value); 176 } 177 } 147 178 } else { 148 179 return base.ToString(); 149 180 } 150 151 181 } 152 182 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IOptimizable.cs
r4981 r4984 8 8 namespace HeuristicLab.Problems.MetaOptimization { 9 9 public interface IOptimizable : IItem { 10 bool IsOptimizable { get; } 10 11 bool Optimize { get; set; } 11 12 ConstrainedValue ConstrainedValue { get; set; } 13 14 event EventHandler IsOptimizableChanged; 12 15 event EventHandler OptimizeChanged; 13 16 }
Note: See TracChangeset
for help on using the changeset viewer.