Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PTSP/HeuristicLab.Problems.PTSP/3.3/MoveGenerators/Stochastic25MultiMoveGenerator.cs @ 12797

Last change on this file since 12797 was 12272, checked in by apolidur, 10 years ago

#2221: Adding 2.5-opt-EEs operators to PTSP

File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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.Data;
25using HeuristicLab.Encodings.PermutationEncoding;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Problems.PTSP {
32  [Item("Stochastic25MultiMoveGenerator", "Randomly samples n from all possible inversion and shift moves (2.5-opt) from a given permutation.")]
33  [StorableClass]
34  class Stochastic25MultiMoveGenerator : TwoPointFiveMoveGenerator, IMultiMoveGenerator, IStochasticOperator {
35    public ILookupParameter<IRandom> RandomParameter {
36      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
37    }
38    public IValueLookupParameter<IntValue> SampleSizeParameter {
39      get { return (IValueLookupParameter<IntValue>)Parameters["SampleSize"]; }
40    }
41
42    public IntValue SampleSize {
43      get { return SampleSizeParameter.Value; }
44      set { SampleSizeParameter.Value = value; }
45    }
46
47    [StorableConstructor]
48    protected Stochastic25MultiMoveGenerator(bool deserializing) : base(deserializing) { }
49    protected Stochastic25MultiMoveGenerator(Stochastic25MultiMoveGenerator original, Cloner cloner) : base(original, cloner) { }
50    public Stochastic25MultiMoveGenerator()
51      : base() {
52      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator."));
53      Parameters.Add(new ValueLookupParameter<IntValue>("SampleSize", "The number of moves to generate."));
54    }
55
56    public override IDeepCloneable Clone(Cloner cloner) {
57      return new Stochastic25MultiMoveGenerator(this, cloner);
58    }
59
60    public static TwoPointFiveMove[] Apply(Permutation permutation, IRandom random, int sampleSize) {
61      int length = permutation.Length;
62      TwoPointFiveMove[] moves = new TwoPointFiveMove[sampleSize];
63      for (int i = 0; i < sampleSize; i++) {
64        moves[i] = Stochastic25SingleMoveGenerator.Apply(permutation, random);
65      }
66      return moves;
67    }
68
69    protected override TwoPointFiveMove[] GenerateMoves(Permutation permutation) {
70      IRandom random = RandomParameter.ActualValue;
71      return Apply(permutation, random, SampleSizeParameter.ActualValue.Value);
72    }
73  }
74}
Note: See TracBrowser for help on using the repository browser.