namespace OpenTraffic.Model.Simulator.RouteAssigner { using System; using System.Collections.Generic; using System.Text; using OpenTraffic.Model.Route; [Serializable] public class Logit : ProbabilityRouteAssigner { private float factor = -1; private bool normalize = true; public Logit(float factor, bool normalize) { this.factor = factor; this.normalize = normalize; } public override Object Clone() { return new Logit(factor, normalize); } protected override double GetGains(Vehicle v, Dictionary gains) { double totGain = 0; if (v != null && gains != null) { List routes = RoutesLookup[v.Origin][v.Destination]; gains.Clear(); double factor1 = this.factor; double minCost = float.PositiveInfinity; Dictionary tgains = new Dictionary(); for (int i = 0; i < routes.Count; i++) { foreach (TrafficRoute r in routes[i].Routes) { if (r != null) { double cost = v.routeClass.CalculateCost(r, inResult, v.StartTime); tgains.Add(r, cost); minCost = Math.Min(minCost, cost); } } } if (normalize) factor1 = factor1 / minCost; foreach (KeyValuePair kv in tgains) { double utility = factor1 * kv.Value; if (utility != 0) { double gain = Math.Exp(utility); if (gain > 0) // The same as gain!=0 because of gain is never negative. { totGain += gain; gains.Add(kv.Key, gain); } } } } return totGain; } public override string ToString() { return "Logit(" + this.factor + ", " + this.normalize + ")"; } } }