Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/05/10 00:10:13 (14 years ago)
Author:
mkommend
Message:

implemented first version of RunConstraints (ticket #970)

Location:
trunk/sources/HeuristicLab.Optimization/3.3
Files:
5 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r3601 r3614  
    8787    <Compile Include="Algorithm.cs" />
    8888    <Compile Include="BatchRun.cs" />
     89    <Compile Include="RunCollectionComparisonConstraint.cs" />
     90    <Compile Include="RunCollectionConstraintCollection.cs" />
     91    <Compile Include="RunCollectionTypeCompatiblityConstraint.cs" />
     92    <Compile Include="RunCollectionEqualityConstraint.cs" />
    8993    <Compile Include="Interfaces\ISingleObjectiveReplacer.cs" />
    9094    <Compile Include="Interfaces\IMigrator.cs" />
     
    97101    <Compile Include="Interfaces\IStrategyParameterCreator.cs" />
    98102    <Compile Include="Interfaces\IRun.cs" />
     103    <Compile Include="IRunCollectionConstraint.cs" />
    99104    <Compile Include="OptimizerList.cs" />
    100105    <Compile Include="Experiment.cs" />
  • trunk/sources/HeuristicLab.Optimization/3.3/RunCollection.cs

    r3492 r3614  
    2727using HeuristicLab.Data;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.Collections;
    2930
    3031namespace HeuristicLab.Optimization {
     
    3839      parameterNames = new List<string>();
    3940      resultNames = new List<string>();
    40     }
    41 
    42     protected static Type[] viewableDataTypes = new Type[]{typeof(BoolValue), typeof(DoubleValue), typeof(IntValue),
    43       typeof(PercentValue), typeof(StringValue)};
     41      dataTypes = new Dictionary<string, HashSet<Type>>();
     42      constraints = new RunCollectionConstraintCollection();
     43      constraints.ItemsAdded += new CollectionItemsChangedEventHandler<IRunCollectionConstraint>(Constraints_ItemsAdded);
     44      constraints.ItemsRemoved += new CollectionItemsChangedEventHandler<IRunCollectionConstraint>(Constraints_ItemsRemoved);
     45      constraints.CollectionReset += new CollectionItemsChangedEventHandler<IRunCollectionConstraint>(Constraints_CollectionReset);
     46    }
     47    private Dictionary<string, HashSet<Type>> dataTypes;
     48    public IEnumerable<Type> GetDataType(string columnName) {
     49      if (!dataTypes.ContainsKey(columnName))
     50        return new Type[0];
     51      return dataTypes[columnName];
     52    }
     53    private RunCollectionConstraintCollection constraints;
     54    public RunCollectionConstraintCollection Constraints {
     55      get { return constraints;}
     56    }
    4457
    4558    protected override void OnCollectionReset(IEnumerable<IRun> items, IEnumerable<IRun> oldItems) {
     
    90103        return false;
    91104      if (!parameterNames.Contains(name)) {
    92         // && viewableDataTypes.Any(x => x.IsAssignableFrom(value.GetType()))) {
    93105        parameterNames.Add(name);
    94         return true;
    95       }
     106        dataTypes[name] = new HashSet<Type>();
     107        dataTypes[name].Add(value.GetType());
     108        return true;
     109      }
     110      dataTypes[name].Add(value.GetType());
    96111      return false;
    97112    }
     
    100115        return false;
    101116      if (!resultNames.Contains(name)) {
    102         // && viewableDataTypes.Any(x => x.IsAssignableFrom(value.GetType()))) {
    103117        resultNames.Add(name);
    104         return true;
    105       }
     118        dataTypes[name] = new HashSet<Type>();
     119        dataTypes[name].Add(value.GetType());
     120        return true;
     121      }
     122      dataTypes[name].Add(value.GetType());
    106123      return false;
    107124    }
     
    221238    public bool SetValue(string value, int rowIndex, int columnIndex) { throw new NotSupportedException(); }
    222239    #endregion
     240
     241    #region filtering
     242    private void UpdateFiltering() {
     243      list.ForEach(r => r.Visible = true);
     244      foreach (IRunCollectionConstraint constraint in this.constraints)
     245        constraint.Check();
     246    }
     247
     248    protected virtual void RegisterConstraintEvents(IEnumerable<IRunCollectionConstraint> constraints) {
     249      foreach (IRunCollectionConstraint constraint in constraints) {
     250        constraint.ActiveChanged += new EventHandler(Constraint_ActiveChanged);
     251        constraint.ConstrainedValueChanged += new EventHandler(Constraint_ConstrainedValueChanged);
     252        constraint.ConstraintOperationChanged += new EventHandler(Constraint_ConstraintOperationChanged);
     253        constraint.ConstraintDataChanged += new EventHandler(Constraint_ConstraintDataChanged);
     254      }
     255    }
     256    protected virtual void DeregisterConstraintEvents(IEnumerable<IRunCollectionConstraint> constraints) {
     257      foreach (IRunCollectionConstraint constraint in constraints) {
     258        constraint.ActiveChanged -= new EventHandler(Constraint_ActiveChanged);
     259        constraint.ConstrainedValueChanged -= new EventHandler(Constraint_ConstrainedValueChanged);
     260        constraint.ConstraintOperationChanged -= new EventHandler(Constraint_ConstraintOperationChanged);
     261        constraint.ConstraintDataChanged -= new EventHandler(Constraint_ConstraintDataChanged);
     262      }
     263    }
     264
     265    protected virtual void Constraints_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRunCollectionConstraint> e) {
     266      DeregisterConstraintEvents(e.OldItems);
     267      RegisterConstraintEvents(e.Items);
     268      this.UpdateFiltering();
     269    }
     270    protected virtual void Constraints_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRunCollectionConstraint> e) {
     271      RegisterConstraintEvents(e.Items);
     272      foreach (IRunCollectionConstraint constraint in e.Items)
     273        constraint.ConstrainedValue = this;
     274      this.UpdateFiltering();
     275    }
     276    protected virtual void Constraints_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRunCollectionConstraint> e) {
     277      DeregisterConstraintEvents(e.Items);
     278      this.UpdateFiltering();
     279    }
     280    protected virtual void Constraint_ActiveChanged(object sender, EventArgs e) {
     281      this.UpdateFiltering();
     282    }
     283    protected virtual void Constraint_ConstrainedValueChanged(object sender, EventArgs e) {
     284      //mkommend: this method is intentionally left empty, because the constrainedValue is set in the ItemsAdded method
     285    }
     286    protected virtual void Constraint_ConstraintOperationChanged(object sender, EventArgs e) {
     287      this.UpdateFiltering();
     288    }
     289    protected virtual void Constraint_ConstraintDataChanged(object sender, EventArgs e) {
     290      this.UpdateFiltering();
     291    }
     292    #endregion
    223293  }
    224294}
Note: See TracChangeset for help on using the changeset viewer.