Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Prins/Manipulators/PrinsStochasticLSManipulator.cs @ 5740

Last change on this file since 5740 was 5445, checked in by swagner, 14 years ago

Updated year of copyrights (#1406)

File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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 HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Problems.VehicleRouting.Encodings.Prins {
30  [Item("PrinsStochasticLSManipulator", "An operator which manipulates a VRP representation by using the stochastic version of the Prins local search.  It is implemented as described in Prins, C. (2004). A simple and effective evolutionary algorithm for the vehicle routing problem. Computers & Operations Research, 12:1985-2002.")]
31  [StorableClass]
32  public sealed class PrinsStochasticLSManipulator : PrinsLSManipulator {
33    public IValueParameter<IntValue> SampleSize {
34      get { return (IValueParameter<IntValue>)Parameters["SampleSize"]; }
35    }
36   
37    [StorableConstructor]
38    private PrinsStochasticLSManipulator(bool deserializing) : base(deserializing) { }
39    private PrinsStochasticLSManipulator(PrinsStochasticLSManipulator original, Cloner cloner) : base(original, cloner) { }
40    public override IDeepCloneable Clone(Cloner cloner) {
41      return new PrinsStochasticLSManipulator(this, cloner);
42    }
43    public PrinsStochasticLSManipulator()
44      : base() {
45        Parameters.Add(new ValueParameter<IntValue>("SampleSize", "The sample size.", new IntValue(200)));
46    }
47
48    protected override void Manipulate(IRandom random, PrinsEncoding individual) {
49      List<Tour> tours = individual.GetTours(DistanceMatrixParameter);
50      bool improvement = false;
51      int iterations = 0;
52
53      do {
54        improvement = false;
55        double originalQuality = GetQuality(individual);
56        PrinsEncoding child = null;
57
58        int samples = 0;
59        while (!improvement &&
60          samples < SampleSize.Value.Value) {
61            int u = random.Next(Cities);
62            int v = random.Next(Cities);
63
64            child = Manipulate(individual,
65                  originalQuality, u, v);
66
67            improvement = child != null;
68
69            samples++;
70        }
71
72        if (improvement) {
73          for (int i = 0; i < child.Length; i++) {
74            individual[i] = child[i];
75          }
76        }
77
78        iterations++;
79      } while (improvement &&
80        iterations < Iterations.Value.Value);
81    }
82  }
83}
Note: See TracBrowser for help on using the repository browser.