Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ScatterSearch/HeuristicLab.Algorithms.ScatterSearch/3.3/OffspringProcessor.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: 3.0 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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Operators;
25using HeuristicLab.Parameters;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Algorithms.ScatterSearch {
29  /// <summary>
30  /// An operator that creates a subscope with subscopes for every variable in the current scope.
31  /// </summary>
32  [Item("OffspringProcessor", "An operator that creates a subscope with subscopes for every variable in the current scope.")]
33  [StorableClass]
34  public sealed class OffspringProcessor : SingleSuccessorOperator {
35    #region Parameter properties
36    public ScopeParameter CurrentScopeParameter {
37      get { return (ScopeParameter)Parameters["CurrentScope"]; }
38    }
39    public IValueLookupParameter<IItem> TargetParameter {
40      get { return (IValueLookupParameter<IItem>)Parameters["Target"]; }
41    }
42    #endregion
43
44    #region Properties
45    private IScope CurrentScope {
46      get { return CurrentScopeParameter.ActualValue; }
47    }
48    private IItem Target {
49      get { return TargetParameter.ActualValue; }
50    }
51    #endregion
52
53    [StorableConstructor]
54    private OffspringProcessor(bool deserializing) : base(deserializing) { }
55    private OffspringProcessor(OffspringProcessor original, Cloner cloner) : base(original, cloner) { }
56    public OffspringProcessor()
57      : base() {
58      #region Create parameters
59      Parameters.Add(new ScopeParameter("CurrentScope"));
60      Parameters.Add(new ValueLookupParameter<IItem>("Target"));
61      #endregion
62    }
63
64    public override IDeepCloneable Clone(Cloner cloner) {
65      return new OffspringProcessor(this, cloner);
66    }
67
68    public override IOperation Apply() {
69      VariableCollection offspringSolutions = CurrentScope.Variables;
70      IScope offspringScope = new Scope("Offspring");
71      foreach (var solution in offspringSolutions) {
72        IScope scope = new Scope();
73        scope.Variables.Add(new Variable(TargetParameter.ActualName, solution.Value));
74        offspringScope.SubScopes.Add(scope);
75      }
76      CurrentScope.SubScopes.Add(offspringScope);
77      CurrentScope.Variables.Clear();
78      return base.Apply();
79    }
80  }
81}
Note: See TracBrowser for help on using the repository browser.