Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimization/3.3/RunCollectionModificationEvaluator.cs @ 6675

Last change on this file since 6675 was 6667, checked in by epitzer, 13 years ago

Modify run collection to force update of cached values (#1622)

File size: 2.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Common;
6using HeuristicLab.Core;
7using HeuristicLab.Parameters;
8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9
10namespace HeuristicLab.Optimization {
11  [Item("RunCollection Modification Evaluator", "Applies a series of RunCollection modifiers.")]
12  [Creatable("Testing & Analysis")]
13  [StorableClass]
14  public class RunCollectionModificationEvaluator : ParameterizedNamedItem, IStorableContent {
15
16    public string Filename { get; set; }
17
18    #region Parameters
19    public ValueParameter<RunCollection> RunCollectionParameter {
20      get { return (ValueParameter<RunCollection>)Parameters["RunCollection"]; }
21    }
22
23    public ValueParameter<CheckedItemList<IRunCollectionModifier>> ModifiersParameter {
24      get { return (ValueParameter<CheckedItemList<IRunCollectionModifier>>)Parameters["Modifiers"]; }
25    }
26    #endregion
27
28    #region Parameter Values
29    public RunCollection RunCollection {
30      get { return RunCollectionParameter.Value; }
31    }
32    public CheckedItemList<IRunCollectionModifier> Modifiers {
33      get { return ModifiersParameter.Value; }
34    }
35    #endregion
36
37    #region Construction & Cloning
38    [StorableConstructor]
39    protected RunCollectionModificationEvaluator(bool deserializing) : base(deserializing) { }
40    protected RunCollectionModificationEvaluator(RunCollectionModificationEvaluator original, Cloner cloner) : base(original, cloner) { }
41    public RunCollectionModificationEvaluator() {
42      Parameters.Add(new ValueParameter<RunCollection>("RunCollection", "The RunCollection to be modified.", new RunCollection()));
43      Parameters.Add(new ValueParameter<CheckedItemList<IRunCollectionModifier>>("Modifiers", "A list of modifiers to be applied to the run collection.", new CheckedItemList<IRunCollectionModifier>()));
44    }
45    public override IDeepCloneable Clone(Cloner cloner) {
46      return new RunCollectionModificationEvaluator(this, cloner);
47    }
48    #endregion
49
50    public void Evaluate() {
51      RunCollection.UpdateOfRunsInProgress = true;
52      var runs = RunCollection.Where(r => r.Visible).ToList();
53      foreach (var modifier in Modifiers.CheckedItems)
54        modifier.Value.Modify(runs);
55      RunCollection.UpdateOfRunsInProgress = false;
56      if (runs.Count > 0) { // force update
57        var run = (IRun) runs[0].Clone();
58        RunCollection.Add(run);
59        RunCollection.Remove(run);
60      }
61    }
62  }
63}
Note: See TracBrowser for help on using the repository browser.