Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProgrammableProblem/HeuristicLab.Optimization/3.3/BasicProblems/Operators/MultiObjectiveAnalyzer.cs @ 11949

Last change on this file since 11949 was 11949, checked in by mkommend, 9 years ago

#2174: Distributed files in programmable problem branch to the correct plugins.

File size: 2.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using HeuristicLab.Common;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
7using HeuristicLab.Operators;
8using HeuristicLab.Optimization;
9using HeuristicLab.Parameters;
10using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
11
12namespace HeuristicLab.Optimization {
13  [Item("Multi-objective Analyzer", "Calls the Analyze method of the problem definition.")]
14  [StorableClass]
15  public class MultiObjectiveAnalyzer : SingleSuccessorOperator, IMultiObjectiveAnalysisOperator, IStochasticOperator {
16    public bool EnabledByDefault { get { return true; } }
17
18    public ILookupParameter<IEncoding> EncodingParameter {
19      get { return (ILookupParameter<IEncoding>)Parameters["Encoding"]; }
20    }
21
22    public IScopeTreeLookupParameter<DoubleArray> QualitiesParameter {
23      get { return (IScopeTreeLookupParameter<DoubleArray>)Parameters["Qualities"]; }
24    }
25
26    public ILookupParameter<ResultCollection> ResultsParameter {
27      get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; }
28    }
29
30    public ILookupParameter<IRandom> RandomParameter {
31      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
32    }
33
34    public Action<Individual[], double[][], ResultCollection, IRandom> AnalyzeAction { get; set; }
35
36    [StorableConstructor]
37    protected MultiObjectiveAnalyzer(bool deserializing) : base(deserializing) { }
38    protected MultiObjectiveAnalyzer(MultiObjectiveAnalyzer original, Cloner cloner) : base(original, cloner) { }
39    public MultiObjectiveAnalyzer() {
40      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
41      Parameters.Add(new LookupParameter<IEncoding>("Encoding", "An item that holds the problem's encoding."));
42      Parameters.Add(new ScopeTreeLookupParameter<DoubleArray>("Qualities", "The qualities of the parameter vector."));
43      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The results collection to write to."));
44    }
45
46    public override IDeepCloneable Clone(Cloner cloner) {
47      return new MultiObjectiveAnalyzer(this, cloner);
48    }
49
50    public override IOperation Apply() {
51      var encoding = EncodingParameter.ActualValue;
52      var results = ResultsParameter.ActualValue;
53      var random = RandomParameter.ActualValue;
54
55      IEnumerable<IScope> scopes = new[] { ExecutionContext.Scope };
56      for (var i = 0; i < QualitiesParameter.Depth; i++)
57        scopes = scopes.Select(x => (IEnumerable<IScope>)x.SubScopes).Aggregate((a, b) => a.Concat(b));
58
59      var individuals = scopes.Select(encoding.GetIndividual).ToArray();
60      AnalyzeAction(individuals, QualitiesParameter.ActualValue.Select(x => x.ToArray()).ToArray(), results, random);
61      return base.Apply();
62    }
63  }
64}
Note: See TracBrowser for help on using the repository browser.