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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
28 | using HeuristicLab.Core;
|
---|
29 | using HeuristicLab.Parameters;
|
---|
30 | using HeuristicLab.Data;
|
---|
31 | using HeuristicLab.Optimization;
|
---|
32 | using HeuristicLab.PluginInfrastructure;
|
---|
33 | using HeuristicLab.Problems.VehicleRouting.Variants;
|
---|
34 | using HeuristicLab.Common;
|
---|
35 |
|
---|
36 | namespace 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 | } |
---|