1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 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.Optimization;
|
---|
28 | using HeuristicLab.Parameters;
|
---|
29 | using HEAL.Attic;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Algorithms.ScatterSearch {
|
---|
32 | /// <summary>
|
---|
33 | /// An operator that updates the reference set and rebuilds the population.
|
---|
34 | /// </summary>
|
---|
35 | [Item("PopulationRebuildMethod", "An operator that updates the reference set and rebuilds the population.")]
|
---|
36 | [StorableType("B993B7E3-E510-4211-AD13-90517C810E34")]
|
---|
37 | public sealed class PopulationRebuildMethod : SingleSuccessorOperator, ISingleObjectiveOperator {
|
---|
38 | #region Parameter properties
|
---|
39 | public ScopeParameter CurrentScopeParameter {
|
---|
40 | get { return (ScopeParameter)Parameters["CurrentScope"]; }
|
---|
41 | }
|
---|
42 | public IValueLookupParameter<BoolValue> MaximizationParameter {
|
---|
43 | get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
|
---|
44 | }
|
---|
45 | public IValueLookupParameter<IntValue> NumberOfHighQualitySolutionsParameter {
|
---|
46 | get { return (IValueLookupParameter<IntValue>)Parameters["NumberOfHighQualitySolutions"]; }
|
---|
47 | }
|
---|
48 | public IValueLookupParameter<IItem> QualityParameter {
|
---|
49 | get { return (IValueLookupParameter<IItem>)Parameters["Quality"]; }
|
---|
50 | }
|
---|
51 | public IValueLookupParameter<IntValue> ReferenceSetSizeParameter {
|
---|
52 | get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
|
---|
53 | }
|
---|
54 | #endregion
|
---|
55 |
|
---|
56 | #region Properties
|
---|
57 | private IScope CurrentScope {
|
---|
58 | get { return CurrentScopeParameter.ActualValue; }
|
---|
59 | }
|
---|
60 | private BoolValue Maximization {
|
---|
61 | get { return MaximizationParameter.ActualValue; }
|
---|
62 | set { MaximizationParameter.ActualValue = value; }
|
---|
63 | }
|
---|
64 | private IntValue NumberOfHighQualitySolutions {
|
---|
65 | get { return NumberOfHighQualitySolutionsParameter.ActualValue; }
|
---|
66 | set { NumberOfHighQualitySolutionsParameter.ActualValue = value; }
|
---|
67 | }
|
---|
68 | private IItem Quality {
|
---|
69 | get { return QualityParameter.ActualValue; }
|
---|
70 | }
|
---|
71 | private IntValue ReferenceSetSize {
|
---|
72 | get { return ReferenceSetSizeParameter.ActualValue; }
|
---|
73 | set { ReferenceSetSizeParameter.ActualValue = value; }
|
---|
74 | }
|
---|
75 | #endregion
|
---|
76 |
|
---|
77 | [StorableConstructor]
|
---|
78 | private PopulationRebuildMethod(StorableConstructorFlag _) : base(_) { }
|
---|
79 | private PopulationRebuildMethod(PopulationRebuildMethod original, Cloner cloner) : base(original, cloner) { }
|
---|
80 | public PopulationRebuildMethod()
|
---|
81 | : base() {
|
---|
82 | #region Create parameters
|
---|
83 | Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the population and the reference set."));
|
---|
84 | Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
|
---|
85 | Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfHighQualitySolutions", "The number of high quality solutions in the reference set."));
|
---|
86 | Parameters.Add(new ValueLookupParameter<IItem>("Quality", "This parameter is used for name translation only."));
|
---|
87 | Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set."));
|
---|
88 | #endregion
|
---|
89 | }
|
---|
90 |
|
---|
91 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
92 | return new PopulationRebuildMethod(this, cloner);
|
---|
93 | }
|
---|
94 |
|
---|
95 | public override IOperation Apply() {
|
---|
96 | IScope populationScope = CurrentScope.SubScopes[0];
|
---|
97 | IScope referenceSetScope = CurrentScope.SubScopes[1];
|
---|
98 | var orderedReferenceSet = Maximization.Value ? referenceSetScope.SubScopes.OrderByDescending(r => r.Variables[QualityParameter.ActualName].Value) :
|
---|
99 | referenceSetScope.SubScopes.OrderBy(r => r.Variables[QualityParameter.ActualName].Value);
|
---|
100 | referenceSetScope.SubScopes.Replace(orderedReferenceSet.Take(NumberOfHighQualitySolutions.Value).ToList());
|
---|
101 | populationScope.SubScopes.Clear();
|
---|
102 | return base.Apply();
|
---|
103 | }
|
---|
104 | }
|
---|
105 | }
|
---|