[7722] | 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.Linq;
|
---|
| 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Data;
|
---|
| 26 | using HeuristicLab.Operators;
|
---|
| 27 | using HeuristicLab.Parameters;
|
---|
| 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Algorithms.ScatterSearch {
|
---|
| 31 | /// <summary>
|
---|
| 32 | /// An operator that updates a population.
|
---|
| 33 | /// </summary>
|
---|
| 34 | [Item("PopulationRebuildMethod", "An operator that rebuilds the population.")]
|
---|
| 35 | [StorableClass]
|
---|
| 36 | public sealed class PopulationRebuildMethod : SingleSuccessorOperator {
|
---|
| 37 | #region Parameter properties
|
---|
| 38 | private ScopeParameter CurrentScopeParameter {
|
---|
| 39 | get { return (ScopeParameter)Parameters["CurrentScope"]; }
|
---|
| 40 | }
|
---|
| 41 | public ValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter {
|
---|
| 42 | get { return (ValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
|
---|
| 43 | }
|
---|
| 44 | public ValueLookupParameter<IntValue> ReferenceSetSizeParameter {
|
---|
| 45 | get { return (ValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
|
---|
| 46 | }
|
---|
| 47 | #endregion
|
---|
| 48 |
|
---|
| 49 | #region Properties
|
---|
| 50 | public IScope CurrentScope {
|
---|
| 51 | get { return CurrentScopeParameter.ActualValue; }
|
---|
| 52 | }
|
---|
| 53 | public IntValue NumberOfHighQualitySolutions {
|
---|
| 54 | get { return NumberOfHighQualitySolutionsParameter.ActualValue; }
|
---|
| 55 | set { NumberOfHighQualitySolutionsParameter.ActualValue = value; }
|
---|
| 56 | }
|
---|
| 57 | public IntValue ReferenceSetSize {
|
---|
| 58 | get { return ReferenceSetSizeParameter.ActualValue; }
|
---|
| 59 | set { ReferenceSetSizeParameter.ActualValue = value; }
|
---|
| 60 | }
|
---|
| 61 | #endregion
|
---|
| 62 |
|
---|
| 63 | [StorableConstructor]
|
---|
| 64 | private PopulationRebuildMethod(bool deserializing) : base(deserializing) { }
|
---|
| 65 | private PopulationRebuildMethod(PopulationRebuildMethod original, Cloner cloner) : base(original, cloner) { }
|
---|
| 66 | public PopulationRebuildMethod() : base() { Initialize(); }
|
---|
| 67 |
|
---|
| 68 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 69 | return new PopulationRebuildMethod(this, cloner);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | private void Initialize() {
|
---|
| 73 | #region Create parameters
|
---|
| 74 | Parameters.Add(new ScopeParameter("CurrentScope", "The current scope to which the new solutions are added as sub-scopes."));
|
---|
| 75 | Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions that should be added to the reference set."));
|
---|
| 76 | Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set."));
|
---|
| 77 | #endregion
|
---|
| 78 |
|
---|
| 79 | #region Create operators
|
---|
| 80 | #endregion
|
---|
| 81 |
|
---|
| 82 | #region Create operator graph
|
---|
| 83 | #endregion
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | public override IOperation Apply() {
|
---|
| 87 | IScope population = CurrentScope.SubScopes[0];
|
---|
| 88 | IScope refSet = CurrentScope.SubScopes[1];
|
---|
| 89 | refSet.SubScopes.Replace(refSet.SubScopes.OrderByDescending(r => r.Variables["Quality"].Value)
|
---|
| 90 | .Take(NumberOfHighQualitySolutions.Value).ToList());
|
---|
| 91 | population.SubScopes.Clear();
|
---|
| 92 | return base.Apply();
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 | }
|
---|