Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/ReferenceSetUpdateMethod.cs @ 7786

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

#1331:

  • fixed bug in path relinking selection
  • fixed bug in ScatterSearch.Prepare()
  • added custom interface (IImprovementOperator) for Scatter Search specific improvement operators
  • switched from diversity calculation to similarity calculation
  • separated IPathRelinker from ICrossover
  • changed TestFunctionsImprovementOperator to use reflection for evaluating functions
  • changed SolutionPoolUpdateMethod to use similarity calculation for solution comparison
  • improved TravelingSalesmanImprovementOperator
  • improved operator graph
  • removed specific operators used to evaluate TestFunctions problems
  • removed custom crossover operator (NChildCrossover)
  • added parameters and adjusted types
  • adjusted event handling
  • changed access levels
  • minor code improvements
File size: 4.1 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.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Operators;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Algorithms.ScatterSearch {
32  /// <summary>
33  /// An operator that updates the reference set.
34  /// </summary>
35  [Item("ReferenceSetUpdateMethod", "An operator that updates the reference set.")]
36  [StorableClass]
37  public sealed class ReferenceSetUpdateMethod : SingleSuccessorOperator {
38    #region Parameter properties
39    public ScopeParameter CurrentScopeParameter {
40      get { return (ScopeParameter)Parameters["CurrentScope"]; }
41    }
42    public IValueLookupParameter<IntValue> ReferenceSetSizeParameter {
43      get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
44    }
45    public IValueLookupParameter<SimilarityCalculator> SimilarityCalculatorParameter {
46      get { return (IValueLookupParameter<SimilarityCalculator>)Parameters["SimilarityCalculator"]; }
47    }
48    public IValueLookupParameter<IItem> TargetParameter {
49      get { return (IValueLookupParameter<IItem>)Parameters["Target"]; }
50    }
51    #endregion
52
53    #region Properties
54    private IScope CurrentScope {
55      get { return CurrentScopeParameter.ActualValue; }
56    }
57    private IntValue ReferenceSetSize {
58      get { return ReferenceSetSizeParameter.ActualValue; }
59    }
60    private SimilarityCalculator SimilarityCalculator {
61      get { return SimilarityCalculatorParameter.ActualValue; }
62    }
63    private IItem Target {
64      get { return TargetParameter.ActualValue; }
65    }
66    #endregion
67
68    [StorableConstructor]
69    private ReferenceSetUpdateMethod(bool deserializing) : base(deserializing) { }
70    private ReferenceSetUpdateMethod(ReferenceSetUpdateMethod original, Cloner cloner) : base(original, cloner) { }
71    public ReferenceSetUpdateMethod()
72      : base() {
73      #region Create parameters
74      Parameters.Add(new ScopeParameter("CurrentScope"));
75      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize"));
76      Parameters.Add(new ValueLookupParameter<SimilarityCalculator>("SimilarityCalculator"));
77      Parameters.Add(new ValueLookupParameter<IItem>("Target"));
78      #endregion
79    }
80
81    public override IDeepCloneable Clone(Cloner cloner) {
82      return new ReferenceSetUpdateMethod(this, cloner);
83    }
84
85    public override IOperation Apply() {
86      IDictionary<IScope, double> population = new Dictionary<IScope, double>();
87      foreach (var pScope in CurrentScope.SubScopes[0].SubScopes) {
88        double similarity = 0;
89        foreach (var rScope in CurrentScope.SubScopes[1].SubScopes) {
90          similarity += SimilarityCalculator.ExecuteCalculation(pScope, rScope);
91        }
92        population[pScope] = similarity;
93      }
94      int numberOfHighQualitySolutions = CurrentScope.SubScopes[1].SubScopes.Count;
95      foreach (var entry in population.OrderBy(x => x.Value).Take(ReferenceSetSize.Value - numberOfHighQualitySolutions)) {
96        CurrentScope.SubScopes[1].SubScopes.Add(entry.Key);
97        CurrentScope.SubScopes[0].SubScopes.Remove(entry.Key);
98      }
99      return base.Apply();
100    }
101  }
102}
Note: See TracBrowser for help on using the repository browser.