Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPoolUpdateMethod.cs @ 7724

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

#1331:

  • added analyzer
  • added parameters and adjusted parameter types
  • corrected ReferenceSetUpdateMethod
  • changed access levels
File size: 4.3 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 solution pool.
33  /// </summary>
34  [Item("SolutionPoolUpdateMethod", "An operator that updates the solution pool.")]
35  [StorableClass]
36  public sealed class SolutionPoolUpdateMethod : SingleSuccessorOperator {
37    #region Parameter properties
38    private ScopeParameter CurrentScopeParameter {
39      get { return (ScopeParameter)Parameters["CurrentScope"]; }
40    }
41    private ValueLookupParameter<BoolValue> NewSolutionsParameter {
42      get { return (ValueLookupParameter<BoolValue>)Parameters["NewSolutions"]; }
43    }
44    private ValueLookupParameter<IntValue> ReferenceSetSizeParameter {
45      get { return (ValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
46    }
47    #endregion
48
49    #region Properties
50    private IScope CurrentScope {
51      get { return CurrentScopeParameter.ActualValue; }
52    }
53    private BoolValue NewSolutions {
54      get { return NewSolutionsParameter.ActualValue; }
55    }
56    private IntValue ReferenceSetSize {
57      get { return ReferenceSetSizeParameter.ActualValue; }
58      set { ReferenceSetSizeParameter.ActualValue = value; }
59    }
60    #endregion
61
62    [StorableConstructor]
63    private SolutionPoolUpdateMethod(bool deserializing) : base(deserializing) { }
64    private SolutionPoolUpdateMethod(SolutionPoolUpdateMethod original, Cloner cloner) : base(original, cloner) { }
65    public SolutionPoolUpdateMethod() : base() { Initialize(); }
66
67    public override IDeepCloneable Clone(Cloner cloner) {
68      return new SolutionPoolUpdateMethod(this, cloner);
69    }
70
71    private void Initialize() {
72      #region Create parameters
73      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope to which the new solutions are added as sub-scopes."));
74      Parameters.Add(new ValueLookupParameter<BoolValue>("NewSolutions", "Indicates if new solutions have been found."));
75      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set."));
76      #endregion
77
78      #region Create operators
79      #endregion
80
81      #region Create operator graph
82      #endregion
83    }
84
85    public override IOperation Apply() {
86      IScope parents = new Scope("Parents");
87      IScope offspring = new Scope("Offspring");
88      foreach (var scope in CurrentScope.SubScopes) {
89        parents.SubScopes.AddRange(scope.SubScopes.Take(scope.SubScopes.Count - 1));
90        offspring.SubScopes.AddRange(scope.SubScopes.Last().SubScopes);
91      }
92      CurrentScope.SubScopes.Clear();
93      CurrentScope.SubScopes.AddRange(parents.SubScopes.OrderByDescending(o => o.Variables["Quality"].Value));
94      if ((offspring.SubScopes.OrderByDescending(o => o.Variables["Quality"].Value).First().Variables["Quality"].Value as DoubleValue).Value
95          > (parents.SubScopes.OrderByDescending(o => o.Variables["Quality"].Value).First().Variables["Quality"].Value as DoubleValue).Value) {
96        CurrentScope.SubScopes.Replace(CurrentScope.SubScopes.Union(offspring.SubScopes).OrderByDescending(o => o.Variables["Quality"].Value).Take(ReferenceSetSize.Value));
97        NewSolutions.Value = true;
98      }
99      return base.Apply();
100    }
101  }
102}
Note: See TracBrowser for help on using the repository browser.