/* * 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.Collections.Generic; using System.Text; using System.Xml.Serialization; using OpenTraffic.Model.Route; [Serializable] public class Vehicle { public static int lastId { get; set; } public TrafficZone Origin { get; private set; } public TrafficZone Destination { get; private set; } public float StartTime { get; private set; } public float StopTime { get; set; } public TrafficRoute trafficRoute { get; set; } public int RoutePos { get; set; } public int LinkPos { get; set; } public float LastTimePassedNode { get; set; } public int LastBinPassedNode { get; set; } public int Id { get; private set; } public VehicleClass routeClass { get; private set; } private TrafficModelLink activelink; private TrafficModelLink nextLink; public Vehicle(TrafficZone origin, TrafficZone destination, float starttime, TrafficRoute route, VehicleClass c) { routeClass = c; Origin = origin; Destination = destination; StartTime = starttime; trafficRoute = route; RoutePos = 0; lastId = 0; LastTimePassedNode = 0; LastBinPassedNode = -1; Id = lastId++; } [XmlIgnore] public ODPair ODPair { get { return new ODPair(Origin, Destination, routeClass); } } public void MoveToNextLink() { if (nextLink != null) { activelink = nextLink; nextLink = null; } else { activelink = null; } RoutePos++; } public TrafficModelLink GetLink() { if (activelink != null) return activelink; return GetLink(RoutePos); } private TrafficModelLink GetLink(int i) { return trafficRoute.GetLink(i); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public void ChooseNextLink() { return; /* Link activeLink = GetLink(); Link routeNextLink = GetLink(RoutePos + 1); Link route2NextLink = GetLink(RoutePos + 2); if (routeNextLink == null) return; float min = float.PositiveInfinity; foreach (Turning t in activeLink.Turnings) { Link l = t.Destination; if (l.Target == routeNextLink.Target) { foreach (Turning t2 in l.Turnings) { if (t2.Destination == route2NextLink) { float density = l.Simulator.GetNumberOfVehicles() / (l.Length * l.Lanes); if (density < min) { min = density; nextLink = l; } break; } } } }*/ } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] public TrafficModelLink GetNextLink() { if (nextLink != null) return nextLink; return GetLink(RoutePos + 1); } public void Reset() { RoutePos = 0; LastTimePassedNode = 0.0f; nextLink = null; activelink = null; } } }