[6854] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[11170] | 3 | * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6854] | 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;
|
---|
[6854] | 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
| 28 | using HeuristicLab.Optimization;
|
---|
[7934] | 29 | using HeuristicLab.Parameters;
|
---|
| 30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[6854] | 31 | using HeuristicLab.PluginInfrastructure;
|
---|
[7934] | 32 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
[6854] | 33 | using HeuristicLab.Problems.VehicleRouting.Variants;
|
---|
| 34 |
|
---|
| 35 | namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
|
---|
| 36 | [Item("MDCVRPTWProblemInstance", "Represents a multi depot CVRPTW instance.")]
|
---|
| 37 | [StorableClass]
|
---|
[7934] | 38 | public class MDCVRPTWProblemInstance : MDCVRPProblemInstance, ITimeWindowedProblemInstance {
|
---|
[6854] | 39 | protected IValueParameter<DoubleArray> ReadyTimeParameter {
|
---|
| 40 | get { return (IValueParameter<DoubleArray>)Parameters["ReadyTime"]; }
|
---|
| 41 | }
|
---|
| 42 | protected IValueParameter<DoubleArray> DueTimeParameter {
|
---|
| 43 | get { return (IValueParameter<DoubleArray>)Parameters["DueTime"]; }
|
---|
| 44 | }
|
---|
| 45 | protected IValueParameter<DoubleArray> ServiceTimeParameter {
|
---|
| 46 | get { return (IValueParameter<DoubleArray>)Parameters["ServiceTime"]; }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | protected IValueParameter<DoubleValue> TimeFactorParameter {
|
---|
| 50 | get { return (IValueParameter<DoubleValue>)Parameters["EvalTimeFactor"]; }
|
---|
| 51 | }
|
---|
| 52 | protected IValueParameter<DoubleValue> TardinessPenaltyParameter {
|
---|
| 53 | get { return (IValueParameter<DoubleValue>)Parameters["EvalTardinessPenalty"]; }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | public DoubleArray ReadyTime {
|
---|
| 57 | get { return ReadyTimeParameter.Value; }
|
---|
| 58 | set { ReadyTimeParameter.Value = value; }
|
---|
| 59 | }
|
---|
| 60 | public DoubleArray DueTime {
|
---|
| 61 | get { return DueTimeParameter.Value; }
|
---|
| 62 | set { DueTimeParameter.Value = value; }
|
---|
| 63 | }
|
---|
| 64 | public DoubleArray ServiceTime {
|
---|
| 65 | get { return ServiceTimeParameter.Value; }
|
---|
| 66 | set { ServiceTimeParameter.Value = value; }
|
---|
| 67 | }
|
---|
| 68 | public DoubleValue TimeFactor {
|
---|
| 69 | get { return TimeFactorParameter.Value; }
|
---|
| 70 | set { TimeFactorParameter.Value = value; }
|
---|
| 71 | }
|
---|
| 72 |
|
---|
[7864] | 73 | protected IValueParameter<DoubleValue> CurrentTardinessPenaltyParameter {
|
---|
| 74 | get { return (IValueParameter<DoubleValue>)Parameters["CurrentTardinessPenalty"]; }
|
---|
| 75 | }
|
---|
[6854] | 76 |
|
---|
| 77 | public DoubleValue TardinessPenalty {
|
---|
| 78 | get {
|
---|
[7864] | 79 | DoubleValue currentTardinessPenalty = CurrentTardinessPenaltyParameter.Value;
|
---|
[6854] | 80 | if (currentTardinessPenalty != null)
|
---|
| 81 | return currentTardinessPenalty;
|
---|
| 82 | else
|
---|
| 83 | return TardinessPenaltyParameter.Value;
|
---|
| 84 | }
|
---|
[7864] | 85 | set { CurrentTardinessPenaltyParameter.Value = value; }
|
---|
[6854] | 86 | }
|
---|
| 87 |
|
---|
| 88 | protected override IEnumerable<IOperator> GetOperators() {
|
---|
| 89 | return base.GetOperators()
|
---|
| 90 | .Where(o => o is ITimeWindowedOperator).Cast<IOperator>();
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | protected override IEnumerable<IOperator> GetAnalyzers() {
|
---|
| 94 | return ApplicationManager.Manager.GetInstances<ITimeWindowedOperator>()
|
---|
| 95 | .Where(o => o is IAnalyzer)
|
---|
| 96 | .Cast<IOperator>().Union(base.GetAnalyzers());
|
---|
| 97 | }
|
---|
[7934] | 98 |
|
---|
[6854] | 99 | protected override IVRPEvaluator Evaluator {
|
---|
| 100 | get {
|
---|
| 101 | return new MDCVRPTWEvaluator();
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
[7934] | 104 |
|
---|
[6854] | 105 | [StorableConstructor]
|
---|
| 106 | protected MDCVRPTWProblemInstance(bool deserializing) : base(deserializing) { }
|
---|
| 107 |
|
---|
| 108 | public MDCVRPTWProblemInstance() {
|
---|
| 109 | Parameters.Add(new ValueParameter<DoubleArray>("ReadyTime", "The ready time of each customer.", new DoubleArray()));
|
---|
| 110 | Parameters.Add(new ValueParameter<DoubleArray>("DueTime", "The due time of each customer.", new DoubleArray()));
|
---|
| 111 | Parameters.Add(new ValueParameter<DoubleArray>("ServiceTime", "The service time of each customer.", new DoubleArray()));
|
---|
| 112 |
|
---|
| 113 | Parameters.Add(new ValueParameter<DoubleValue>("EvalTimeFactor", "The time factor considered in the evaluation.", new DoubleValue(0)));
|
---|
| 114 | Parameters.Add(new ValueParameter<DoubleValue>("EvalTardinessPenalty", "The tardiness penalty considered in the evaluation.", new DoubleValue(100)));
|
---|
[7864] | 115 | Parameters.Add(new OptionalValueParameter<DoubleValue>("CurrentTardinessPenalty", "The current tardiness penalty considered in the evaluation."));
|
---|
[6854] | 116 |
|
---|
| 117 | AttachEventHandlers();
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 121 | return new MDCVRPTWProblemInstance(this, cloner);
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | protected MDCVRPTWProblemInstance(MDCVRPTWProblemInstance original, Cloner cloner)
|
---|
| 125 | : base(original, cloner) {
|
---|
[7934] | 126 | AttachEventHandlers();
|
---|
[6854] | 127 | }
|
---|
| 128 |
|
---|
| 129 | [StorableHook(HookType.AfterDeserialization)]
|
---|
[7934] | 130 | private void AfterDeserialization() {
|
---|
[6854] | 131 | AttachEventHandlers();
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | private void AttachEventHandlers() {
|
---|
| 135 | TardinessPenaltyParameter.ValueChanged += new EventHandler(TardinessPenaltyParameter_ValueChanged);
|
---|
| 136 | TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenalty_ValueChanged);
|
---|
| 137 | TimeFactorParameter.ValueChanged += new EventHandler(TimeFactorParameter_ValueChanged);
|
---|
| 138 | TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactor_ValueChanged);
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | public override void InitializeState() {
|
---|
| 142 | base.InitializeState();
|
---|
| 143 |
|
---|
[7864] | 144 | CurrentTardinessPenaltyParameter.Value = null;
|
---|
[6854] | 145 | }
|
---|
| 146 |
|
---|
| 147 | #region Event handlers
|
---|
| 148 | void TardinessPenaltyParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 149 | TardinessPenaltyParameter.Value.ValueChanged += new EventHandler(TardinessPenalty_ValueChanged);
|
---|
| 150 | EvalBestKnownSolution();
|
---|
| 151 | }
|
---|
| 152 | void TardinessPenalty_ValueChanged(object sender, EventArgs e) {
|
---|
| 153 | EvalBestKnownSolution();
|
---|
| 154 | }
|
---|
| 155 | void TimeFactorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 156 | TimeFactorParameter.Value.ValueChanged += new EventHandler(TimeFactor_ValueChanged);
|
---|
| 157 | EvalBestKnownSolution();
|
---|
| 158 | }
|
---|
| 159 | void TimeFactor_ValueChanged(object sender, EventArgs e) {
|
---|
| 160 | EvalBestKnownSolution();
|
---|
| 161 | }
|
---|
| 162 | #endregion
|
---|
| 163 | }
|
---|
| 164 | } |
---|