/// <summary> /// Calculates all interfering vehicles from registered vehicles. /// </summary> public List <CrossingVehicleTimes> CalculateInterferingVehicles(IVehicle v, NodeConnection nc) { Debug.Assert(nc == _aConnection || nc == _bConnection); // hopefully these are references... ;) List <CrossingVehicleTimes> toReturn = new List <CrossingVehicleTimes>(); Dictionary <IVehicle, CrossingVehicleTimes> myCrossingVehicles = (nc == _aConnection ? aCrossingVehicles : bCrossingVehicles); Dictionary <IVehicle, CrossingVehicleTimes> otherCrossingVehicles = (nc == _aConnection ? bCrossingVehicles : aCrossingVehicles); CrossingVehicleTimes myCvt = myCrossingVehicles[v]; if (_aConnection.startNode != _bConnection.startNode || (_frontWaitingDistance < aArcPosition && _frontWaitingDistance < bArcPosition)) { // check each vehicle in aCrossingVehicles with each in bCrossingVehicles for interference foreach (KeyValuePair <IVehicle, CrossingVehicleTimes> ocv in otherCrossingVehicles) { if ((!ocv.Value.willWaitInFrontOfIntersection || ocv.Value.remainingDistance < 0) && myCvt.blockingTime.IntersectsTrue(ocv.Value.blockingTime)) { toReturn.Add(ocv.Value); } } } return(toReturn); }
/// <summary> /// Updates the already registered vehicle v crossing on nc. /// </summary> /// <param name="v">Vehicle to update (must already be registered!).</param> /// <param name="nc">NodeConnection the vehicle is going to use (must participate on this Intersection!).</param> /// <param name="distance">Current distance of the vehicle to the Intersection</param> /// <param name="currentTime">current world time.</param> public void UpdateVehicle(IVehicle v, NodeConnection nc, double distance, double currentTime) { Debug.Assert(nc == _aConnection || nc == _bConnection); // TODO: add some safety space before and behind double blockingStartTime = currentTime + CalculateArrivingTime(v, distance - (_frontWaitingDistance / 2)) - v.SafetyTime / 8; double blockingEndTime = currentTime + CalculateArrivingTime(v, distance + v.length) + v.SafetyTime / 8; if (nc == _aConnection) { Debug.Assert(aCrossingVehicles.ContainsKey(v)); CrossingVehicleTimes cvt = aCrossingVehicles[v]; // CrossingVehicleTimes is a Value-Type! cvt.remainingDistance = distance; cvt.blockingTime.left = blockingStartTime; cvt.blockingTime.right = blockingEndTime; aCrossingVehicles[v] = cvt; } else { Debug.Assert(bCrossingVehicles.ContainsKey(v)); CrossingVehicleTimes cvt = bCrossingVehicles[v]; // CrossingVehicleTimes is a Value-Type! cvt.remainingDistance = distance; cvt.blockingTime.left = blockingStartTime; cvt.blockingTime.right = blockingEndTime; bCrossingVehicles[v] = cvt; } }
/// <summary> /// Updates the already registered vehicle v crossing on nc. /// </summary> /// <param name="v">Vehicle to update (must already be registered!).</param> /// <param name="nc">NodeConnection the vehicle is going to use (must participate on this Intersection!).</param> /// <param name="willWaitInFrontOfIntersection">Set true if vehicle will wait before intersection (and thus not cross it in the meantime).</param> public void UpdateVehicle(IVehicle v, NodeConnection nc, bool willWaitInFrontOfIntersection) { Debug.Assert(nc == _aConnection || nc == _bConnection); if (nc == _aConnection) { Debug.Assert(aCrossingVehicles.ContainsKey(v)); CrossingVehicleTimes cvt = aCrossingVehicles[v]; // CrossingVehicleTimes is a Value-Type! cvt.willWaitInFrontOfIntersection = willWaitInFrontOfIntersection; aCrossingVehicles[v] = cvt; } else { Debug.Assert(bCrossingVehicles.ContainsKey(v)); CrossingVehicleTimes cvt = bCrossingVehicles[v]; // CrossingVehicleTimes is a Value-Type! cvt.willWaitInFrontOfIntersection = willWaitInFrontOfIntersection; bCrossingVehicles[v] = cvt; } }