Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/Moves/LambdaInterchange/AlbaLambdaInterchangeMoveGenerator.cs @ 14517

Last change on this file since 14517 was 14185, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

File size: 3.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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.Optimization;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.Problems.VehicleRouting.Interfaces;
29
30namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba {
31  [Item("AlbaLambdaInterchangeMoveGenerator", "Generates lambda interchange moves from a given VRP encoding.  It is implemented as described in Alba, E. and Dorronsoro, B. (2004). Solving the Vehicle Routing Problem by Using Cellular Genetic Algorithms.")]
32  [StorableClass]
33  public abstract class AlbaLambdaInterchangeMoveGenerator : AlbaMoveGenerator, IExhaustiveMoveGenerator, IAlbaLambdaInterchangeMoveOperator {
34    #region IAlbaLambdaInterchangeMoveOperator Members
35
36    public ILookupParameter<AlbaLambdaInterchangeMove> LambdaInterchangeMoveParameter {
37      get { return (ILookupParameter<AlbaLambdaInterchangeMove>)Parameters["AlbaLambdaInterchangeMove"]; }
38    }
39
40    public override ILookupParameter VRPMoveParameter {
41      get { return LambdaInterchangeMoveParameter; }
42    }
43
44    protected ScopeParameter CurrentScopeParameter {
45      get { return (ScopeParameter)Parameters["CurrentScope"]; }
46    }
47
48    public IValueParameter<IntValue> LambdaParameter {
49      get { return (IValueParameter<IntValue>)Parameters["Lambda"]; }
50    }
51
52    #endregion
53
54    [StorableConstructor]
55    protected AlbaLambdaInterchangeMoveGenerator(bool deserializing) : base(deserializing) { }
56
57    public AlbaLambdaInterchangeMoveGenerator()
58      : base() {
59      Parameters.Add(new LookupParameter<AlbaLambdaInterchangeMove>("AlbaLambdaInterchangeMove", "The moves that should be generated in subscopes."));
60      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the moves should be added as subscopes."));
61      Parameters.Add(new ValueParameter<IntValue>("Lambda", "The lambda value.", new IntValue(1)));
62    }
63
64    protected AlbaLambdaInterchangeMoveGenerator(AlbaLambdaInterchangeMoveGenerator original, Cloner cloner)
65      : base(original, cloner) {
66    }
67
68    protected abstract AlbaLambdaInterchangeMove[] GenerateMoves(AlbaEncoding individual, IVRPProblemInstance problemInstance, int lambda);
69
70    public override IOperation InstrumentedApply() {
71      IOperation next = base.InstrumentedApply();
72
73      AlbaEncoding individual = VRPToursParameter.ActualValue as AlbaEncoding;
74      AlbaLambdaInterchangeMove[] moves = GenerateMoves(individual, ProblemInstanceParameter.ActualValue, LambdaParameter.Value.Value);
75      Scope[] moveScopes = new Scope[moves.Length];
76      for (int i = 0; i < moveScopes.Length; i++) {
77        moveScopes[i] = new Scope(i.ToString());
78        moveScopes[i].Variables.Add(new Variable(LambdaInterchangeMoveParameter.ActualName, moves[i]));
79      }
80      CurrentScopeParameter.ActualValue.SubScopes.AddRange(moveScopes);
81
82      return next;
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.