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