namespace OpenTraffic.Model.Simulator.RouteAssigner { using System; using System.Collections.Generic; using System.Text; using OpenTraffic.Model.Route; [Serializable] public abstract class ProbabilityRouteAssigner : TrafficRouteAssigner { protected ProbabilityRouteAssigner() { } protected abstract double GetGains(Vehicle v, Dictionary gains); protected override void FillInRoute(Vehicle v) { if (v != null) { // XXX Dictionary gains = new Dictionary(); double totGain = GetGains(v, gains); double p = (double)rand.NextDouble() * totGain; foreach (KeyValuePair gain in gains) { p -= gain.Value; if (p <= 0) { // xxx *** This is not okay *** v.trafficRoute = gain.Key; break; } } } } } }