1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2019 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 |
|
---|
22 | using System.Linq;
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Operators;
|
---|
27 | using HeuristicLab.Optimization;
|
---|
28 | using HeuristicLab.Parameters;
|
---|
29 | using HEAL.Attic;
|
---|
30 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
|
---|
33 | [Item("PotvinCustomerRelocationTabuCriterion", @"Checks if a certain customer relocation move is tabu.")]
|
---|
34 | [StorableType("DFA45CF0-EE4A-47C5-B98B-FB82251463D3")]
|
---|
35 | public class PotvinCustomerRelocationMoveTabuCriterion : SingleSuccessorOperator, IPotvinCustomerRelocationMoveOperator, ITabuChecker, IPotvinOperator, IVRPMoveOperator {
|
---|
36 | public override bool CanChangeName {
|
---|
37 | get { return false; }
|
---|
38 | }
|
---|
39 |
|
---|
40 | public ILookupParameter<PotvinCustomerRelocationMove> CustomerRelocationMoveParameter {
|
---|
41 | get { return (ILookupParameter<PotvinCustomerRelocationMove>)Parameters["PotvinCustomerRelocationMove"]; }
|
---|
42 | }
|
---|
43 | public ILookupParameter VRPMoveParameter {
|
---|
44 | get { return CustomerRelocationMoveParameter; }
|
---|
45 | }
|
---|
46 | public ILookupParameter<IVRPEncoding> VRPToursParameter {
|
---|
47 | get { return (ILookupParameter<IVRPEncoding>)Parameters["VRPTours"]; }
|
---|
48 | }
|
---|
49 | public ILookupParameter<IVRPProblemInstance> ProblemInstanceParameter {
|
---|
50 | get { return (LookupParameter<IVRPProblemInstance>)Parameters["ProblemInstance"]; }
|
---|
51 | }
|
---|
52 |
|
---|
53 | public ILookupParameter<ItemList<IItem>> TabuListParameter {
|
---|
54 | get { return (ILookupParameter<ItemList<IItem>>)Parameters["TabuList"]; }
|
---|
55 | }
|
---|
56 | public ILookupParameter<BoolValue> MoveTabuParameter {
|
---|
57 | get { return (ILookupParameter<BoolValue>)Parameters["MoveTabu"]; }
|
---|
58 | }
|
---|
59 | public IValueLookupParameter<BoolValue> MaximizationParameter {
|
---|
60 | get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
|
---|
61 | }
|
---|
62 | public ILookupParameter<DoubleValue> MoveQualityParameter {
|
---|
63 | get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; }
|
---|
64 | }
|
---|
65 | public ValueParameter<BoolValue> UseAspirationCriterionParameter {
|
---|
66 | get { return (ValueParameter<BoolValue>)Parameters["UseAspirationCriterion"]; }
|
---|
67 | }
|
---|
68 |
|
---|
69 | public BoolValue UseAspirationCriterion {
|
---|
70 | get { return UseAspirationCriterionParameter.Value; }
|
---|
71 | set { UseAspirationCriterionParameter.Value = value; }
|
---|
72 | }
|
---|
73 |
|
---|
74 | [StorableConstructor]
|
---|
75 | protected PotvinCustomerRelocationMoveTabuCriterion(StorableConstructorFlag _) : base(_) { }
|
---|
76 | protected PotvinCustomerRelocationMoveTabuCriterion(PotvinCustomerRelocationMoveTabuCriterion original, Cloner cloner) : base(original, cloner) { }
|
---|
77 | public PotvinCustomerRelocationMoveTabuCriterion()
|
---|
78 | : base() {
|
---|
79 | Parameters.Add(new LookupParameter<PotvinCustomerRelocationMove>("PotvinCustomerRelocationMove", "The moves that should be made."));
|
---|
80 | Parameters.Add(new LookupParameter<IVRPEncoding>("VRPTours", "The VRP tours considered in the move."));
|
---|
81 | Parameters.Add(new LookupParameter<IVRPProblemInstance>("ProblemInstance", "The VRP problem instance"));
|
---|
82 |
|
---|
83 | Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The variable to store if a move was tabu."));
|
---|
84 | Parameters.Add(new LookupParameter<ItemList<IItem>>("TabuList", "The tabu list."));
|
---|
85 | Parameters.Add(new ValueParameter<BoolValue>("UseAspirationCriterion", "Whether to use the aspiration criterion or not.", new BoolValue(true)));
|
---|
86 | Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, else if it is a minimization problem."));
|
---|
87 | Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The quality of the current move."));
|
---|
88 | }
|
---|
89 |
|
---|
90 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
91 | return new PotvinCustomerRelocationMoveTabuCriterion(this, cloner);
|
---|
92 | }
|
---|
93 |
|
---|
94 | public override IOperation Apply() {
|
---|
95 | ItemList<IItem> tabuList = TabuListParameter.ActualValue;
|
---|
96 | double moveQuality = MoveQualityParameter.ActualValue.Value;
|
---|
97 | bool useAspiration = UseAspirationCriterion.Value;
|
---|
98 | bool isTabu = false;
|
---|
99 | PotvinCustomerRelocationMove move = CustomerRelocationMoveParameter.ActualValue;
|
---|
100 |
|
---|
101 | foreach (var attribute in tabuList.OfType<PotvinCustomerRelocationMoveAttribute>()) {
|
---|
102 | if (!useAspiration || moveQuality >= attribute.MoveQuality) {
|
---|
103 | if (attribute.City == move.City && attribute.Tour == move.Tour) {
|
---|
104 | isTabu = true;
|
---|
105 | break;
|
---|
106 | }
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | MoveTabuParameter.ActualValue = new BoolValue(isTabu);
|
---|
111 | return base.Apply();
|
---|
112 | }
|
---|
113 | }
|
---|
114 | }
|
---|