[6710] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14186] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6710] | 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;
|
---|
[7934] | 25 | using HeuristicLab.Common;
|
---|
[6710] | 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
| 28 | using HeuristicLab.Optimization;
|
---|
[7934] | 29 | using HeuristicLab.Parameters;
|
---|
| 30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[6710] | 31 | using HeuristicLab.PluginInfrastructure;
|
---|
[7934] | 32 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
[6710] | 33 | using HeuristicLab.Problems.VehicleRouting.Variants;
|
---|
| 34 |
|
---|
| 35 | namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
|
---|
| 36 | [Item("CVRPPDTWProblemInstance", "Represents a single depot CVRPPDTW instance.")]
|
---|
| 37 | [StorableClass]
|
---|
[7934] | 38 | public class CVRPPDTWProblemInstance : CVRPTWProblemInstance, IPickupAndDeliveryProblemInstance {
|
---|
[6710] | 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 | }
|
---|
[7934] | 45 |
|
---|
[6710] | 46 | public IntArray PickupDeliveryLocation {
|
---|
| 47 | get { return PickupDeliveryLocationParameter.Value; }
|
---|
| 48 | set { PickupDeliveryLocationParameter.Value = value; }
|
---|
| 49 | }
|
---|
| 50 |
|
---|
[7864] | 51 | protected IValueParameter<DoubleValue> CurrentPickupViolationPenaltyParameter {
|
---|
| 52 | get { return (IValueParameter<DoubleValue>)Parameters["CurrentPickupViolationPenalty"]; }
|
---|
| 53 | }
|
---|
[6711] | 54 |
|
---|
[6710] | 55 | public DoubleValue PickupViolationPenalty {
|
---|
[6711] | 56 | get {
|
---|
[7864] | 57 | DoubleValue currentPickupViolationPenalty = CurrentPickupViolationPenaltyParameter.Value;
|
---|
[6711] | 58 | if (currentPickupViolationPenalty != null)
|
---|
| 59 | return currentPickupViolationPenalty;
|
---|
| 60 | else
|
---|
| 61 | return PickupViolationPenaltyParameter.Value;
|
---|
| 62 | }
|
---|
[12738] | 63 | }
|
---|
| 64 | DoubleValue IPickupAndDeliveryProblemInstance.CurrentPickupViolationPenalty {
|
---|
| 65 | get { return CurrentOverloadPenaltyParameter.Value; }
|
---|
[7864] | 66 | set { CurrentPickupViolationPenaltyParameter.Value = value; }
|
---|
[6710] | 67 | }
|
---|
| 68 |
|
---|
| 69 | protected override IEnumerable<IOperator> GetOperators() {
|
---|
[7934] | 70 | return
|
---|
[6710] | 71 | ApplicationManager.Manager.GetInstances<IPickupAndDeliveryOperator>()
|
---|
[6790] | 72 | .Where(o => !(o is IAnalyzer))
|
---|
[6710] | 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 | }
|
---|
[7934] | 81 |
|
---|
[6710] | 82 | protected override IVRPEvaluator Evaluator {
|
---|
| 83 | get {
|
---|
| 84 | return new CVRPPDTWEvaluator();
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
[6856] | 87 |
|
---|
| 88 | public int GetPickupDeliveryLocation(int city) {
|
---|
| 89 | return PickupDeliveryLocation[city];
|
---|
| 90 | }
|
---|
[7934] | 91 |
|
---|
[6710] | 92 | [StorableConstructor]
|
---|
| 93 | protected CVRPPDTWProblemInstance(bool deserializing) : base(deserializing) { }
|
---|
| 94 |
|
---|
| 95 | public CVRPPDTWProblemInstance() {
|
---|
| 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)));
|
---|
[12738] | 99 | Parameters.Add(new OptionalValueParameter<DoubleValue>("CurrentPickupViolationPenalty", "The current pickup violation penalty considered in the evaluation.") { Hidden = true });
|
---|
[6710] | 100 |
|
---|
| 101 | AttachEventHandlers();
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 105 | return new CVRPPDTWProblemInstance(this, cloner);
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | protected CVRPPDTWProblemInstance(CVRPPDTWProblemInstance original, Cloner cloner)
|
---|
| 109 | : base(original, cloner) {
|
---|
[7934] | 110 | AttachEventHandlers();
|
---|
[6710] | 111 | }
|
---|
| 112 |
|
---|
| 113 | [StorableHook(HookType.AfterDeserialization)]
|
---|
[7934] | 114 | private void AfterDeserialization() {
|
---|
[6710] | 115 | AttachEventHandlers();
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | private void AttachEventHandlers() {
|
---|
[15219] | 119 | PickupDeliveryLocationParameter.ValueChanged += PickupDeliveryLocationParameter_ValueChanged;
|
---|
| 120 | PickupDeliveryLocation.Reset += PickupDeliveryLocation_Changed;
|
---|
| 121 | PickupDeliveryLocation.ItemChanged += PickupDeliveryLocation_Changed;
|
---|
[6710] | 122 | }
|
---|
| 123 |
|
---|
[6711] | 124 | public override void InitializeState() {
|
---|
| 125 | base.InitializeState();
|
---|
| 126 |
|
---|
[7864] | 127 | CurrentPickupViolationPenaltyParameter.Value = null;
|
---|
[6711] | 128 | }
|
---|
| 129 |
|
---|
[6710] | 130 | #region Event handlers
|
---|
| 131 | void PickupDeliveryLocationParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[15219] | 132 | PickupDeliveryLocation.Reset += PickupDeliveryLocation_Changed;
|
---|
| 133 | PickupDeliveryLocation.ItemChanged += PickupDeliveryLocation_Changed;
|
---|
[6710] | 134 | EvalBestKnownSolution();
|
---|
| 135 | }
|
---|
[15219] | 136 | private void PickupDeliveryLocation_Changed(object sender, EventArgs e) {
|
---|
[6710] | 137 | EvalBestKnownSolution();
|
---|
| 138 | }
|
---|
| 139 | #endregion
|
---|
| 140 | }
|
---|
| 141 | } |
---|