[5303] | 1 | using System.Linq;
|
---|
| 2 | using HeuristicLab.Common;
|
---|
| 3 | using HeuristicLab.Core;
|
---|
| 4 | using HeuristicLab.Data;
|
---|
| 5 | using HeuristicLab.Operators;
|
---|
| 6 | using HeuristicLab.Optimization;
|
---|
| 7 | using HeuristicLab.Parameters;
|
---|
| 8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 9 | using System.Collections.Generic;
|
---|
| 10 | using System;
|
---|
| 11 |
|
---|
| 12 | namespace HeuristicLab.Problems.MetaOptimization {
|
---|
| 13 | /// <summary>
|
---|
| 14 | /// TODO
|
---|
| 15 | /// </summary>
|
---|
| 16 | [Item("RunsAnalyzer", "")]
|
---|
| 17 | [StorableClass]
|
---|
| 18 | public sealed class RunsAnalyzer : SingleSuccessorOperator, IAnalyzer {
|
---|
| 19 |
|
---|
| 20 | public ValueLookupParameter<ResultCollection> ResultsParameter {
|
---|
| 21 | get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
|
---|
| 22 | }
|
---|
| 23 | public ScopeTreeLookupParameter<ParameterConfigurationTree> ParameterConfigurationParameter {
|
---|
| 24 | get { return (ScopeTreeLookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; }
|
---|
| 25 | }
|
---|
| 26 | public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
|
---|
| 27 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
|
---|
| 28 | }
|
---|
| 29 | public LookupParameter<DoubleArray> ProblemQualityReferenceParameter {
|
---|
| 30 | get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityReferences"]; }
|
---|
| 31 | }
|
---|
[5337] | 32 | public LookupParameter<ConstrainedItemList<IProblem>> ProblemsParameter {
|
---|
| 33 | get { return (LookupParameter<ConstrainedItemList<IProblem>>)Parameters[MetaOptimizationProblem.ProblemsParameterName]; }
|
---|
[5303] | 34 | }
|
---|
| 35 | public ValueLookupParameter<ItemDictionary<StringValue, RunCollection>> RunsParameter {
|
---|
| 36 | get { return (ValueLookupParameter<ItemDictionary<StringValue, RunCollection>>)Parameters["Runs"]; }
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | public RunsAnalyzer()
|
---|
| 40 | : base() {
|
---|
| 41 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", ""));
|
---|
| 42 | Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", ""));
|
---|
| 43 | Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", ""));
|
---|
| 44 | Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityReferences", ""));
|
---|
[5337] | 45 | Parameters.Add(new LookupParameter<ConstrainedItemList<IProblem>>(MetaOptimizationProblem.ProblemsParameterName, ""));
|
---|
[5303] | 46 | Parameters.Add(new ValueLookupParameter<ItemDictionary<StringValue, RunCollection>>("Runs", "", new ItemDictionary<StringValue, RunCollection>()));
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | [StorableConstructor]
|
---|
| 50 | private RunsAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
| 51 | private RunsAnalyzer(RunsAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
| 52 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 53 | return new RunsAnalyzer(this, cloner);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | public override IOperation Apply() {
|
---|
| 57 | ResultCollection results = ResultsParameter.ActualValue;
|
---|
| 58 | ItemArray<ParameterConfigurationTree> solutions = ParameterConfigurationParameter.ActualValue;
|
---|
| 59 | ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
|
---|
| 60 | ItemDictionary<StringValue, RunCollection> allRuns = RunsParameter.ActualValue;
|
---|
| 61 |
|
---|
| 62 | foreach (var solution in solutions) {
|
---|
| 63 | string key = solution.ParameterInfoString;
|
---|
| 64 | if (allRuns.Count(x => x.Key.Value == key) == 0) {
|
---|
| 65 | allRuns.Add(new StringValue(key), new RunCollection());
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | foreach (var run in solution.Runs) {
|
---|
| 69 | if (!((BoolValue)run.Results["Meta.FromCache"]).Value) {
|
---|
| 70 | run.Results["Meta.FromCache"] = new BoolValue(true);
|
---|
| 71 | allRuns.Single(x => x.Key.Value == key).Value.Add(run);
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | if (!results.ContainsKey("Runs")) {
|
---|
| 77 | results.Add(new Result("Runs", allRuns));
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | return base.Apply();
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 | }
|
---|