#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.Data; using HeuristicLab.PDPSimulation.DomainModel; namespace HeuristicLab.PDPSimulation { [Item("PickupDeliveryVisualization", "Represents an PDP scenario visualization.")] [StorableClass] public class PickupDeliveryVisualization : Item { [Storable] private List orders; public IEnumerable Orders { get { return orders; } } [Storable] private double orderRangeX; public double OrderRangeX { get { return orderRangeX; } } [Storable] private double orderRangeY; public double OrderRangeY { get { return orderRangeY; } } [Storable] private List vehicles; public IEnumerable Vehicles { get { return vehicles; } } [Storable] private Dictionary actions; public PDAction GetAction(Vehicle vehicle) { if (actions.ContainsKey(vehicle)) return actions[vehicle]; else return null; } public void SetState(PickupDeliverySimulation simulation) { orders = new List(); foreach (Order order in simulation.Orders) { orders.Add(order.Clone() as Order); } orderRangeX = simulation.OrderRangeX; orderRangeY = simulation.OrderRangeY; vehicles = new List(); actions = new Dictionary(); foreach (Vehicle vehicle in simulation.Vehicles) { Vehicle clone = vehicle.Clone() as Vehicle; vehicles.Add(clone); PDAction action = simulation.GetAction(vehicle); if (action != null) actions[clone] = action.Clone() as PDAction; } } public PickupDeliveryVisualization(PickupDeliverySimulation simulation) : base() { SetState(simulation); } [StorableConstructor] protected PickupDeliveryVisualization(bool deserializing) : base(deserializing) { } protected PickupDeliveryVisualization(PickupDeliveryVisualization original, Cloner cloner) : base(original, cloner) { orders = new List(); foreach (Order order in original.orders) { orders.Add(order.Clone() as Order); } orderRangeX = original.orderRangeX; orderRangeY = original.orderRangeY; vehicles = new List(); actions = new Dictionary(); foreach (Vehicle vehicle in original.vehicles) { Vehicle clone = vehicle.Clone() as Vehicle; vehicles.Add(clone); PDAction action = original.GetAction(vehicle); if (action != null) actions[clone] = action.Clone() as PDAction; } } public override IDeepCloneable Clone(Cloner cloner) { return new PickupDeliveryVisualization(this, cloner); } public event EventHandler ContentChanged; private void OnContentChanged() { var changed = ContentChanged; if (changed != null) changed(this, EventArgs.Empty); } public void Refresh() { OnContentChanged(); } } }