Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPTW/MDCVRPPDTW/MDCVRPPDTWProblemInstance.cs @ 18190

Last change on this file since 18190 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 6.0 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 System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30using HEAL.Attic;
31using HeuristicLab.PluginInfrastructure;
32using HeuristicLab.Problems.VehicleRouting.Interfaces;
33using HeuristicLab.Problems.VehicleRouting.Variants;
34
35namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
36  [Item("MDCVRPPDTWProblemInstance", "Represents a multi depot CVRPPDTW instance.")]
37  [StorableType("A77F180E-8DE5-43E2-B9A4-313B5E2C5A06")]
38  public class MDCVRPPDTWProblemInstance : MDCVRPTWProblemInstance, IPickupAndDeliveryProblemInstance {
39    protected IValueParameter<IntArray> PickupDeliveryLocationParameter {
40      get { return (IValueParameter<IntArray>)Parameters["PickupDeliveryLocation"]; }
41    }
42    protected IValueParameter<DoubleValue> PickupViolationPenaltyParameter {
43      get { return (IValueParameter<DoubleValue>)Parameters["EvalPickupViolationPenalty"]; }
44    }
45
46    public IntArray PickupDeliveryLocation {
47      get { return PickupDeliveryLocationParameter.Value; }
48      set { PickupDeliveryLocationParameter.Value = value; }
49    }
50
51    protected IValueParameter<DoubleValue> CurrentPickupViolationPenaltyParameter {
52      get { return (IValueParameter<DoubleValue>)Parameters["CurrentPickupViolationPenalty"]; }
53    }
54
55    public DoubleValue PickupViolationPenalty {
56      get {
57        DoubleValue currentPickupViolationPenalty = CurrentPickupViolationPenaltyParameter.Value;
58        if (currentPickupViolationPenalty != null)
59          return currentPickupViolationPenalty;
60        else
61          return PickupViolationPenaltyParameter.Value;
62      }
63    }
64    DoubleValue IPickupAndDeliveryProblemInstance.CurrentPickupViolationPenalty {
65      get { return CurrentPickupViolationPenaltyParameter.Value; }
66      set { CurrentPickupViolationPenaltyParameter.Value = value; }
67    }
68
69    protected override IEnumerable<IOperator> GetOperators() {
70      return
71        ApplicationManager.Manager.GetInstances<IPickupAndDeliveryOperator>()
72        .Where(o => !(o is IAnalyzer))
73        .Cast<IOperator>().Union(base.GetOperators());
74    }
75
76    protected override IEnumerable<IOperator> GetAnalyzers() {
77      return ApplicationManager.Manager.GetInstances<IPickupAndDeliveryOperator>()
78        .Where(o => o is IAnalyzer)
79        .Cast<IOperator>().Union(base.GetAnalyzers());
80    }
81
82    protected override IVRPEvaluator Evaluator {
83      get {
84        return new MDCVRPPDTWEvaluator();
85      }
86    }
87
88    public int GetPickupDeliveryLocation(int city) {
89      return PickupDeliveryLocation[city - 1];
90    }
91
92    [StorableConstructor]
93    protected MDCVRPPDTWProblemInstance(StorableConstructorFlag _) : base(_) { }
94
95    public MDCVRPPDTWProblemInstance() {
96      Parameters.Add(new ValueParameter<IntArray>("PickupDeliveryLocation", "The pickup and delivery location for each customer.", new IntArray()));
97
98      Parameters.Add(new ValueParameter<DoubleValue>("EvalPickupViolationPenalty", "The pickup violation penalty considered in the evaluation.", new DoubleValue(100)));
99      Parameters.Add(new OptionalValueParameter<DoubleValue>("CurrentPickupViolationPenalty", "The current pickup violation penalty considered in the evaluation.") { Hidden = true });
100
101      AttachEventHandlers();
102    }
103
104    public override IDeepCloneable Clone(Cloner cloner) {
105      return new MDCVRPPDTWProblemInstance(this, cloner);
106    }
107
108    protected MDCVRPPDTWProblemInstance(MDCVRPPDTWProblemInstance original, Cloner cloner)
109      : base(original, cloner) {
110      AttachEventHandlers();
111    }
112
113    [StorableHook(HookType.AfterDeserialization)]
114    private void AfterDeserialization() {
115      AttachEventHandlers();
116    }
117
118    private void AttachEventHandlers() {
119      PickupDeliveryLocationParameter.ValueChanged += PickupDeliveryLocationParameter_ValueChanged;
120      PickupDeliveryLocation.Reset += PickupDeliveryLocation_Changed;
121      PickupDeliveryLocation.ItemChanged += PickupDeliveryLocation_Changed;
122      PickupViolationPenaltyParameter.ValueChanged += PickupViolationPenaltyParameter_ValueChanged;
123      PickupViolationPenalty.ValueChanged += PickupViolationPenalty_Changed;
124    }
125
126    public override void InitializeState() {
127      base.InitializeState();
128
129      CurrentPickupViolationPenaltyParameter.Value = null;
130    }
131
132    #region Event handlers
133    void PickupDeliveryLocationParameter_ValueChanged(object sender, EventArgs e) {
134      PickupDeliveryLocation.Reset += PickupDeliveryLocation_Changed;
135      PickupDeliveryLocation.ItemChanged += PickupDeliveryLocation_Changed;
136      EvalBestKnownSolution();
137    }
138    private void PickupDeliveryLocation_Changed(object sender, EventArgs e) {
139      EvalBestKnownSolution();
140    }
141    private void PickupViolationPenaltyParameter_ValueChanged(object sender, EventArgs e) {
142      PickupViolationPenalty.ValueChanged += PickupViolationPenalty_Changed;
143      EvalBestKnownSolution();
144    }
145    private void PickupViolationPenalty_Changed(object sender, EventArgs e) {
146      EvalBestKnownSolution();
147    }
148    #endregion
149  }
150}
Note: See TracBrowser for help on using the repository browser.