Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DynamicVehicleRouting/HeuristicLab.PDPSimulation/3.3/OrderGenerators/PickupDeliveryPredefinedOrderGenerator.cs @ 15728

Last change on this file since 15728 was 8824, checked in by svonolfe, 12 years ago

Fixed issue with order generator (#1955)

File size: 5.7 KB
RevLine 
[8670]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Core;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.Common;
29using HeuristicLab.Parameters;
30using HeuristicLab.Data;
31using HeuristicLab.PDPSimulation.DomainModel;
32
33namespace HeuristicLab.PDPSimulation {
34  [Item("PickupDeliveryPredefinedOrderGenerator", "A pickup and delivery order generator.")]
35  [StorableClass]
36  public sealed class PickupDeliveryPredefinedOrderGenerator: PickupDeliveryOrderGenerator {
37    public ValueParameter<IntValue> OrderRangeXParameter {
38      get { return (ValueParameter<IntValue>)Parameters["OrderRangeX"]; }
39    }
40
41    public ValueParameter<IntValue> OrderRangeYParameter {
42      get { return (ValueParameter<IntValue>)Parameters["OrderRangeY"]; }
43    }
44   
45    public ValueParameter<DoubleMatrix> OrdersParameter {
46      get { return (ValueParameter<DoubleMatrix>)Parameters["Orders"]; }
47    }
48
49    public OptionalValueParameter<StringArray> OrderNamesParameter {
50      get { return (OptionalValueParameter<StringArray>)Parameters["OrderNames"]; }
51    }
52   
53    public PickupDeliveryPredefinedOrderGenerator() : base() {
54      Parameters.Add(new ValueParameter<DoubleMatrix>("Orders", new DoubleMatrix()));
55      Parameters.Add(new OptionalValueParameter<StringArray>("OrderNames"));
56      Parameters.Add(new ValueParameter<IntValue>("OrderRangeX", new IntValue(0)));
57      Parameters.Add(new ValueParameter<IntValue>("OrderRangeY", new IntValue(0)));
58
59      OrdersParameter.GetsCollected = false;
60    }
61    [StorableConstructor]
62    private PickupDeliveryPredefinedOrderGenerator(bool deserializing) : base(deserializing) { }
63    private PickupDeliveryPredefinedOrderGenerator(PickupDeliveryPredefinedOrderGenerator original, Cloner cloner)
64      : base(original, cloner) {
65    }
66    public override IDeepCloneable Clone(Cloner cloner) {
67      return new PickupDeliveryPredefinedOrderGenerator(this, cloner);
68    }
69
70    public override double RangeX() {
71      double maxX = OrderRangeXParameter.Value.Value;
72
73      if (maxX == 0) {
74        DoubleMatrix orderMatrix = OrdersParameter.Value;
75
76        for (int i = 0; i < orderMatrix.Rows; i++) {
77          double pickupXCoord = orderMatrix[i, 1];
78          if (pickupXCoord > maxX)
79            maxX = pickupXCoord;
80
81          double deliveryXCoord = orderMatrix[i, 3];
82          if (deliveryXCoord > maxX)
83            maxX = deliveryXCoord;
84        }
85      }
86
87      return maxX;
88    }
89
90    public override double RangeY() {
91      double maxY = OrderRangeYParameter.Value.Value;
92
93      if (maxY == 0) {
94        DoubleMatrix orderMatrix = OrdersParameter.Value;
95
96        for (int i = 0; i < orderMatrix.Rows; i++) {
97          double pickupYCoord = orderMatrix[i, 2];
98          if (pickupYCoord > maxY)
99            maxY = pickupYCoord;
100
101          double deliveryYCoord = orderMatrix[i, 4];
102          if (deliveryYCoord > maxY)
103            maxY = deliveryYCoord;
104        }
105      }
106
107      return maxY;
108    }
109
110    public override bool MoreOrders(double time) {
111      bool moreOrders = false;
112     
113      DoubleMatrix orderMatrix = OrdersParameter.Value;
114       for (int i = 0; i < orderMatrix.Rows; i++) {
115         double revealedTime = orderMatrix[i, 0];
116
[8824]117         if (revealedTime > time) {
[8670]118           moreOrders = true;
119           break;
120         }
121       }
122
123       return moreOrders;
124    }
125
126    public override IEnumerable<Order> GetOrders(double timeStart, double timeEnd) {
127      List<Order> orders = new List<Order>();
128
129      DoubleMatrix orderMatrix = OrdersParameter.Value;
130      for (int i = 0; i < orderMatrix.Rows; i++) {
131        double revealedTime = orderMatrix[i, 0];
[8824]132        if ((timeStart == timeEnd && revealedTime == timeStart) || (revealedTime > timeStart && revealedTime <= timeEnd)) {
[8670]133          Order order = new Order();
134          order.OrderState = OrderState.Waiting;
135
136          order.Index = i;
137          order.PickupXCoord = orderMatrix[i, 1];
138          order.PickupYCoord = orderMatrix[i, 2];
139          order.DeliveryXCoord = orderMatrix[i, 3];
140          order.DeliveryYCoord = orderMatrix[i, 4];
141          order.Demand = orderMatrix[i, 5];
142          order.PickupServiceTime = orderMatrix[i, 6];
143          order.PickupReadyTime = orderMatrix[i, 7];
144          order.PickupDueTime = orderMatrix[i, 8];
145          order.DeliveryServiceTime = orderMatrix[i, 9];
146          order.DeliveryReadyTime = orderMatrix[i, 10];
147          order.DeliveryDueTime = orderMatrix[i, 11];
148
149          order.ServiceRequest = order.DeliveryDueTime < 0;
150
151          if (OrderNamesParameter.Value != null && i < OrderNamesParameter.Value.Length)
152            order.Name = OrderNamesParameter.Value[i];
153          else
154            order.Name = "Order" + i;
155
156          orders.Add(order);
157        }
158      }
159
160      return orders;
161    }
162  }
163}
Note: See TracBrowser for help on using the repository browser.