Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/PMOEvaluator.cs @ 16574

Last change on this file since 16574 was 16574, checked in by gkronber, 6 years ago

#2520: changed HeuristicLab.MetaOptimization addon to compile with new HL.Persistence

File size: 4.5 KB
Line 
1using HeuristicLab.Common;
2using HeuristicLab.Core;
3using HeuristicLab.Data;
4using HeuristicLab.Operators;
5using HeuristicLab.Optimization;
6using HeuristicLab.Parameters;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8using HEAL.Attic;
9
10namespace HeuristicLab.Problems.MetaOptimization {
11  [Item("PMOEvaluator", "An operator which represents the main loop of a genetic algorithm.")]
12  [StorableType("20F53B3F-5618-452C-B180-247A530EB7FB")]
13  public class PMOEvaluator : AlgorithmOperator, IParameterConfigurationEvaluator {
14
15    #region Parameter properties
16    public ILookupParameter<IRandom> RandomParameter {
17      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
18    }
19    public ILookupParameter<DoubleValue> QualityParameter {
20      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
21    }
22    public ILookupParameter<TypeValue> AlgorithmTypeParameter {
23      get { return (ILookupParameter<TypeValue>)Parameters[MetaOptimizationProblem.AlgorithmTypeParameterName]; }
24    }
25    public ILookupParameter<IItemList<IProblem>> ProblemsParameter {
26      get { return (ILookupParameter<IItemList<IProblem>>)Parameters[MetaOptimizationProblem.ProblemsParameterName]; }
27    }
28    public ILookupParameter<ParameterConfigurationTree> ParameterConfigurationParameter {
29      get { return (ILookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; }
30    }
31    public LookupParameter<IntValue> RepetitionsParameter {
32      get { return (LookupParameter<IntValue>)Parameters[MetaOptimizationProblem.RepetitionsParameterName]; }
33    }
34    public LookupParameter<IntValue> GenerationsParameter {
35      get { return (LookupParameter<IntValue>)Parameters["Generations"]; }
36    }
37    public LookupParameter<ResultCollection> ResultsParameter {
38      get { return (LookupParameter<ResultCollection>)Parameters["Results"]; }
39    }
40    private ScopeParameter CurrentScopeParameter {
41      get { return (ScopeParameter)Parameters["CurrentScope"]; }
42    }
43    public IScope CurrentScope {
44      get { return CurrentScopeParameter.ActualValue; }
45    }
46    #endregion
47
48    [StorableConstructor]
49    protected PMOEvaluator(StorableConstructorFlag _) : base(_) { }
50    public PMOEvaluator() {
51      Initialize();
52    }
53    protected PMOEvaluator(PMOEvaluator original, Cloner cloner) : base(original, cloner) { }
54    public override IDeepCloneable Clone(Cloner cloner) {
55      return new PMOEvaluator(this, cloner);
56    }
57
58    private void Initialize() {
59      #region Create parameters
60      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used to initialize the new random permutation."));
61      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The evaluated quality of the ParameterVector."));
62      Parameters.Add(new LookupParameter<TypeValue>(MetaOptimizationProblem.AlgorithmTypeParameterName, ""));
63      Parameters.Add(new LookupParameter<IItemList<IProblem>>(MetaOptimizationProblem.ProblemsParameterName, ""));
64      Parameters.Add(new LookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", ""));
65      Parameters.Add(new LookupParameter<IntValue>(MetaOptimizationProblem.RepetitionsParameterName, "Number of evaluations on one problem."));
66      Parameters.Add(new LookupParameter<IntValue>("Generations", ""));
67      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the genetic algorithm should be applied."));
68      #endregion
69     
70      var algorithmSubScopesCreator = new AlgorithmSubScopesCreator();
71      var uniformSubScopesProcessor = new UniformSubScopesProcessor();
72      var algorithmEvaluator = new AlgorithmEvaluator();
73      var algorithmRunsAnalyzer = new AlgorithmRunsAnalyzer();
74
75      uniformSubScopesProcessor.Parallel.Value = true;
76     
77      this.OperatorGraph.InitialOperator = algorithmSubScopesCreator;
78      algorithmSubScopesCreator.Successor = uniformSubScopesProcessor;
79      uniformSubScopesProcessor.Operator = algorithmEvaluator;
80      uniformSubScopesProcessor.Successor = algorithmRunsAnalyzer;
81      algorithmRunsAnalyzer.Successor = null;
82    }
83
84    [StorableHook(HookType.AfterDeserialization)]
85    private void AfterDeserialization() {
86      ///// only for debug reasons - remove later (set this in stored algs)
87      ((UniformSubScopesProcessor)((AlgorithmSubScopesCreator)this.OperatorGraph.InitialOperator).Successor).Parallel.Value = true;
88    }
89  }
90}
Note: See TracBrowser for help on using the repository browser.