#region License Information /* HeuristicLab * Copyright (C) 2002-2015 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 HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.PluginInfrastructure; using HeuristicLab.Problems.VehicleRouting.Interfaces; using HeuristicLab.Problems.VehicleRouting.Variants; namespace HeuristicLab.Problems.VehicleRouting.ProblemInstances { [Item("CVRPPDTWProblemInstance", "Represents a single depot CVRPPDTW instance.")] [StorableClass] public class CVRPPDTWProblemInstance : CVRPTWProblemInstance, IPickupAndDeliveryProblemInstance { protected IValueParameter PickupDeliveryLocationParameter { get { return (IValueParameter)Parameters["PickupDeliveryLocation"]; } } protected IValueParameter PickupViolationPenaltyParameter { get { return (IValueParameter)Parameters["EvalPickupViolationPenalty"]; } } public IntArray PickupDeliveryLocation { get { return PickupDeliveryLocationParameter.Value; } set { PickupDeliveryLocationParameter.Value = value; } } protected IValueParameter CurrentPickupViolationPenaltyParameter { get { return (IValueParameter)Parameters["CurrentPickupViolationPenalty"]; } } public DoubleValue PickupViolationPenalty { get { DoubleValue currentPickupViolationPenalty = CurrentPickupViolationPenaltyParameter.Value; if (currentPickupViolationPenalty != null) return currentPickupViolationPenalty; else return PickupViolationPenaltyParameter.Value; } } DoubleValue IPickupAndDeliveryProblemInstance.CurrentPickupViolationPenalty { get { return CurrentOverloadPenaltyParameter.Value; } set { CurrentPickupViolationPenaltyParameter.Value = value; } } protected override IEnumerable GetOperators() { return ApplicationManager.Manager.GetInstances() .Where(o => !(o is IAnalyzer)) .Cast().Union(base.GetOperators()); } protected override IEnumerable GetAnalyzers() { return ApplicationManager.Manager.GetInstances() .Where(o => o is IAnalyzer) .Cast().Union(base.GetAnalyzers()); } protected override IVRPEvaluator Evaluator { get { return new CVRPPDTWEvaluator(); } } public int GetPickupDeliveryLocation(int city) { return PickupDeliveryLocation[city]; } [StorableConstructor] protected CVRPPDTWProblemInstance(bool deserializing) : base(deserializing) { } public CVRPPDTWProblemInstance() { Parameters.Add(new ValueParameter("PickupDeliveryLocation", "The pickup and delivery location for each customer.", new IntArray())); Parameters.Add(new ValueParameter("EvalPickupViolationPenalty", "The pickup violation penalty considered in the evaluation.", new DoubleValue(100))); Parameters.Add(new OptionalValueParameter("CurrentPickupViolationPenalty", "The current pickup violation penalty considered in the evaluation.") { Hidden = true }); AttachEventHandlers(); } public override IDeepCloneable Clone(Cloner cloner) { return new CVRPPDTWProblemInstance(this, cloner); } protected CVRPPDTWProblemInstance(CVRPPDTWProblemInstance original, Cloner cloner) : base(original, cloner) { AttachEventHandlers(); } [StorableHook(HookType.AfterDeserialization)] private void AfterDeserialization() { AttachEventHandlers(); } private void AttachEventHandlers() { PickupDeliveryLocationParameter.ValueChanged += new EventHandler(PickupDeliveryLocationParameter_ValueChanged); } public override void InitializeState() { base.InitializeState(); CurrentPickupViolationPenaltyParameter.Value = null; } #region Event handlers void PickupDeliveryLocationParameter_ValueChanged(object sender, EventArgs e) { PickupDeliveryLocationParameter.Value.ItemChanged += new EventHandler>(Value_ItemChanged); EvalBestKnownSolution(); } void Value_ItemChanged(object sender, EventArgs e) { EvalBestKnownSolution(); } #endregion } }