#region License Information
/* HeuristicLab
* Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.Optimization;
using HeuristicLab.Parameters;
using HEAL.Attic;
using HeuristicLab.PluginInfrastructure;
using HeuristicLab.Problems.VehicleRouting.Interfaces;
using HeuristicLab.Problems.VehicleRouting.Variants;
namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances {
[Item("MDCVRPTWProblemInstance", "Represents a multi depot CVRPTW instance.")]
[StorableType("ADC41AA7-EFA6-46FB-BBA7-DC08AE0A26F0")]
public class MDCVRPTWProblemInstance : MDCVRPProblemInstance, ITimeWindowedProblemInstance {
protected IValueParameter ReadyTimeParameter {
get { return (IValueParameter)Parameters["ReadyTime"]; }
}
protected IValueParameter DueTimeParameter {
get { return (IValueParameter)Parameters["DueTime"]; }
}
protected IValueParameter ServiceTimeParameter {
get { return (IValueParameter)Parameters["ServiceTime"]; }
}
protected IValueParameter TimeFactorParameter {
get { return (IValueParameter)Parameters["EvalTimeFactor"]; }
}
protected IValueParameter TardinessPenaltyParameter {
get { return (IValueParameter)Parameters["EvalTardinessPenalty"]; }
}
public DoubleArray ReadyTime {
get { return ReadyTimeParameter.Value; }
set { ReadyTimeParameter.Value = value; }
}
public DoubleArray DueTime {
get { return DueTimeParameter.Value; }
set { DueTimeParameter.Value = value; }
}
public DoubleArray ServiceTime {
get { return ServiceTimeParameter.Value; }
set { ServiceTimeParameter.Value = value; }
}
public DoubleValue TimeFactor {
get { return TimeFactorParameter.Value; }
set { TimeFactorParameter.Value = value; }
}
protected IValueParameter CurrentTardinessPenaltyParameter {
get { return (IValueParameter)Parameters["CurrentTardinessPenalty"]; }
}
public DoubleValue TardinessPenalty {
get {
DoubleValue currentTardinessPenalty = CurrentTardinessPenaltyParameter.Value;
if (currentTardinessPenalty != null)
return currentTardinessPenalty;
else
return TardinessPenaltyParameter.Value;
}
}
DoubleValue ITimeWindowedProblemInstance.CurrentTardinessPenalty {
get { return CurrentTardinessPenaltyParameter.Value; }
set { CurrentTardinessPenaltyParameter.Value = value; }
}
protected override IEnumerable GetOperators() {
return base.GetOperators()
.Where(o => o is ITimeWindowedOperator).Cast();
}
protected override IEnumerable GetAnalyzers() {
return ApplicationManager.Manager.GetInstances()
.Where(o => o is IAnalyzer)
.Cast().Union(base.GetAnalyzers());
}
protected override IVRPEvaluator Evaluator {
get {
return new MDCVRPTWEvaluator();
}
}
[StorableConstructor]
protected MDCVRPTWProblemInstance(StorableConstructorFlag _) : base(_) { }
public MDCVRPTWProblemInstance() {
Parameters.Add(new ValueParameter("ReadyTime", "The ready time of each customer.", new DoubleArray()));
Parameters.Add(new ValueParameter("DueTime", "The due time of each customer.", new DoubleArray()));
Parameters.Add(new ValueParameter("ServiceTime", "The service time of each customer.", new DoubleArray()));
Parameters.Add(new ValueParameter("EvalTimeFactor", "The time factor considered in the evaluation.", new DoubleValue(0)));
Parameters.Add(new ValueParameter("EvalTardinessPenalty", "The tardiness penalty considered in the evaluation.", new DoubleValue(100)));
Parameters.Add(new OptionalValueParameter("CurrentTardinessPenalty", "The current tardiness penalty considered in the evaluation.") { Hidden = true });
AttachEventHandlers();
}
public override IDeepCloneable Clone(Cloner cloner) {
return new MDCVRPTWProblemInstance(this, cloner);
}
protected MDCVRPTWProblemInstance(MDCVRPTWProblemInstance original, Cloner cloner)
: base(original, cloner) {
AttachEventHandlers();
}
[StorableHook(HookType.AfterDeserialization)]
private void AfterDeserialization() {
AttachEventHandlers();
}
private void AttachEventHandlers() {
ReadyTimeParameter.ValueChanged += ReadyTimeParameter_ValueChanged;
ReadyTime.Reset += ReadyTime_Changed;
ReadyTime.ItemChanged += ReadyTime_Changed;
DueTimeParameter.ValueChanged += DueTimeParameter_ValueChanged;
DueTime.Reset += DueTime_Changed;
DueTime.ItemChanged += DueTime_Changed;
ServiceTimeParameter.ValueChanged += ServiceTimeParameter_ValueChanged;
ServiceTime.Reset += ServiceTime_Changed;
ServiceTime.ItemChanged += ServiceTime_Changed;
TardinessPenaltyParameter.ValueChanged += TardinessPenaltyParameter_ValueChanged;
TardinessPenalty.ValueChanged += TardinessPenalty_ValueChanged;
TimeFactorParameter.ValueChanged += TimeFactorParameter_ValueChanged;
TimeFactor.ValueChanged += TimeFactor_ValueChanged;
}
public override void InitializeState() {
base.InitializeState();
CurrentTardinessPenaltyParameter.Value = null;
}
#region Event handlers
private void ReadyTimeParameter_ValueChanged(object sender, EventArgs e) {
ReadyTime.Reset += ReadyTime_Changed;
ReadyTime.ItemChanged += ReadyTime_Changed;
EvalBestKnownSolution();
}
private void ReadyTime_Changed(object sender, EventArgs e) {
EvalBestKnownSolution();
}
private void DueTimeParameter_ValueChanged(object sender, EventArgs e) {
DueTime.Reset += DueTime_Changed;
DueTime.ItemChanged += DueTime_Changed;
EvalBestKnownSolution();
}
private void DueTime_Changed(object sender, EventArgs e) {
EvalBestKnownSolution();
}
private void ServiceTimeParameter_ValueChanged(object sender, EventArgs e) {
ServiceTime.Reset += ServiceTime_Changed;
ServiceTime.ItemChanged += ServiceTime_Changed;
EvalBestKnownSolution();
}
private void ServiceTime_Changed(object sender, EventArgs e) {
EvalBestKnownSolution();
}
private void TardinessPenaltyParameter_ValueChanged(object sender, EventArgs e) {
TardinessPenalty.ValueChanged += TardinessPenalty_ValueChanged;
EvalBestKnownSolution();
}
private void TardinessPenalty_ValueChanged(object sender, EventArgs e) {
EvalBestKnownSolution();
}
private void TimeFactorParameter_ValueChanged(object sender, EventArgs e) {
TimeFactor.ValueChanged += TimeFactor_ValueChanged;
EvalBestKnownSolution();
}
private void TimeFactor_ValueChanged(object sender, EventArgs e) {
EvalBestKnownSolution();
}
#endregion
}
}