Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/AlgorithmSubScopesCreator.cs @ 5927

Last change on this file since 5927 was 5927, checked in by cneumuel, 13 years ago

#1215

  • worked on configurability of SymbolicExpressionGrammar
File size: 3.8 KB
Line 
1using System;
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.Problems.MetaOptimization {
11  [Item("ChildrenCreator", "An operator which is used to prepare crossover. The sub-scopes of the current scope the operator is applied on represent the parents. The operator creates new and empty scopes for each child, adds the scopes that represent the child's parents as sub-scopes to the child and adds the child as sub-scope to the current scope.")]
12  [StorableClass]
13  public class AlgorithmSubScopesCreator : SingleSuccessorOperator {
14    #region Parameter properties
15    public ILookupParameter<TypeValue> AlgorithmTypeParameter {
16      get { return (ILookupParameter<TypeValue>)Parameters[MetaOptimizationProblem.AlgorithmTypeParameterName]; }
17    }
18    public ILookupParameter<IItemList<IProblem>> ProblemsParameter {
19      get { return (ILookupParameter<IItemList<IProblem>>)Parameters[MetaOptimizationProblem.ProblemsParameterName]; }
20    }
21    public ILookupParameter<ParameterConfigurationTree> ParameterConfigurationParameter {
22      get { return (ILookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; }
23    }
24    public LookupParameter<IntValue> RepetitionsParameter {
25      get { return (LookupParameter<IntValue>)Parameters[MetaOptimizationProblem.RepetitionsParameterName]; }
26    }
27    private ScopeParameter CurrentScopeParameter {
28      get { return (ScopeParameter)Parameters["CurrentScope"]; }
29    }
30    public IScope CurrentScope {
31      get { return CurrentScopeParameter.ActualValue; }
32    }
33    #endregion
34
35    [StorableConstructor]
36    protected AlgorithmSubScopesCreator(bool deserializing) : base(deserializing) { }
37    public AlgorithmSubScopesCreator()
38      : base() {
39      Parameters.Add(new LookupParameter<TypeValue>(MetaOptimizationProblem.AlgorithmTypeParameterName, ""));
40      Parameters.Add(new LookupParameter<IItemList<IProblem>>(MetaOptimizationProblem.ProblemsParameterName, ""));
41      Parameters.Add(new LookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", ""));
42      Parameters.Add(new LookupParameter<IntValue>(MetaOptimizationProblem.RepetitionsParameterName, "Number of evaluations on one problem."));
43      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope whose sub-scopes represent the parents."));
44    }
45    protected AlgorithmSubScopesCreator(AlgorithmSubScopesCreator original, Cloner cloner)
46      : base(original, cloner) {
47    }
48    public override IDeepCloneable Clone(Cloner cloner) {
49      return new AlgorithmSubScopesCreator(this, cloner);
50    }
51
52    public override IOperation Apply() {
53      ParameterConfigurationTree parameterConfiguration = ParameterConfigurationParameter.ActualValue;
54      IItemList<IProblem> problems = ProblemsParameter.ActualValue;
55      int repetitions = RepetitionsParameter.ActualValue.Value;
56      Type algorithmType = AlgorithmTypeParameter.ActualValue.Value;
57
58      for (int i = 0; i < repetitions; i++) {
59        for (int j = 0; j < problems.Count; j++) {
60          IScope child = new Scope(string.Format("Problem {0}, Repetition {1}", j, i));
61          var algorithm = MetaOptimizationUtil.CreateParameterizedAlgorithmInstance(parameterConfiguration, algorithmType, (IProblem)problems[j].Clone());
62          child.Variables.Add(new Variable("Algorithm", algorithm));
63          child.Variables.Add(new Variable("ProblemIndex", new IntValue(j)));
64          child.Variables.Add(new Variable("RepetitionIndex", new IntValue(i)));
65          CurrentScope.SubScopes.Add(child);
66        }
67      }
68      return base.Apply();
69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.