[4362] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[4362] | 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;
|
---|
[4362] | 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
| 28 | using HeuristicLab.Optimization;
|
---|
[7934] | 29 | using HeuristicLab.Parameters;
|
---|
[16565] | 30 | using HEAL.Attic;
|
---|
[4362] | 31 | using HeuristicLab.PluginInfrastructure;
|
---|
[7934] | 32 | using HeuristicLab.Problems.VehicleRouting.Interfaces;
|
---|
[4363] | 33 | using HeuristicLab.Problems.VehicleRouting.Variants;
|
---|
[4362] | 34 |
|
---|
| 35 | namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
|
---|
| 36 | [Item("CVRPTWProblemInstance", "Represents a single depot CVRPTW instance.")]
|
---|
[16565] | 37 | [StorableType("2138BE6C-058E-4003-8578-55E8DE3706C7")]
|
---|
[7934] | 38 | public class CVRPTWProblemInstance : CVRPProblemInstance, ITimeWindowedProblemInstance {
|
---|
[4363] | 39 | protected IValueParameter<DoubleArray> ReadyTimeParameter {
|
---|
| 40 | get { return (IValueParameter<DoubleArray>)Parameters["ReadyTime"]; }
|
---|
[4362] | 41 | }
|
---|
[4363] | 42 | protected IValueParameter<DoubleArray> DueTimeParameter {
|
---|
| 43 | get { return (IValueParameter<DoubleArray>)Parameters["DueTime"]; }
|
---|
[4362] | 44 | }
|
---|
[4363] | 45 | protected IValueParameter<DoubleArray> ServiceTimeParameter {
|
---|
| 46 | get { return (IValueParameter<DoubleArray>)Parameters["ServiceTime"]; }
|
---|
[4362] | 47 | }
|
---|
| 48 |
|
---|
| 49 | protected IValueParameter<DoubleValue> TimeFactorParameter {
|
---|
| 50 | get { return (IValueParameter<DoubleValue>)Parameters["EvalTimeFactor"]; }
|
---|
| 51 | }
|
---|
[4454] | 52 | protected IValueParameter<DoubleValue> TardinessPenaltyParameter {
|
---|
[4362] | 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 | }
|
---|
[6711] | 72 |
|
---|
[7864] | 73 | protected IValueParameter<DoubleValue> CurrentTardinessPenaltyParameter {
|
---|
| 74 | get { return (IValueParameter<DoubleValue>)Parameters["CurrentTardinessPenalty"]; }
|
---|
| 75 | }
|
---|
[6711] | 76 |
|
---|
[4362] | 77 | public DoubleValue TardinessPenalty {
|
---|
[6711] | 78 | get {
|
---|
[7864] | 79 | DoubleValue currentTardinessPenalty = CurrentTardinessPenaltyParameter.Value;
|
---|
[6711] | 80 | if (currentTardinessPenalty != null)
|
---|
| 81 | return currentTardinessPenalty;
|
---|
| 82 | else
|
---|
| 83 | return TardinessPenaltyParameter.Value;
|
---|
| 84 | }
|
---|
[12488] | 85 | }
|
---|
| 86 | DoubleValue ITimeWindowedProblemInstance.CurrentTardinessPenalty {
|
---|
| 87 | get { return CurrentTardinessPenaltyParameter.Value; }
|
---|
[7864] | 88 | set { CurrentTardinessPenaltyParameter.Value = value; }
|
---|
[4362] | 89 | }
|
---|
[4374] | 90 |
|
---|
| 91 | protected override IEnumerable<IOperator> GetOperators() {
|
---|
| 92 | return base.GetOperators()
|
---|
| 93 | .Where(o => o is ITimeWindowedOperator).Cast<IOperator>();
|
---|
[4362] | 94 | }
|
---|
[4363] | 95 |
|
---|
[4374] | 96 | protected override IEnumerable<IOperator> GetAnalyzers() {
|
---|
| 97 | return ApplicationManager.Manager.GetInstances<ITimeWindowedOperator>()
|
---|
| 98 | .Where(o => o is IAnalyzer)
|
---|
| 99 | .Cast<IOperator>().Union(base.GetAnalyzers());
|
---|
| 100 | }
|
---|
[7934] | 101 |
|
---|
[4363] | 102 | protected override IVRPEvaluator Evaluator {
|
---|
| 103 | get {
|
---|
| 104 | return new CVRPTWEvaluator();
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
[7934] | 107 |
|
---|
[4362] | 108 | [StorableConstructor]
|
---|
[16565] | 109 | protected CVRPTWProblemInstance(StorableConstructorFlag _) : base(_) { }
|
---|
[4362] | 110 |
|
---|
| 111 | public CVRPTWProblemInstance() {
|
---|
| 112 | Parameters.Add(new ValueParameter<DoubleArray>("ReadyTime", "The ready time of each customer.", new DoubleArray()));
|
---|
| 113 | Parameters.Add(new ValueParameter<DoubleArray>("DueTime", "The due time of each customer.", new DoubleArray()));
|
---|
| 114 | Parameters.Add(new ValueParameter<DoubleArray>("ServiceTime", "The service time of each customer.", new DoubleArray()));
|
---|
| 115 |
|
---|
| 116 | Parameters.Add(new ValueParameter<DoubleValue>("EvalTimeFactor", "The time factor considered in the evaluation.", new DoubleValue(0)));
|
---|
[6710] | 117 | Parameters.Add(new ValueParameter<DoubleValue>("EvalTardinessPenalty", "The tardiness penalty considered in the evaluation.", new DoubleValue(100)));
|
---|
[12488] | 118 | Parameters.Add(new OptionalValueParameter<DoubleValue>("CurrentTardinessPenalty", "The current tardiness penalty considered in the evaluation.") { Hidden = true });
|
---|
[4860] | 119 |
|
---|
| 120 | AttachEventHandlers();
|
---|
[4362] | 121 | }
|
---|
[4752] | 122 |
|
---|
| 123 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 124 | return new CVRPTWProblemInstance(this, cloner);
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | protected CVRPTWProblemInstance(CVRPTWProblemInstance original, Cloner cloner)
|
---|
| 128 | : base(original, cloner) {
|
---|
[7934] | 129 | AttachEventHandlers();
|
---|
[4752] | 130 | }
|
---|
[4860] | 131 |
|
---|
| 132 | [StorableHook(HookType.AfterDeserialization)]
|
---|
[7934] | 133 | private void AfterDeserialization() {
|
---|
[4860] | 134 | AttachEventHandlers();
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | private void AttachEventHandlers() {
|
---|
[15168] | 138 | ReadyTimeParameter.ValueChanged += ReadyTimeParameter_ValueChanged;
|
---|
| 139 | ReadyTime.Reset += ReadyTime_Changed;
|
---|
| 140 | ReadyTime.ItemChanged += ReadyTime_Changed;
|
---|
| 141 | DueTimeParameter.ValueChanged += DueTimeParameter_ValueChanged;
|
---|
| 142 | DueTime.Reset += DueTime_Changed;
|
---|
| 143 | DueTime.ItemChanged += DueTime_Changed;
|
---|
| 144 | ServiceTimeParameter.ValueChanged += ServiceTimeParameter_ValueChanged;
|
---|
| 145 | ServiceTime.Reset += ServiceTime_Changed;
|
---|
| 146 | ServiceTime.ItemChanged += ServiceTime_Changed;
|
---|
| 147 | TardinessPenaltyParameter.ValueChanged += TardinessPenaltyParameter_ValueChanged;
|
---|
| 148 | TardinessPenalty.ValueChanged += TardinessPenalty_ValueChanged;
|
---|
| 149 | TimeFactorParameter.ValueChanged += TimeFactorParameter_ValueChanged;
|
---|
| 150 | TimeFactor.ValueChanged += TimeFactor_ValueChanged;
|
---|
[4860] | 151 | }
|
---|
| 152 |
|
---|
[6711] | 153 | public override void InitializeState() {
|
---|
| 154 | base.InitializeState();
|
---|
| 155 |
|
---|
[7864] | 156 | CurrentTardinessPenaltyParameter.Value = null;
|
---|
[6711] | 157 | }
|
---|
| 158 |
|
---|
[4860] | 159 | #region Event handlers
|
---|
[15168] | 160 | private void ReadyTimeParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 161 | ReadyTime.Reset += ReadyTime_Changed;
|
---|
| 162 | ReadyTime.ItemChanged += ReadyTime_Changed;
|
---|
[4860] | 163 | EvalBestKnownSolution();
|
---|
| 164 | }
|
---|
[15168] | 165 | private void ReadyTime_Changed(object sender, EventArgs e) {
|
---|
[4860] | 166 | EvalBestKnownSolution();
|
---|
| 167 | }
|
---|
[15168] | 168 | private void DueTimeParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 169 | DueTime.Reset += DueTime_Changed;
|
---|
| 170 | DueTime.ItemChanged += DueTime_Changed;
|
---|
[4860] | 171 | EvalBestKnownSolution();
|
---|
| 172 | }
|
---|
[15168] | 173 | private void DueTime_Changed(object sender, EventArgs e) {
|
---|
[4860] | 174 | EvalBestKnownSolution();
|
---|
| 175 | }
|
---|
[15168] | 176 | private void ServiceTimeParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 177 | ServiceTime.Reset += ServiceTime_Changed;
|
---|
| 178 | ServiceTime.ItemChanged += ServiceTime_Changed;
|
---|
| 179 | EvalBestKnownSolution();
|
---|
| 180 | }
|
---|
| 181 | private void ServiceTime_Changed(object sender, EventArgs e) {
|
---|
| 182 | EvalBestKnownSolution();
|
---|
| 183 | }
|
---|
| 184 | private void TardinessPenaltyParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 185 | TardinessPenaltyParameter.Value.ValueChanged += TardinessPenalty_ValueChanged;
|
---|
| 186 | EvalBestKnownSolution();
|
---|
| 187 | }
|
---|
| 188 | private void TardinessPenalty_ValueChanged(object sender, EventArgs e) {
|
---|
| 189 | EvalBestKnownSolution();
|
---|
| 190 | }
|
---|
| 191 | private void TimeFactorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
| 192 | TimeFactorParameter.Value.ValueChanged += TimeFactor_ValueChanged;
|
---|
| 193 | EvalBestKnownSolution();
|
---|
| 194 | }
|
---|
| 195 | private void TimeFactor_ValueChanged(object sender, EventArgs e) {
|
---|
| 196 | EvalBestKnownSolution();
|
---|
| 197 | }
|
---|
[4860] | 198 | #endregion
|
---|
[4362] | 199 | }
|
---|
| 200 | } |
---|