Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking/3.4/EvolutionTrackingOperators/EvolutionTrackingAfterCreationOperator.cs @ 10267

Last change on this file since 10267 was 10267, checked in by bburlacu, 10 years ago

#1772: Updated files in the HeuristicLab.EvolutionTracking project.

File size: 3.7 KB
Line 
1using System.Linq;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Data;
5using HeuristicLab.Operators;
6using HeuristicLab.Optimization;
7using HeuristicLab.Parameters;
8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9
10namespace HeuristicLab.EvolutionaryTracking {
11  [StorableClass]
12  [Item("EvolutionTrackingAfterCrossoverOperator", "An operator that performs additional operators after crossover")]
13  public sealed class EvolutionTrackingAfterCreationOperator : SingleSuccessorOperator {
14    private const string ResultsParameterName = "Results";
15    private const string PopulationGraphParameterName = "PopulationGraph";
16    private const string GenerationsParameterName = "Generations";
17    private const string CurrentScopeParameterName = "CurrentScope";
18    #region Parameter Properties
19    public ILookupParameter<ResultCollection> ResultsParameter {
20      get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; }
21    }
22    private ScopeParameter CurrentScopeParameter {
23      get { return (ScopeParameter)Parameters[CurrentScopeParameterName]; }
24    }
25    public LookupParameter<IntValue> GenerationsParameter {
26      get { return (LookupParameter<IntValue>)Parameters[GenerationsParameterName]; }
27    }
28    public ILookupParameter<ItemArray<IItem>> ParentsParameter {
29      get { return (ScopeTreeLookupParameter<IItem>)Parameters["Parents"]; }
30    }
31    public ILookupParameter<IItem> ChildParameter {
32      get { return (ILookupParameter<IItem>)Parameters["Child"]; }
33    }
34    #endregion
35    #region Properties
36    public IScope CurrentScope {
37      get { return CurrentScopeParameter.ActualValue; }
38    }
39    public ResultCollection Results {
40      get { return ResultsParameter.ActualValue; }
41    }
42
43    public IntValue Generations {
44      get { return GenerationsParameter.ActualValue; }
45    }
46    private GenealogyGraph<IGenealogyGraphNode> GenealogyGraph {
47      get {
48        IResult result;
49        if (!Results.ContainsKey(PopulationGraphParameterName)) {
50          result = new Result(PopulationGraphParameterName, new GenealogyGraph<IGenealogyGraphNode>());
51          Results.Add(result);
52        } else {
53          result = Results[PopulationGraphParameterName];
54        }
55        var graph = (GenealogyGraph<IGenealogyGraphNode>)result.Value;
56        return graph;
57      }
58    }
59    #endregion
60    public EvolutionTrackingAfterCreationOperator() {
61      Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The results collection."));
62      Parameters.Add(new ScopeParameter(CurrentScopeParameterName, "The current scope from which sub-scopes should be selected."));
63      Parameters.Add(new LookupParameter<IntValue>(GenerationsParameterName, "The number of elapsed generations."));
64      Parameters.Add(new ScopeTreeLookupParameter<IItem>("Parents", "The parent individuals which should be crossed."));
65      Parameters.Add(new LookupParameter<IItem>("Child", "The child individual resulting from the crossover."));
66    }
67    private EvolutionTrackingAfterCreationOperator(EvolutionTrackingAfterCreationOperator original, Cloner cloner)
68      : base(original, cloner) {
69    }
70    public override IDeepCloneable Clone(Cloner cloner) {
71      return new EvolutionTrackingAfterCreationOperator(this, cloner);
72    }
73
74    public override IOperation Apply() {
75      var individuals = CurrentScope.SubScopes.Select(s => s.Variables.First().Value).ToList();
76      foreach (var ind in individuals) {
77        var graphNode = new GenealogyGraphNode {
78          Rank = 0
79        };
80        GenealogyGraph.AddVertex(graphNode);
81      }
82      return base.Apply();
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.