[6018] | 1 | using HeuristicLab.Common;
|
---|
[5653] | 2 | using HeuristicLab.Core;
|
---|
| 3 | using HeuristicLab.Data;
|
---|
[6018] | 4 | using HeuristicLab.Operators;
|
---|
[5653] | 5 | using HeuristicLab.Optimization;
|
---|
[6018] | 6 | using HeuristicLab.Parameters;
|
---|
| 7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[5653] | 8 |
|
---|
| 9 | namespace 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 |
|
---|
[6421] | 74 | uniformSubScopesProcessor.Parallel.Value = true;
|
---|
| 75 |
|
---|
[5653] | 76 | this.OperatorGraph.InitialOperator = algorithmSubScopesCreator;
|
---|
| 77 | algorithmSubScopesCreator.Successor = uniformSubScopesProcessor;
|
---|
| 78 | uniformSubScopesProcessor.Operator = algorithmEvaluator;
|
---|
| 79 | uniformSubScopesProcessor.Successor = algorithmRunsAnalyzer;
|
---|
| 80 | algorithmRunsAnalyzer.Successor = null;
|
---|
[6421] | 81 | }
|
---|
[5653] | 82 |
|
---|
[6421] | 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;
|
---|
[5653] | 87 | }
|
---|
| 88 | }
|
---|
| 89 | }
|
---|