1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Encodings.ParameterConfigurationEncoding;
|
---|
27 | using HeuristicLab.Operators;
|
---|
28 | using HeuristicLab.Optimization;
|
---|
29 | using HeuristicLab.Parameters;
|
---|
30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.Problems.MetaOptimization {
|
---|
33 | /// <summary>
|
---|
34 | /// TODO
|
---|
35 | /// </summary>
|
---|
36 | [Item("AlgorithmSubScopesCreator", "TODO")]
|
---|
37 | [StorableClass]
|
---|
38 | public class AlgorithmSubScopesCreator : SingleSuccessorOperator {
|
---|
39 | #region Parameter properties
|
---|
40 | public ILookupParameter<TypeValue> AlgorithmTypeParameter {
|
---|
41 | get { return (ILookupParameter<TypeValue>)Parameters[MetaOptimizationProblem.AlgorithmTypeParameterName]; }
|
---|
42 | }
|
---|
43 | public ILookupParameter<IItemList<IProblem>> ProblemsParameter {
|
---|
44 | get { return (ILookupParameter<IItemList<IProblem>>)Parameters[MetaOptimizationProblem.ProblemsParameterName]; }
|
---|
45 | }
|
---|
46 | public ILookupParameter<ParameterConfigurationTree> ParameterConfigurationParameter {
|
---|
47 | get { return (ILookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; }
|
---|
48 | }
|
---|
49 | public LookupParameter<IntValue> RepetitionsParameter {
|
---|
50 | get { return (LookupParameter<IntValue>)Parameters[MetaOptimizationProblem.RepetitionsParameterName]; }
|
---|
51 | }
|
---|
52 | private ScopeParameter CurrentScopeParameter {
|
---|
53 | get { return (ScopeParameter)Parameters["CurrentScope"]; }
|
---|
54 | }
|
---|
55 | public IScope CurrentScope {
|
---|
56 | get { return CurrentScopeParameter.ActualValue; }
|
---|
57 | }
|
---|
58 | #endregion
|
---|
59 |
|
---|
60 | #region Constructors and Cloning
|
---|
61 | public AlgorithmSubScopesCreator()
|
---|
62 | : base() {
|
---|
63 | Parameters.Add(new LookupParameter<TypeValue>(MetaOptimizationProblem.AlgorithmTypeParameterName, ""));
|
---|
64 | Parameters.Add(new LookupParameter<IItemList<IProblem>>(MetaOptimizationProblem.ProblemsParameterName, ""));
|
---|
65 | Parameters.Add(new LookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", ""));
|
---|
66 | Parameters.Add(new LookupParameter<IntValue>(MetaOptimizationProblem.RepetitionsParameterName, "Number of evaluations on one problem."));
|
---|
67 | Parameters.Add(new ScopeParameter("CurrentScope", "The current scope whose sub-scopes represent the parents."));
|
---|
68 | }
|
---|
69 |
|
---|
70 | [StorableConstructor]
|
---|
71 | protected AlgorithmSubScopesCreator(bool deserializing) : base(deserializing) { }
|
---|
72 | protected AlgorithmSubScopesCreator(AlgorithmSubScopesCreator original, Cloner cloner) : base(original, cloner) { }
|
---|
73 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
74 | return new AlgorithmSubScopesCreator(this, cloner);
|
---|
75 | }
|
---|
76 | #endregion
|
---|
77 |
|
---|
78 | public override IOperation Apply() {
|
---|
79 | ParameterConfigurationTree parameterConfiguration = ParameterConfigurationParameter.ActualValue;
|
---|
80 | IItemList<IProblem> problems = ProblemsParameter.ActualValue;
|
---|
81 | int repetitions = RepetitionsParameter.ActualValue.Value;
|
---|
82 | Type algorithmType = AlgorithmTypeParameter.ActualValue.Value;
|
---|
83 |
|
---|
84 | for (int i = 0; i < repetitions; i++) {
|
---|
85 | for (int j = 0; j < problems.Count; j++) {
|
---|
86 | IScope child = new Scope(string.Format("Problem {0}, Repetition {1}", j, i));
|
---|
87 | var algorithm = MetaOptimizationUtil.CreateParameterizedAlgorithmInstance(parameterConfiguration, algorithmType, (IProblem)problems[j].Clone());
|
---|
88 | child.Variables.Add(new Variable("Algorithm", algorithm));
|
---|
89 | child.Variables.Add(new Variable("ProblemIndex", new IntValue(j)));
|
---|
90 | child.Variables.Add(new Variable("RepetitionIndex", new IntValue(i)));
|
---|
91 | CurrentScope.SubScopes.Add(child);
|
---|
92 | }
|
---|
93 | }
|
---|
94 | return base.Apply();
|
---|
95 | }
|
---|
96 | }
|
---|
97 | } |
---|