Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/PMOEvaluator.cs @ 13365

Last change on this file since 13365 was 6421, checked in by cneumuel, 14 years ago

#1215

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