[6662] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using HeuristicLab.Common;
|
---|
| 6 | using HeuristicLab.Core;
|
---|
| 7 | using HeuristicLab.Parameters;
|
---|
| 8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 9 |
|
---|
| 10 | namespace 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;
|
---|
[6667] | 56 | if (runs.Count > 0) { // force update
|
---|
| 57 | var run = (IRun) runs[0].Clone();
|
---|
| 58 | RunCollection.Add(run);
|
---|
| 59 | RunCollection.Remove(run);
|
---|
| 60 | }
|
---|
[6662] | 61 | }
|
---|
| 62 | }
|
---|
| 63 | }
|
---|