Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/ReferenceSetUpdateMethod.cs @ 8319

Last change on this file since 8319 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: 3.8 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.Optimization;
29using HeuristicLab.Optimization.Operators;
30using HeuristicLab.Parameters;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
32
33namespace HeuristicLab.Algorithms.ScatterSearch {
34  /// <summary>
35  /// An operator that updates the reference set.
36  /// </summary>
37  [Item("ReferenceSetUpdateMethod", "An operator that updates the reference set.")]
38  [StorableClass]
39  public sealed class ReferenceSetUpdateMethod : SingleSuccessorOperator, ISimilarityBasedOperator {
40    #region ISimilarityBasedOperator Members
41    public ISolutionSimilarityCalculator SimilarityCalculator { get; set; }
42    #endregion
43
44    #region Parameter properties
45    public ScopeParameter CurrentScopeParameter {
46      get { return (ScopeParameter)Parameters["CurrentScope"]; }
47    }
48    public IValueLookupParameter<IntValue> ReferenceSetSizeParameter {
49      get { return (IValueLookupParameter<IntValue>)Parameters["ReferenceSetSize"]; }
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    #endregion
61
62    [StorableConstructor]
63    private ReferenceSetUpdateMethod(bool deserializing) : base(deserializing) { }
64    private ReferenceSetUpdateMethod(ReferenceSetUpdateMethod original, Cloner cloner) : base(original, cloner) { }
65    public ReferenceSetUpdateMethod()
66      : base() {
67      #region Create parameters
68      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the population and the reference set."));
69      Parameters.Add(new ValueLookupParameter<IntValue>("ReferenceSetSize", "The size of the reference set."));
70      #endregion
71    }
72
73    public override IDeepCloneable Clone(Cloner cloner) {
74      return new ReferenceSetUpdateMethod(this, cloner);
75    }
76
77    public override IOperation Apply() {
78      var populationSimilarity = new Dictionary<IScope, double>();
79      var populationScope = CurrentScope.SubScopes[0];
80      var refSetScope = CurrentScope.SubScopes[1];
81      var similarityMatrix = SimilarityCalculator.CalculateSolutionCrowdSimilarity(populationScope, refSetScope);
82      for (int i = 0; i < populationScope.SubScopes.Count; i++) {
83        populationSimilarity[populationScope.SubScopes[i]] = similarityMatrix[i].Sum();
84      }
85      int numberOfHighQualitySolutions = CurrentScope.SubScopes[1].SubScopes.Count;
86      foreach (var entry in populationSimilarity.OrderBy(x => x.Value).Take(ReferenceSetSize.Value - numberOfHighQualitySolutions)) {
87        CurrentScope.SubScopes[1].SubScopes.Add(entry.Key);
88        CurrentScope.SubScopes[0].SubScopes.Remove(entry.Key);
89      }
90      return base.Apply();
91    }
92  }
93}
Note: See TracBrowser for help on using the repository browser.