Free cookie consent management tool by TermsFeed Policy Generator

source: branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/ProblemInstances/MultiDepotVRP/MDCVRP/MDCVRPTW/MDCVRPPDTW/MDCVRPPDTWProblemInstance.cs @ 6856

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

Added support for the multi depot pickup and delivery problem with time windows (#1177)

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