using HeuristicLab.Problems.RoutePlanning.Data.Core; using HeuristicLab.Problems.RoutePlanning.Interfaces; using HeuristicLab.Problems.RoutePlanning.Utilities; namespace HeuristicLab.Problems.RoutePlanning.RoutingGraph { public class TravelTimeCostCalculator : ICostCalculator { #region CostCalculator Members public float Costs(Edge edge) { //double distance = Utils.Distance(edge.Source.Logitude, edge.Source.Latitude, // edge.Target.Logitude, edge.Target.Latitude); //double distance = Utils.LocationDistance(source.Node.Point, target.Node.Point); //int speed = edge.GetMaxSpeed(); //double weight = (distance / speed) * 3.6; //double weight = (distance / speed); //return (float)1; return edge.Weight; } public float CalculateCosts(Vertex source, Vertex destination, HighwayType category) { double distanceKms = Utils.Distance(source.Logitude, source.Latitude, destination.Logitude, destination.Latitude); int speedKmH = GetMaxSpeed(category); double weight = (distanceKms / speedKmH) * 60; return (float)weight; } public float EstimatedCosts(Vertex source, Vertex destination) { //double distance = Utils.Distance(source.Logitude, source.Latitude, // destination.Logitude, destination.Latitude); //double distance = Utils.LocationDistance(source.Node.Point, target.Node.Point); int speedKmH = 130; //double costs = (distance / speed) * 3.6; //double costs = (distance / speed); //return (float)costs; double distanceKms = Utils.Distance(source.Logitude, source.Latitude, destination.Logitude, destination.Latitude); double weight = (distanceKms / speedKmH) * 60; return (float)weight; } private int GetMaxSpeed(short category) { int speed = 0; //TODO: switch (category) { case 23: case 17: case 18: case 22: case 21: case 24: case 16: case 20: case 15: case 12: case 0: speed = 1; break; case 11: case 14: speed = 15; break; case 19: speed = 30; break; case 9: case 10: case 7: case 8: speed = 80; break; case 13: speed = 50; break; case 3: case 4: case 5: case 6: speed = 100; break; case 1: case 2: speed = 130; break; default: speed = 1; break; } return speed; } public int GetMaxSpeed(HighwayType ht) { int speed = 0; //TODO: switch (ht) { case HighwayType.bridleway: case HighwayType.bus_guideway: case HighwayType.raceway: case HighwayType.cycleway: case HighwayType.footway: case HighwayType.steps: case HighwayType.null_type: speed = 1; break; case HighwayType.path: case HighwayType.service: case HighwayType.pedestrian: case HighwayType.living_street: speed = 15; break; case HighwayType.road: case HighwayType.track: speed = 30; break; case HighwayType.tertiary: case HighwayType.tertiary_link: case HighwayType.secondary: case HighwayType.secondary_link: speed = 80; break; case HighwayType.unclassified: case HighwayType.residential: speed = 50; break; case HighwayType.trunk: case HighwayType.trunk_link: case HighwayType.primary: case HighwayType.primary_link: speed = 100; break; case HighwayType.motorway: case HighwayType.motorway_link: speed = 130; break; default: speed = 1; break; } return speed; } #endregion } }