Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1215

  • support for maximization problems
  • made base level algorithms stoppable
  • optimization for multiple goals possible (AverageQuality, AverageDeviation, AverageEvaluatedSolutions)
  • lots of fixes
File size: 3.5 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("AlgorithmSubScopesCreator", "An operator which ...")]
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.