Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DynamicVehicleRouting/HeuristicLab.PDPSimulation/3.3/PickupDeliveryVisualization.cs @ 10394

Last change on this file since 10394 was 8670, checked in by svonolfe, 12 years ago

Added first version of the dynamic vehicle routing addon (#1955)

File size: 4.1 KB
Line 
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.Data;
30using HeuristicLab.PDPSimulation.DomainModel;
31
32namespace HeuristicLab.PDPSimulation {
33  [Item("PickupDeliveryVisualization", "Represents an PDP scenario visualization.")]
34  [StorableClass]
35  public class PickupDeliveryVisualization : Item {
36    [Storable]
37    private List<Order> orders;
38    public IEnumerable<Order> Orders {
39      get { return orders; }
40    }
41
42    [Storable]
43    private double orderRangeX;
44    public double OrderRangeX {
45      get { return orderRangeX; }
46    }
47
48    [Storable]
49    private double orderRangeY;
50    public double OrderRangeY {
51      get { return orderRangeY; }
52    }
53
54    [Storable]
55    private List<Vehicle> vehicles;
56    public IEnumerable<Vehicle> Vehicles {
57      get { return vehicles; }
58    }
59
60    [Storable]
61    private Dictionary<Vehicle, PDAction> actions;
62    public PDAction GetAction(Vehicle vehicle) {
63      if (actions.ContainsKey(vehicle))
64        return actions[vehicle];
65      else
66        return null;
67    }
68
69    public void SetState(PickupDeliverySimulation simulation) {
70      orders = new List<Order>();
71      foreach (Order order in simulation.Orders) {
72        orders.Add(order.Clone() as Order);
73      }
74
75      orderRangeX = simulation.OrderRangeX;
76      orderRangeY = simulation.OrderRangeY;
77
78      vehicles = new List<Vehicle>();
79      actions = new Dictionary<Vehicle, PDAction>();
80      foreach (Vehicle vehicle in simulation.Vehicles) {
81        Vehicle clone = vehicle.Clone() as Vehicle;
82        vehicles.Add(clone);
83        PDAction action = simulation.GetAction(vehicle);
84        if (action != null)
85          actions[clone] = action.Clone() as PDAction;
86      }
87    }
88
89    public PickupDeliveryVisualization(PickupDeliverySimulation simulation)
90      : base() {
91      SetState(simulation);     
92    }
93
94    [StorableConstructor]
95    protected PickupDeliveryVisualization(bool deserializing) : base(deserializing) { }
96    protected PickupDeliveryVisualization(PickupDeliveryVisualization original, Cloner cloner)
97      : base(original, cloner) {
98      orders = new List<Order>();
99      foreach (Order order in original.orders) {
100        orders.Add(order.Clone() as Order);
101      }
102
103      orderRangeX = original.orderRangeX;
104      orderRangeY = original.orderRangeY;
105
106      vehicles = new List<Vehicle>();
107      actions = new Dictionary<Vehicle, PDAction>();
108      foreach (Vehicle vehicle in original.vehicles) {
109        Vehicle clone = vehicle.Clone() as Vehicle;
110        vehicles.Add(clone);
111        PDAction action = original.GetAction(vehicle);
112        if (action != null)
113          actions[clone] = action.Clone() as PDAction;
114      }   
115    }
116    public override IDeepCloneable Clone(Cloner cloner) {
117      return new PickupDeliveryVisualization(this, cloner);
118    }
119
120    public event EventHandler ContentChanged;
121    private void OnContentChanged() {
122      var changed = ContentChanged;
123      if (changed != null)
124        changed(this, EventArgs.Empty);
125    }
126
127    public void Refresh() {
128      OnContentChanged();
129    }
130  }
131}
132
Note: See TracBrowser for help on using the repository browser.