[13368] | 1 | #region License Information
|
---|
[11609] | 2 | /* HeuristicLab
|
---|
[12018] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[11609] | 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 System.Linq;
|
---|
| 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Operators;
|
---|
| 27 | using HeuristicLab.Parameters;
|
---|
| 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Algorithms.ALPS {
|
---|
[13206] | 31 | [Item("LastLayerCloner", "An operator that creates a new layer by cloning the current last one.")]
|
---|
[13368] | 32 | [StorableClass("A7D0BA7F-1C3E-4320-8E99-AAEDFBD29715")]
|
---|
[13206] | 33 | public sealed class LastLayerCloner : SingleSuccessorOperator {
|
---|
| 34 | public OperatorParameter NewLayerOperatorParameter {
|
---|
| 35 | get { return (OperatorParameter)Parameters["NewLayerOperator"]; }
|
---|
[11609] | 36 | }
|
---|
| 37 |
|
---|
[13206] | 38 | public IOperator NewLayerOperator {
|
---|
| 39 | get { return NewLayerOperatorParameter.Value; }
|
---|
| 40 | set { NewLayerOperatorParameter.Value = value; }
|
---|
[13095] | 41 | }
|
---|
| 42 |
|
---|
[11609] | 43 | [StorableConstructor]
|
---|
[13206] | 44 | private LastLayerCloner(bool deserializing) : base(deserializing) { }
|
---|
[11609] | 45 |
|
---|
[13206] | 46 | private LastLayerCloner(LastLayerCloner original, Cloner cloner)
|
---|
[11609] | 47 | : base(original, cloner) {
|
---|
| 48 | }
|
---|
[13124] | 49 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[13206] | 50 | return new LastLayerCloner(this, cloner);
|
---|
[11609] | 51 | }
|
---|
| 52 |
|
---|
[13206] | 53 | public LastLayerCloner()
|
---|
[13124] | 54 | : base() {
|
---|
[13206] | 55 | Parameters.Add(new OperatorParameter("NewLayerOperator", "An operator that is performed on the new layer."));
|
---|
[11609] | 56 | }
|
---|
| 57 |
|
---|
| 58 | public override IOperation Apply() {
|
---|
[13124] | 59 | var scopes = ExecutionContext.Scope.SubScopes;
|
---|
| 60 | if (scopes.Count < 1)
|
---|
[13095] | 61 | throw new ArgumentException("At least one layer must exist.");
|
---|
[11609] | 62 |
|
---|
[13124] | 63 | var newScope = (IScope)scopes.Last().Clone();
|
---|
[11609] | 64 |
|
---|
[13124] | 65 | int scopeNumber;
|
---|
| 66 | if (int.TryParse(newScope.Name, out scopeNumber))
|
---|
| 67 | newScope.Name = (scopeNumber + 1).ToString();
|
---|
[11609] | 68 |
|
---|
[13124] | 69 | scopes.Add(newScope);
|
---|
[11609] | 70 |
|
---|
[13095] | 71 | var next = new OperationCollection(base.Apply());
|
---|
[13206] | 72 | if (NewLayerOperator != null)
|
---|
| 73 | next.Insert(0, ExecutionContext.CreateOperation(NewLayerOperator, newScope));
|
---|
[13095] | 74 | return next;
|
---|
[11609] | 75 | }
|
---|
| 76 | }
|
---|
| 77 | } |
---|