Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4984


Ignore:
Timestamp:
11/28/10 23:58:59 (14 years ago)
Author:
cneumuel
Message:

#1215 worked on metaoptimization

Location:
branches/HeuristicLab.MetaOptimization
Files:
3 added
3 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/HeuristicLab.Problems.MetaOptimization.Views-3.3.csproj

    r4982 r4984  
    105105      <DependentUpon>ValueConfigurationCheckedItemList.cs</DependentUpon>
    106106    </Compile>
    107     <Compile Include="ValueConfigurationViews\NumericRangeView.cs">
     107    <Compile Include="ValueConfigurationViews\RangeView.cs">
    108108      <SubType>UserControl</SubType>
    109109    </Compile>
    110     <Compile Include="ValueConfigurationViews\NumericRangeView.Designer.cs">
    111       <DependentUpon>NumericRangeView.cs</DependentUpon>
     110    <Compile Include="ValueConfigurationViews\RangeView.Designer.cs">
     111      <DependentUpon>RangeView.cs</DependentUpon>
    112112    </Compile>
    113113    <Compile Include="ObjectSelectorDialog.cs">
     
    137137      <DependentUpon>RootValueConfigurationView.cs</DependentUpon>
    138138    </EmbeddedResource>
    139     <EmbeddedResource Include="ValueConfigurationViews\NumericRangeView.resx">
    140       <DependentUpon>NumericRangeView.cs</DependentUpon>
     139    <EmbeddedResource Include="ValueConfigurationViews\RangeView.resx">
     140      <DependentUpon>RangeView.cs</DependentUpon>
    141141    </EmbeddedResource>
    142142    <EmbeddedResource Include="ObjectSelectorDialog.resx">
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/OptimizableView.cs

    r4981 r4984  
    2929    protected override void DeregisterContentEvents() {
    3030      Content.OptimizeChanged -= new EventHandler(Content_OptimizeChanged);
     31      Content.IsOptimizableChanged -= new EventHandler(Content_IsOptimizabeChanged);
    3132      base.DeregisterContentEvents();
    3233    }
     
    3435    protected override void RegisterContentEvents() {
    3536      base.RegisterContentEvents();
     37      Content.IsOptimizableChanged += new EventHandler(Content_IsOptimizabeChanged);
    3638      Content.OptimizeChanged += new EventHandler(Content_OptimizeChanged);
    3739    }
     
    4648          this.viewHost.ViewType = null;
    4749          if (Content is IParameterConfiguration) {
    48             // this is a shortcut if only one possible ValueConfiguration is available
    49             //if (((IParameterConfiguration)Content).ValueConfigurations.Count == 1) {
    50             //  IValueConfiguration vc = ((IParameterConfiguration)Content).ValueConfigurations.First();
    51             //  vc.Optimize = true;
    52             //  this.viewHost.Content = vc;
    53             //} else {
    54             //  this.viewHost.Content = ((IParameterConfiguration)Content).ValueConfigurations;
    55             //}
    5650            this.viewHost.Content = ((IParameterConfiguration)Content).ValueConfigurations;
    5751          } else if (Content is IValueConfiguration) {
    5852            if (Content.ConstrainedValue.ValueDataType == typeof(IntValue) ||
    59                 Content.ConstrainedValue.ValueDataType == typeof(DoubleValue)) {
     53                Content.ConstrainedValue.ValueDataType == typeof(DoubleValue) ||
     54                Content.ConstrainedValue.ValueDataType == typeof(PercentValue)) {
    6055              this.viewHost.Content = ((IValueConfiguration)Content).RangeConstraint;
     56            } else if(Content.ConstrainedValue.ValueDataType == typeof(BoolValue)) {
     57              this.viewHost.Content = null; // no configuration required
    6158            } else {
    6259              this.viewHost.Content = ((IValueConfiguration)Content).ParameterConfigurations;
     
    6865          this.viewHost.Content = Content.ConstrainedValue;
    6966        }
     67      }
     68    }
     69    void Content_IsOptimizabeChanged(object sender, EventArgs e) {
     70      if (InvokeRequired) {
     71        Invoke(new EventHandler(Content_IsOptimizabeChanged), sender, e);
     72      } else {
     73        SetEnabledStateOfControls();
    7074      }
    7175    }
     
    8387    protected override void SetEnabledStateOfControls() {
    8488      base.SetEnabledStateOfControls();
     89      if (Content != null) {
     90        this.optimizeCheckBox.Enabled = !this.ReadOnly && Content.IsOptimizable;
     91      }
    8592    }
    8693
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ParameterConfigurations/ParameterConfiguration.cs

    r4982 r4984  
    99namespace HeuristicLab.Problems.MetaOptimization {
    1010  [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
    1216    [Storable]
    1317    public string Filename { get; set; }
     
    2630          }
    2731          OnOptimizeChanged();
     32          OnToStringChanged();
    2833        }
    2934      }
     
    3742        if (parameterName != value) {
    3843          parameterName = value;
     44          OnToStringChanged();
    3945        }
    4046      }
     
    6571    public ICheckedValueConfigurationCollection ValueConfigurations {
    6672      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      }
    6880    }
    6981
     
    116128    #endregion
    117129
     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
    118142    private void PopulateValueConfigurations() {
    119143      foreach (IItem validValue in this.validValues) {
     
    132156    }
    133157
    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    }
    153167
    154168    #region INamedItem Properties
     
    167181      get { return false; }
    168182    }
    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; }
    180191    }
    181192    #endregion
     
    199210      if (handler != null) handler(sender, e);
    200211    }
    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);
    212217    }
    213218
     
    220225
    221226    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      }
    223232    }
    224233
     
    226235      if (parameter is IValueParameter) {
    227236        IValueParameter valueParameter = parameter as IValueParameter;
    228 
    229237        return new ParameterConfiguration(parameter.Name, valueParameter);
    230238      }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encodings/ValueConfigurations/ValueConfiguration.cs

    r4982 r4984  
    1010  // TODO: ItemName/Descr, storability
    1111  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
    1223    protected bool optimize;
    1324    public bool Optimize {
     
    5263      get { return rangeConstraint; }
    5364    }
    54    
     65
    5566    #region Constructors and Cloning
    5667    public ValueConfiguration(IItem value, Type valueDataType) {
    5768      this.ParameterConfigurations = new ItemList<IParameterConfiguration>();
    5869      this.ConstrainedValue = new ConstrainedValue(value, valueDataType);
     70      this.IsOptimizable = true;
    5971      if (constrainedValue.ValueDataType == typeof(IntValue)) {
    6072        rangeConstraint = new Range<IntValue>(new IntValue(0), (IntValue)value, new IntValue(1));
    6173      } 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
    6379      } else {
    6480        rangeConstraint = null;
     
    7490      this.ConstrainedValue = cloner.Clone(original.ConstrainedValue);
    7591      this.rangeConstraint = cloner.Clone(original.RangeConstraint);
     92      this.IsOptimizable = original.IsOptimizable;
    7693      RegisterEvents();
    7794    }
     
    131148    }
    132149
     150    public virtual event EventHandler IsOptimizableChanged;
     151    private void OnIsOptimizableChanged() {
     152      var handler = IsOptimizableChanged;
     153      if (handler != null) handler(this, EventArgs.Empty);
     154    }
     155
    133156    public virtual event EventHandler OptimizeChanged;
    134157    protected virtual void OnOptimizeChanged() {
     
    140163    public override string ToString() {
    141164      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          }
    144171        } 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        }
    147178      } else {
    148179        return base.ToString();
    149180      }
    150 
    151181    }
    152182  }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IOptimizable.cs

    r4981 r4984  
    88namespace HeuristicLab.Problems.MetaOptimization {
    99  public interface IOptimizable : IItem {
     10    bool IsOptimizable { get; }
    1011    bool Optimize { get; set; }
    1112    ConstrainedValue ConstrainedValue { get; set; }
     13
     14    event EventHandler IsOptimizableChanged;
    1215    event EventHandler OptimizeChanged;
    1316  }
Note: See TracChangeset for help on using the changeset viewer.