Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/Moves/MultiVRPMoveOperator/MultiVRPMoveTabuChecker.cs @ 17590

Last change on this file since 17590 was 17181, checked in by swagner, 5 years ago

#2875: Merged r17180 from trunk to stable

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