Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.ScatterSearch/3.3/PopulationRebuildMethod.cs @ 9439

Last change on this file since 9439 was 8319, checked in by jkarder, 12 years ago

#1331:

  • applied some of the changes suggested by ascheibe in comment:32:ticket:1331
  • restructured path relinking and improvement operators and similarity calculators
  • fixed bug in TSPMultipleGuidesPathRelinker
File size: 4.7 KB
Line 
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
22using System.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Algorithms.ScatterSearch {
31  /// <summary>
32  /// An operator that updates the reference set and rebuilds the population.
33  /// </summary>
34  [Item("PopulationRebuildMethod", "An operator that updates the reference set and rebuilds the population.")]
35  [StorableClass]
36  public sealed class PopulationRebuildMethod : SingleSuccessorOperator {
37    #region Parameter properties
38    public ScopeParameter CurrentScopeParameter {
39      get { return (ScopeParameter)Parameters["CurrentScope"]; }
40    }
41    public IValueLookupParameter<BoolValue> MaximizationParameter {
42      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
43    }
44    public IValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter {
45      get { return (IValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
46    }
47    public IValueLookupParameter<IItem> QualityParameter {
48      get { return (IValueLookupParameter<IItem>)Parameters["Quality"]; }
49    }
50    public IValueLookupParameter<IntValue> ReferenceSetSizeParameter {
51      get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
52    }
53    #endregion
54
55    #region Properties
56    private IScope CurrentScope {
57      get { return CurrentScopeParameter.ActualValue; }
58    }
59    private BoolValue Maximization {
60      get { return MaximizationParameter.ActualValue; }
61      set { MaximizationParameter.ActualValue = value; }
62    }
63    private IntValue NumberOfHighQualitySolutions {
64      get { return NumberOfHighQualitySolutionsParameter.ActualValue; }
65      set { NumberOfHighQualitySolutionsParameter.ActualValue = value; }
66    }
67    private IItem Quality {
68      get { return QualityParameter.ActualValue; }
69    }
70    private IntValue ReferenceSetSize {
71      get { return ReferenceSetSizeParameter.ActualValue; }
72      set { ReferenceSetSizeParameter.ActualValue = value; }
73    }
74    #endregion
75
76    [StorableConstructor]
77    private PopulationRebuildMethod(bool deserializing) : base(deserializing) { }
78    private PopulationRebuildMethod(PopulationRebuildMethod original, Cloner cloner) : base(original, cloner) { }
79    public PopulationRebuildMethod()
80      : base() {
81      #region Create parameters
82      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the population and the reference set."));
83      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
84      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions in the reference set."));
85      Parameters.Add(new ValueLookupParameter<IItem>("Quality", "This parameter is used for name translation only."));
86      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set."));
87      #endregion
88    }
89
90    public override IDeepCloneable Clone(Cloner cloner) {
91      return new PopulationRebuildMethod(this, cloner);
92    }
93
94    public override IOperation Apply() {
95      IScope populationScope = CurrentScope.SubScopes[0];
96      IScope referenceSetScope = CurrentScope.SubScopes[1];
97      var orderedReferenceSet = Maximization.Value ? referenceSetScope.SubScopes.OrderByDescending(r => r.Variables[QualityParameter.ActualName].Value) :
98                                                     referenceSetScope.SubScopes.OrderBy(r => r.Variables[QualityParameter.ActualName].Value);
99      referenceSetScope.SubScopes.Replace(orderedReferenceSet.Take(NumberOfHighQualitySolutions.Value).ToList());
100      populationScope.SubScopes.Clear();
101      return base.Apply();
102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.