#region License Information /* HeuristicLab * Copyright (C) 2002-2010 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 System.Text; using HeuristicLab.Problems.VehicleRouting.Interfaces; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Core; using HeuristicLab.Parameters; using HeuristicLab.Data; using HeuristicLab.Optimization; using HeuristicLab.PluginInfrastructure; using HeuristicLab.Problems.VehicleRouting.Variants; using HeuristicLab.Common; using HeuristicLab.Problems.VehicleRouting.ProblemInstances; using HeuristicLab.PDPSimulation.DistanceMeasures; using HeuristicLab.PDPSimulation.DomainModel; using HeuristicLab.Problems.VehicleRouting.Encodings.Potvin; using System.Threading; namespace HeuristicLab.PDPSimulation.Operators { [Item("DynPDPProblemInstance", "Represents a dynamic multi depot CVRPPDTW instance.")] [StorableClass] public class DynPDPProblemInstance: MDCVRPPDTWProblemInstance { protected ValueParameter DepotCoordinatesParameter { get { return (ValueParameter)Parameters["DepotCoordinates"]; } } protected ValueParameter VehicleUsedParameter { get { return (ValueParameter)Parameters["VehicleUsed"]; } } [Storable] public List VehicleStates { get; set; } [Storable] public PotvinEncoding CurrentPlan { get; set; } public BoolArray VehicleUsed { get { return VehicleUsedParameter.Value; } set { VehicleUsedParameter.Value = value; } } public DoubleMatrix DepotCoordinates { get { return DepotCoordinatesParameter.Value; } set { DepotCoordinatesParameter.Value = value; } } protected override IVRPCreator Creator { get { return new DynPushForwardInsertionCreator(); } } protected override IVRPEvaluator Evaluator { get { return new DynPDPEvaluator(); } } public Barrier AlgorithmSyncObject { get; set; } public Barrier AnalyzerSyncObject { get; set; } [Storable] private ResultCollection results; public ResultCollection Results { get { return results; } } [Storable] private PickupDeliveryScenario scenario; public bool RelocateBackToDepot { get { return scenario.RelocateBackToDepot; } } public double Horizon { get { return scenario.VehicleDueTimesParameter.Value.Max(); } } [Storable] protected WaitingStrategy waitingStrategy; public WaitingStrategy WaitingStrategy { get { return waitingStrategy; } set { waitingStrategy = value; } } [StorableConstructor] protected DynPDPProblemInstance(bool deserializing) : base(deserializing) { } public DynPDPProblemInstance(PickupDeliveryScenario scenario, ResultCollection results) : base() { Parameters.Add(new ValueParameter("DepotCoordinates", "The x- and y-Coordinates of the depots.", new DoubleMatrix())); Parameters.Add(new ValueParameter("VehicleUsed", "Indicates, if a vehicle has been used.", new BoolArray())); this.scenario = scenario; this.results = results; VehicleStates = new List(); if (scenario != null) { SolutionEvaluator = scenario.Evaluator; } } public override IDeepCloneable Clone(Cloner cloner) { return new DynPDPProblemInstance(this, cloner); } protected DynPDPProblemInstance(DynPDPProblemInstance original, Cloner cloner) : base(original, cloner) { this.scenario = cloner.Clone(original.scenario); this.SolutionEvaluator = cloner.Clone(original.SolutionEvaluator); this.results = cloner.Clone(original.results); this.waitingStrategy = cloner.Clone(original.waitingStrategy); this.VehicleStates = new List(original.VehicleStates); this.CurrentPlan = cloner.Clone(CurrentPlan); } public DynPDPProblemInstance ShallowClone() { Cloner cloner = new Cloner(); return new DynPDPProblemInstance(this, cloner, true); } protected DynPDPProblemInstance(DynPDPProblemInstance original, Cloner cloner, bool shallow) : base(original, cloner) { this.scenario = original.scenario; this.SolutionEvaluator = cloner.Clone(original.SolutionEvaluator); this.results = original.results; this.waitingStrategy = original.waitingStrategy; this.VehicleStates = original.VehicleStates; this.CurrentPlan = cloner.Clone(CurrentPlan); } protected override double CalculateDistance(int start, int end) { double distance = 0.0; if (end < Depots.Value) { distance = scenario.DistanceMeasure.GetDistance(Coordinates[start, 0], Coordinates[start, 1], DepotCoordinates[end, 0], DepotCoordinates[end, 1]); } else { distance = scenario.DistanceMeasure.GetDistance(Coordinates[start, 0], Coordinates[start, 1], Coordinates[end, 0], Coordinates[end, 1]); } return distance; } public double GetDistance(int start, int end) { return CalculateDistance(start, end); } public double GetDistanceToDepot(int vehicle) { return CalculateDistance(vehicle, vehicle); } public void ResetDistanceMatrix() { UseDistanceMatrixParameter.Value = new BoolValue(false); DistanceMatrixParameter.Value = null; UseDistanceMatrixParameter.Value = new BoolValue(true); } public void Initialize() { PickupViolationPenalty.Value = scenario.PickupViolationPenaltyParameter.Value.Value; OverloadPenalty.Value = scenario.OverloadPenaltyParameter.Value.Value; TardinessPenalty.Value = scenario.TardinessPenaltyParameter.Value.Value; FleetUsageFactor.Value = scenario.FleetUsageFactorParameter.Value.Value; DistanceFactor.Value = scenario.DistanceFactorParameter.Value.Value; } } }