#region License Information
/* HeuristicLab
* Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Operators;
using HeuristicLab.Parameters;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm {
[Item("OffspringCollector", "An operator that can be used as a pre-processing operator for Offspring Selectors to collect solutions.")]
[StorableClass]
public class OffspringCollector : SingleSuccessorOperator {
public LookupParameter> GeneratedOffspringParameter {
get { return (LookupParameter>)Parameters["GeneratedOffspring"]; }
}
[StorableConstructor]
private OffspringCollector(bool deserializing) : base(deserializing) { }
private OffspringCollector(OffspringCollector original, Cloner cloner) : base(original, cloner) { }
public OffspringCollector()
: base() {
Parameters.Add(new LookupParameter>("GeneratedOffspring", "Temporary store of the offspring population."));
}
public override IOperation Apply() {
IScope scope = ExecutionContext.Scope;
if (scope.SubScopes.Count != 2) {
throw new InvalidOperationException(Name + ": Wrong number of scopes.");
}
IScope offspring = scope.SubScopes[1];
if (GeneratedOffspringParameter.ActualValue == null) {
throw new InvalidOperationException(Name + ": GeneratedOffspring list is not initialized. Have you forgotten to add the ProbabilitiesGenerator to the analyzers?");
}
GeneratedOffspringParameter.ActualValue.AddRange(offspring.SubScopes);
return base.Apply();
}
public override IDeepCloneable Clone(Cloner cloner) {
return new OffspringCollector(this, cloner);
}
}
}