#region License Information /* HeuristicLab * Copyright (C) 2002-2011 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.Core; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Common; using HeuristicLab.Parameters; using HeuristicLab.Data; using HeuristicLab.PDPSimulation.DomainModel; namespace HeuristicLab.PDPSimulation { [Item("PickupDeliveryPredefinedOrderGenerator", "A pickup and delivery order generator.")] [StorableClass] public sealed class PickupDeliveryPredefinedOrderGenerator: PickupDeliveryOrderGenerator { public ValueParameter OrderRangeXParameter { get { return (ValueParameter)Parameters["OrderRangeX"]; } } public ValueParameter OrderRangeYParameter { get { return (ValueParameter)Parameters["OrderRangeY"]; } } public ValueParameter OrdersParameter { get { return (ValueParameter)Parameters["Orders"]; } } public OptionalValueParameter OrderNamesParameter { get { return (OptionalValueParameter)Parameters["OrderNames"]; } } public PickupDeliveryPredefinedOrderGenerator() : base() { Parameters.Add(new ValueParameter("Orders", new DoubleMatrix())); Parameters.Add(new OptionalValueParameter("OrderNames")); Parameters.Add(new ValueParameter("OrderRangeX", new IntValue(0))); Parameters.Add(new ValueParameter("OrderRangeY", new IntValue(0))); OrdersParameter.GetsCollected = false; } [StorableConstructor] private PickupDeliveryPredefinedOrderGenerator(bool deserializing) : base(deserializing) { } private PickupDeliveryPredefinedOrderGenerator(PickupDeliveryPredefinedOrderGenerator original, Cloner cloner) : base(original, cloner) { } public override IDeepCloneable Clone(Cloner cloner) { return new PickupDeliveryPredefinedOrderGenerator(this, cloner); } public override double RangeX() { double maxX = OrderRangeXParameter.Value.Value; if (maxX == 0) { DoubleMatrix orderMatrix = OrdersParameter.Value; for (int i = 0; i < orderMatrix.Rows; i++) { double pickupXCoord = orderMatrix[i, 1]; if (pickupXCoord > maxX) maxX = pickupXCoord; double deliveryXCoord = orderMatrix[i, 3]; if (deliveryXCoord > maxX) maxX = deliveryXCoord; } } return maxX; } public override double RangeY() { double maxY = OrderRangeYParameter.Value.Value; if (maxY == 0) { DoubleMatrix orderMatrix = OrdersParameter.Value; for (int i = 0; i < orderMatrix.Rows; i++) { double pickupYCoord = orderMatrix[i, 2]; if (pickupYCoord > maxY) maxY = pickupYCoord; double deliveryYCoord = orderMatrix[i, 4]; if (deliveryYCoord > maxY) maxY = deliveryYCoord; } } return maxY; } public override bool MoreOrders(double time) { bool moreOrders = false; DoubleMatrix orderMatrix = OrdersParameter.Value; for (int i = 0; i < orderMatrix.Rows; i++) { double revealedTime = orderMatrix[i, 0]; if (revealedTime > time) { moreOrders = true; break; } } return moreOrders; } public override IEnumerable GetOrders(double timeStart, double timeEnd) { List orders = new List(); DoubleMatrix orderMatrix = OrdersParameter.Value; for (int i = 0; i < orderMatrix.Rows; i++) { double revealedTime = orderMatrix[i, 0]; if ((timeStart == timeEnd && revealedTime == timeStart) || (revealedTime > timeStart && revealedTime <= timeEnd)) { Order order = new Order(); order.OrderState = OrderState.Waiting; order.Index = i; order.PickupXCoord = orderMatrix[i, 1]; order.PickupYCoord = orderMatrix[i, 2]; order.DeliveryXCoord = orderMatrix[i, 3]; order.DeliveryYCoord = orderMatrix[i, 4]; order.Demand = orderMatrix[i, 5]; order.PickupServiceTime = orderMatrix[i, 6]; order.PickupReadyTime = orderMatrix[i, 7]; order.PickupDueTime = orderMatrix[i, 8]; order.DeliveryServiceTime = orderMatrix[i, 9]; order.DeliveryReadyTime = orderMatrix[i, 10]; order.DeliveryDueTime = orderMatrix[i, 11]; order.ServiceRequest = order.DeliveryDueTime < 0; if (OrderNamesParameter.Value != null && i < OrderNamesParameter.Value.Length) order.Name = OrderNamesParameter.Value[i]; else order.Name = "Order" + i; orders.Add(order); } } return orders; } } }