Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Moves/MultiVRPMoveOperator/MultiVRPMoveTabuChecker.cs @ 7203

Last change on this file since 7203 was 6772, checked in by svonolfe, 13 years ago

Added support for multiple moves in tabu search (#1177)

File size: 4.8 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.Data;
24using HeuristicLab.Operators;
25using HeuristicLab.Optimization;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using System.Collections.Generic;
29using HeuristicLab.Problems.VehicleRouting.Variants;
30using HeuristicLab.Common;
31using HeuristicLab.Problems.VehicleRouting.Interfaces;
32
33namespace HeuristicLab.Problems.VehicleRouting.Encodings.General{
34  [Item("MultiVRPMoveTabuChecker", "Checks if a VRP move is tabu.")]
35  [StorableClass]
36  public class MultiVRPMoveTabuChecker : SingleSuccessorOperator, IMultiVRPMoveOperator, ITabuChecker, IGeneralVRPOperator {
37    public ILookupParameter VRPMoveParameter {
38      get { return (ILookupParameter)Parameters["VRPMove"]; }
39    }
40
41    public ILookupParameter<IVRPEncoding> VRPToursParameter {
42      get { return (ILookupParameter<IVRPEncoding>)Parameters["VRPTours"]; }
43    }
44    public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter {
45      get { return (LookupParameter<IVRPProblemInstance>)Parameters["ProblemInstance"]; }
46    }
47
48    public ILookupParameter<ItemList<IItem>> TabuListParameter {
49      get { return (ILookupParameter<ItemList<IItem>>)Parameters["TabuList"]; }
50    }
51    public ILookupParameter<BoolValue> MoveTabuParameter {
52      get { return (ILookupParameter<BoolValue>)Parameters["MoveTabu"]; }
53    }
54    public IValueLookupParameter<BoolValue> MaximizationParameter {
55      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
56    }
57    public ILookupParameter<DoubleValue> MoveQualityParameter {
58      get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
59    }
60    public ValueParameter<BoolValue> UseAspirationCriterionParameter {
61      get { return (ValueParameter<BoolValue>)Parameters["UseAspirationCriterion"]; }
62    }
63
64    public BoolValue UseAspirationCriterion {
65      get { return UseAspirationCriterionParameter.Value; }
66      set { UseAspirationCriterionParameter.Value = value; }
67    }
68   
69    [StorableConstructor]
70    private MultiVRPMoveTabuChecker(bool deserializing) : base(deserializing) { }
71
72    public MultiVRPMoveTabuChecker()
73      : base() {
74      Parameters.Add(new LookupParameter<IVRPMove>("VRPMove", "The move."));
75      Parameters.Add(new LookupParameter<IVRPEncoding>("VRPTours", "The VRP tours considered in the move."));
76      Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The VRP problem instance"));
77
78      Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The variable to store if a move was tabu."));
79      Parameters.Add(new LookupParameter<ItemList<IItem>>("TabuList", "The tabu list."));
80      Parameters.Add(new ValueParameter<BoolValue>("UseAspirationCriterion", "Whether to use the aspiration criterion or not.", new BoolValue(true)));
81      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, else if it is a minimization problem."));
82      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The quality of the current move."));
83    }
84
85    public override IDeepCloneable Clone(Cloner cloner) {
86      return new MultiVRPMoveTabuChecker(this, cloner);
87    }
88
89    protected MultiVRPMoveTabuChecker(MultiVRPMoveTabuChecker original, Cloner cloner)
90      : base(original, cloner) {
91    }
92
93    public override IOperation Apply() {
94      IVRPMove move = VRPMoveParameter.ActualValue as IVRPMove;
95
96      ITabuChecker tabuChecker;
97      if (UseAspirationCriterion.Value)
98        tabuChecker = move.GetSoftTabuChecker();
99      else
100        tabuChecker = move.GetTabuChecker();
101
102      (tabuChecker as IVRPMoveOperator).VRPMoveParameter.ActualName = VRPMoveParameter.Name;
103
104      OperationCollection next = new OperationCollection(base.Apply());
105      next.Insert(0, ExecutionContext.CreateOperation(tabuChecker));
106
107      return next;
108    }
109  }
110}
Note: See TracBrowser for help on using the repository browser.