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