Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Prins/Manipulators/PrinsExhaustiveLSManipulator.cs @ 4752

Last change on this file since 4752 was 4752, checked in by svonolfe, 14 years ago

Merged relevant changes from the trunk into the branch (cloning,...) (#1177)

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.Core;
23using HeuristicLab.Encodings.PermutationEncoding;
24using HeuristicLab.Parameters;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26using HeuristicLab.Data;
27using System.Collections.Generic;
28using HeuristicLab.Common;
29
30namespace HeuristicLab.Problems.VehicleRouting.Encodings.Prins {
31  [Item("PrinsExhaustiveLSManipulator", "An operator which manipulates a VRP representation by using the exhaustive 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.")]
32  [StorableClass]
33  public sealed class PrinsExhaustiveLSManipulator : PrinsLSManipulator {   
34    [StorableConstructor]
35    private PrinsExhaustiveLSManipulator(bool deserializing) : base(deserializing) { }
36
37    public PrinsExhaustiveLSManipulator()
38      : base() {
39    }
40
41    public override IDeepCloneable Clone(Cloner cloner) {
42      return new PrinsExhaustiveLSManipulator(this, cloner);
43    }
44
45    private PrinsExhaustiveLSManipulator(PrinsExhaustiveLSManipulator original, Cloner cloner)
46      : base(original, cloner) {
47    }
48
49    protected override void Manipulate(IRandom random, PrinsEncoding individual) {
50      List<Tour> tours = individual.GetTours();
51      bool improvement = false;
52      int iterations = 0;
53
54      do {
55        int u = depot;
56        improvement = false;
57        double originalQuality = GetQuality(individual);
58        PrinsEncoding child = null;
59
60        while (!improvement && u < ProblemInstance.Cities.Value) {
61          int v = depot;
62          while (!improvement && v < ProblemInstance.Cities.Value) {
63            if (u != v) {
64              child = Manipulate(individual,
65                originalQuality, u, v);
66
67              improvement = child != null;
68            }
69            v++;
70          }
71          u++;
72        }
73
74        if (improvement) {
75          for (int i = 0; i < child.Length; i++) {
76            individual[i] = child[i];
77          }
78        }
79
80        iterations++;
81      } while (improvement &&
82        iterations < Iterations.Value.Value);
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.