/* * Copyright (c) 2005-2006 Erik Tigerholm * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ namespace OpenTraffic.Model { using System; using System.Xml.Serialization; using OpenTraffic.Model.Route; [Serializable] public class VehicleClass { #region XMLExport [XmlAttribute(AttributeName = "Id")] public int IdRegister { get { return Id; } set { Importer.Lookup.Get().Add(value, this); this.Id = value; } } [XmlElement(ElementName = "Name")] public string Name { get; set; } [XmlAttribute(AttributeName = "Pcu")] public float Pcu { get; set; } [XmlAttribute(AttributeName = "SpeedFactor")] public float SpeedFactor { get; set; } [XmlAttribute(AttributeName = "Headway")] public float Headway { get; set; } [XmlAttribute(AttributeName = "CostPerTime")] public float CostPerTime { get; set; } [XmlAttribute(AttributeName = "CostPerDistance")] public float CostPerDistance { get; set; } #endregion XMLExport /* =========== Ignored XML Elements =========== */ #region XmlIgnore [XmlIgnore] private int Id; // { get; private set; } #endregion XmlIgnore public VehicleClass() { } public VehicleClass(string Name) { this.Name = Name; } public VehicleClass( int id, float pcu, float speedFactor, float headway, string name, float costPerTime, float costPerDistance) { Id = id; Pcu = pcu; SpeedFactor = speedFactor; Headway = headway; Name = name; CostPerTime = costPerTime; CostPerDistance = costPerDistance; } public float CalculateCost(float time, float distance) { return CostPerTime * time + CostPerDistance * distance; } public float CalculateCost(TrafficModelLink l, Result.ResultData res, float t) { if (l != null) { return CalculateCost(l.GetObservedTotalTravelTime(t, this, res), l.Length); } return float.MaxValue; } public float CalculateCost(TrafficRoute r, Result.ResultData res, float t) { if (r != null) { return CalculateCost(r.GetObservedTotalTravelTime(t, this, res), r.Length); } return float.MaxValue; } public override string ToString() { return Name; } } }