[13095] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17181] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[13095] | 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 HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.Operators;
|
---|
| 26 | using HeuristicLab.Parameters;
|
---|
[17097] | 27 | using HEAL.Attic;
|
---|
[13095] | 28 |
|
---|
| 29 | namespace HeuristicLab.Algorithms.ALPS {
|
---|
[13111] | 30 | [Item("ReseedingController", "An operator that controls if reseeding is needed.")]
|
---|
[17097] | 31 | [StorableType("67294ABE-C118-41F0-B736-0576F30F664F")]
|
---|
[13111] | 32 | public sealed class ReseedingController : SingleSuccessorOperator {
|
---|
[13127] | 33 | public ILookupParameter<IntValue> GenerationsParameter {
|
---|
[13095] | 34 | get { return (ILookupParameter<IntValue>)Parameters["Generations"]; }
|
---|
| 35 | }
|
---|
[13127] | 36 | public ILookupParameter<IntValue> AgeGapParameter {
|
---|
[13095] | 37 | get { return (ILookupParameter<IntValue>)Parameters["AgeGap"]; }
|
---|
| 38 | }
|
---|
[13111] | 39 | public OperatorParameter FirstLayerOperatorParameter {
|
---|
| 40 | get { return (OperatorParameter)Parameters["FirstLayerOperator"]; }
|
---|
| 41 | }
|
---|
[13095] | 42 |
|
---|
[13111] | 43 | public IOperator FirstLayerOperator {
|
---|
| 44 | get { return FirstLayerOperatorParameter.Value; }
|
---|
| 45 | set { FirstLayerOperatorParameter.Value = value; }
|
---|
[13095] | 46 | }
|
---|
| 47 |
|
---|
| 48 | [StorableConstructor]
|
---|
[17097] | 49 | private ReseedingController(StorableConstructorFlag _) : base(_) { }
|
---|
[13095] | 50 |
|
---|
[13111] | 51 | private ReseedingController(ReseedingController original, Cloner cloner)
|
---|
[13095] | 52 | : base(original, cloner) {
|
---|
| 53 | }
|
---|
| 54 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[13111] | 55 | return new ReseedingController(this, cloner);
|
---|
[13095] | 56 | }
|
---|
| 57 |
|
---|
[13111] | 58 | public ReseedingController()
|
---|
[13095] | 59 | : base() {
|
---|
[13127] | 60 | Parameters.Add(new LookupParameter<IntValue>("Generations", "The current number of generations."));
|
---|
| 61 | Parameters.Add(new ValueLookupParameter<IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers."));
|
---|
[13206] | 62 | Parameters.Add(new OperatorParameter("FirstLayerOperator", "The operator that is performed on the first layer if reseeding is required."));
|
---|
[13095] | 63 | }
|
---|
| 64 |
|
---|
| 65 | public override IOperation Apply() {
|
---|
| 66 | int generations = GenerationsParameter.ActualValue.Value;
|
---|
| 67 | int ageGap = AgeGapParameter.ActualValue.Value;
|
---|
| 68 |
|
---|
| 69 | var next = new OperationCollection(base.Apply());
|
---|
[13110] | 70 | if (generations % ageGap == 0) {
|
---|
[13095] | 71 | var layerZeroScope = ExecutionContext.Scope.SubScopes[0];
|
---|
[13111] | 72 | if (FirstLayerOperator != null)
|
---|
| 73 | next.Insert(0, ExecutionContext.CreateChildOperation(FirstLayerOperator, layerZeroScope));
|
---|
[13095] | 74 | }
|
---|
| 75 | return next;
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 | } |
---|