/// <summary> /// Returns a new router. /// </summary> /// <param name="interpreter"></param> /// <param name="embeddedName"></param> /// <returns></returns> public override Router BuildRouter(IRoutingInterpreter interpreter, string embeddedName) { if (_data == null) { _data = new Dictionary <string, DynamicGraphRouterDataSource <CHEdgeData> >(); } DynamicGraphRouterDataSource <CHEdgeData> data = null; if (!_data.TryGetValue(embeddedName, out data)) { var tagsIndex = new SimpleTagsIndex(); // do the data processing. data = new DynamicGraphRouterDataSource <CHEdgeData>(tagsIndex); var targetData = new CHEdgeGraphOsmStreamWriter( data, interpreter, data.TagsIndex, Vehicle.Car); var dataProcessorSource = new XmlOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format( "OsmSharp.UnitTests.{0}", embeddedName))); var sorter = new OsmStreamFilterSort(); sorter.RegisterSource(dataProcessorSource); targetData.RegisterSource(sorter); targetData.Pull(); // do the pre-processing part. var preProcessor = new CHPreProcessor(data, new SparseOrdering(data), new DykstraWitnessCalculator(data)); preProcessor.Start(); _data[embeddedName] = data; } return(Router.CreateCHFrom(data, new CHRouter( data), interpreter)); }
/// <summary> /// Returns a new router. /// </summary> /// <param name="interpreter"></param> /// <param name="embedded_name"></param> /// <returns></returns> public override IRouter<RouterPoint> BuildRouter(IRoutingInterpreter interpreter, string embedded_name) { if (_data == null) { _data = new Dictionary<string, DynamicGraphRouterDataSource<CHEdgeData>>(); } DynamicGraphRouterDataSource<CHEdgeData> data = null; if (!_data.TryGetValue(embedded_name, out data)) { OsmTagsIndex tags_index = new OsmTagsIndex(); // do the data processing. data = new DynamicGraphRouterDataSource<CHEdgeData>(tags_index); CHEdgeDataGraphProcessingTarget target_data = new CHEdgeDataGraphProcessingTarget( data, interpreter, data.TagsIndex, VehicleEnum.Car); XmlDataProcessorSource data_processor_source = new XmlDataProcessorSource( Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format( "OsmSharp.UnitTests.{0}", embedded_name))); DataProcessorFilterSort sorter = new DataProcessorFilterSort(); sorter.RegisterSource(data_processor_source); target_data.RegisterSource(sorter); target_data.Pull(); // do the pre-processing part. CHPreProcessor pre_processor = new CHPreProcessor(data, new SparseOrdering(data), new DykstraWitnessCalculator(data)); pre_processor.Start(); _data[embedded_name] = data; } return new Router<CHEdgeData>(data, interpreter, new CHRouter( data)); }
/// <summary> /// Creates a CH data processing target. /// </summary> /// <param name="dynamicGraph"></param> /// <param name="interpreter"></param> /// <param name="tagsIndex"></param> /// <param name="vehicle"></param> public CHEdgeGraphOsmStreamWriter(IDynamicGraphRouterDataSource <CHEdgeData> dynamicGraph, IRoutingInterpreter interpreter, ITagsIndex tagsIndex, Vehicle vehicle) : base(dynamicGraph, interpreter, new CHEdgeDataComparer(), tagsIndex) { _vehicle = vehicle; _dynamicDataSource = dynamicGraph; }
/// <summary> /// Preprocesses the data from the given OsmStreamReader and converts it directly to a routable data source. /// </summary> /// <param name="reader"></param> /// <param name="tagsIndex"></param> /// <param name="interpreter"></param> /// <param name="vehicle"></param> /// <returns></returns> public static DynamicGraphRouterDataSource <CHEdgeData> Preprocess(OsmStreamSource reader, ITagsIndex tagsIndex, IRoutingInterpreter interpreter, Vehicle vehicle) { return(CHEdgeGraphOsmStreamWriter.Preprocess(reader, tagsIndex, interpreter, vehicle, false)); }
/// <summary> /// Creates a new osm edge data processing target. /// </summary> /// <param name="dynamicGraph"></param> /// <param name="interpreter"></param> /// <param name="tagsIndex"></param> /// <param name="idTransformations"></param> /// <param name="box"></param> public LiveGraphOsmStreamWriter(IDynamicGraphRouterDataSource <LiveEdge> dynamicGraph, IRoutingInterpreter interpreter, ITagsIndex tagsIndex, IDictionary <long, uint> idTransformations, GeoCoordinateBox box) : base(dynamicGraph, interpreter, null, tagsIndex, idTransformations, box) { _dynamicDataSource = dynamicGraph; }
/// <summary> /// Executes the CH contractions while verifying each step. /// </summary> /// <param name="stream"></param> public void DoTestCHEdgeDifferenceVerifiedContraction(Stream stream) { _interpreter = new OsmRoutingInterpreter(); OsmTagsIndex tags_index = new OsmTagsIndex(); // do the data processing. _data = new DynamicGraphRouterDataSource<CHEdgeData>(tags_index); CHEdgeDataGraphProcessingTarget target_data = new CHEdgeDataGraphProcessingTarget( _data, _interpreter, _data.TagsIndex, VehicleEnum.Car); XmlDataProcessorSource data_processor_source = new XmlDataProcessorSource(stream); DataProcessorFilterSort sorter = new DataProcessorFilterSort(); sorter.RegisterSource(data_processor_source); target_data.RegisterSource(sorter); target_data.Pull(); // do the pre-processing part. DykstraWitnessCalculator witness_calculator = new DykstraWitnessCalculator( _data); CHPreProcessor pre_processor = new CHPreProcessor(_data, new EdgeDifference(_data, witness_calculator), witness_calculator); pre_processor.OnBeforeContractionEvent += new CHPreProcessor.VertexDelegate(pre_processor_OnBeforeContractionEvent); pre_processor.OnAfterContractionEvent += new CHPreProcessor.VertexDelegate(pre_processor_OnAfterContractionEvent); pre_processor.Start(); }
/// <summary> /// Builds a router. /// </summary> /// <returns></returns> public override Router BuildRouter(IBasicRouterDataSource <LiveEdge> data, IRoutingInterpreter interpreter, IBasicRouter <LiveEdge> basicRouter) { // initialize the router. return(Router.CreateLiveFrom(data, basicRouter, interpreter)); }
/// <summary> /// Builds the data. /// </summary> /// <param name="interpreter"></param> /// <param name="embeddedString"></param> /// <returns></returns> public override IBasicRouterDataSource <CHEdgeData> BuildData(IRoutingInterpreter interpreter, string embeddedString) { var tagsIndex = new SimpleTagsIndex(); // do the data processing. var memoryData = new DynamicGraphRouterDataSource <CHEdgeData>(tagsIndex); var targetData = new CHEdgeGraphOsmStreamWriter( memoryData, interpreter, memoryData.TagsIndex, Vehicle.Car); var dataProcessorSource = new XmlOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedString)); var sorter = new OsmStreamFilterSort(); sorter.RegisterSource(dataProcessorSource); targetData.RegisterSource(sorter); targetData.Pull(); // do the pre-processing part. var preProcessor = new CHPreProcessor(memoryData, new SparseOrdering(memoryData), new DykstraWitnessCalculator(memoryData)); preProcessor.Start(); return(memoryData); }
/// <summary> /// Executes the CH contractions while verifying each step. /// </summary> /// <param name="stream"></param> public void DoTestCHSparseVerifiedContraction(Stream stream) { _interpreter = new OsmRoutingInterpreter(); var tagsIndex = new SimpleTagsIndex(); // do the data processing. _data = new DynamicGraphRouterDataSource <CHEdgeData>(tagsIndex); var targetData = new CHEdgeGraphOsmStreamWriter( _data, _interpreter, _data.TagsIndex, Vehicle.Car); var dataProcessorSource = new XmlOsmStreamSource(stream); var sorter = new OsmStreamFilterSort(); sorter.RegisterSource(dataProcessorSource); targetData.RegisterSource(sorter); targetData.Pull(); // do the pre-processing part. //INodeWitnessCalculator witness_calculator = new CHRouterWitnessCalculator(_data); INodeWitnessCalculator witnessCalculator = new DykstraWitnessCalculator(_data); var preProcessor = new CHPreProcessor(_data, new EdgeDifferenceContractedSearchSpace(_data, witnessCalculator), witnessCalculator); preProcessor.OnBeforeContractionEvent += new CHPreProcessor.VertexDelegate(pre_processor_OnBeforeContractionEvent); preProcessor.OnAfterContractionEvent += new CHPreProcessor.VertexDelegate(pre_processor_OnAfterContractionEvent); preProcessor.Start(); }
/// <summary> /// Generates instructions. /// </summary> /// <param name="route"></param> /// <param name="interpreter"></param> /// <param name="languageGenerator"></param> /// <returns></returns> public static List <Instruction> Generate(Route route, IRoutingInterpreter interpreter, ILanguageGenerator languageGenerator) { if (route == null) { throw new ArgumentNullException("route"); } if (route.Vehicle == null) { throw new InvalidOperationException("Vehicle not set on route: Cannot generate instruction for a route without a vehicle!"); } if (interpreter == null) { throw new ArgumentNullException("interpreter"); } if (languageGenerator == null) { throw new ArgumentNullException("languageGenerator"); } OsmSharp.Routing.ArcAggregation.ArcAggregator aggregator = new OsmSharp.Routing.ArcAggregation.ArcAggregator(interpreter); AggregatedPoint point = aggregator.Aggregate(route); return(InstructionGenerator.Generate(point, interpreter, languageGenerator)); }
/// <summary> /// Builds data source. /// </summary> /// <param name="interpreter"></param> /// <param name="embeddedString"></param> /// <returns></returns> public override IBasicRouterDataSource <LiveEdge> BuildData(IRoutingInterpreter interpreter, string embeddedString) { string key = string.Format("Dykstra.Routing.IBasicRouterDataSource<SimpleWeighedEdge>.OSM.{0}", embeddedString); var data = StaticDictionary.Get <IBasicRouterDataSource <LiveEdge> >( key); if (data == null) { var tagsIndex = new SimpleTagsIndex(); // do the data processing. var memoryData = new DynamicGraphRouterDataSource <LiveEdge>(tagsIndex); var targetData = new LiveGraphOsmStreamWriter(memoryData, interpreter, memoryData.TagsIndex); var dataProcessorSource = new XmlOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedString)); var sorter = new OsmStreamFilterSort(); sorter.RegisterSource(dataProcessorSource); targetData.RegisterSource(sorter); targetData.Pull(); data = memoryData; StaticDictionary.Add <IBasicRouterDataSource <LiveEdge> >(key, data); } return(data); }
/// <summary> /// Builds the data. /// </summary> /// <param name="interpreter"></param> /// <param name="embeddedString"></param> /// <returns></returns> public override IBasicRouterDataSource <CHEdgeData> BuildData(IRoutingInterpreter interpreter, string embeddedString) { string key = string.Format("CHEdgeDifference.Routing.IBasicRouterDataSource<CHEdgeData>.OSM.{0}", embeddedString); var data = StaticDictionary.Get <IBasicRouterDataSource <CHEdgeData> >( key); if (data == null) { var tagsIndex = new SimpleTagsIndex(); // do the data processing. var memoryData = new DynamicGraphRouterDataSource <CHEdgeData>(tagsIndex); var targetData = new CHEdgeGraphOsmStreamWriter( memoryData, interpreter, memoryData.TagsIndex, Vehicle.Car); var dataProcessorSource = new XmlOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedString)); var sorter = new OsmStreamFilterSort(); sorter.RegisterSource(dataProcessorSource); targetData.RegisterSource(sorter); targetData.Pull(); // do the pre-processing part. var witnessCalculator = new DykstraWitnessCalculator(memoryData); var preProcessor = new CHPreProcessor(memoryData, new EdgeDifference(memoryData, witnessCalculator), witnessCalculator); preProcessor.Start(); data = memoryData; StaticDictionary.Add <IBasicRouterDataSource <CHEdgeData> >(key, data); } return(data); }
/// <summary> /// Builds a raw router to compare against. /// </summary> /// <returns></returns> public IRouter<RouterPoint> BuildDykstraRouter(IBasicRouterDataSource<PreProcessedEdge> data, IRoutingInterpreter interpreter, IBasicRouter<PreProcessedEdge> basic_router) { // initialize the router. return new Router<PreProcessedEdge>( data, interpreter, basic_router); }
/// <summary> /// Preprocesses the data from the given OsmStreamReader and converts it directly to a routable data source. /// </summary> /// <param name="reader"></param> /// <param name="tagsIndex"></param> /// <param name="interpreter"></param> /// <param name="vehicle"></param> /// <param name="leaveReverseEdges"></param> /// <returns></returns> public static DynamicGraphRouterDataSource <CHEdgeData> Preprocess(OsmStreamSource reader, ITagsIndex tagsIndex, IRoutingInterpreter interpreter, Vehicle vehicle, bool leaveReverseEdges) { // pull in the data. var dynamicGraphRouterDataSource = new DynamicGraphRouterDataSource <CHEdgeData>(tagsIndex); var targetData = new CHEdgeGraphOsmStreamWriter( dynamicGraphRouterDataSource, interpreter, dynamicGraphRouterDataSource.TagsIndex, vehicle); targetData.RegisterSource(reader); targetData.Pull(); // compress the graph. INodeWitnessCalculator witnessCalculator = new DykstraWitnessCalculator(dynamicGraphRouterDataSource); var edgeDifference = new EdgeDifference( dynamicGraphRouterDataSource, witnessCalculator); var preProcessor = new CHPreProcessor( dynamicGraphRouterDataSource, edgeDifference, witnessCalculator); preProcessor.Start(); return(dynamicGraphRouterDataSource); }
/// <summary> /// Creates a router using interpreted edges. /// </summary> /// <param name="data">The data to route on.</param> /// <param name="interpreter">The routing interpreter.</param> /// <returns></returns> public static Router CreateFrom(IRoutingAlgorithmData <Edge> data, IRoutingInterpreter interpreter) { // creates the edge router. var typedRouter = new TypedRouterEdge( data, interpreter, new Dykstra()); return(new Router(typedRouter)); // create the actual router. }
/// <summary> /// Creates a router using live interpreted edges. /// </summary> /// <param name="data">The data to route on.</param> /// <param name="interpreter">The routing interpreter.</param> /// <returns></returns> public static Router CreateLiveFrom(IBasicRouterDataSource <LiveEdge> data, IRoutingInterpreter interpreter) { // creates the live edge router. var liveEdgeRouter = new TypedRouterLiveEdge( data, interpreter, new DykstraRoutingLive()); return(new Router(liveEdgeRouter)); // create the actual router. }
/// <summary> /// Generates instructions. /// </summary> /// <param name="route"></param> /// <param name="interpreter"></param> /// <param name="languageGenerator"></param> /// <returns></returns> public static List <Instruction> Generate(Route route, IRoutingInterpreter interpreter, ILanguageGenerator languageGenerator) { OsmSharp.Routing.ArcAggregation.ArcAggregator aggregator = new OsmSharp.Routing.ArcAggregation.ArcAggregator(interpreter); AggregatedPoint point = aggregator.Aggregate(route); return(InstructionGenerator.Generate(point, interpreter, languageGenerator)); }
/// <summary> /// Returns true if the given direction can be considered 'turning'. /// </summary> /// <param name="direction">The direction.</param> /// <param name="interpreter">The routing interpreter.</param> /// <returns></returns> public static bool IsTurn(RelativeDirectionEnum direction, IRoutingInterpreter interpreter) { switch (direction) { case RelativeDirectionEnum.StraightOn: return false; } return true; }
/// <summary> /// Generates instructions. /// </summary> /// <param name="route"></param> /// <param name="interpreter"></param> /// <param name="languageGenerator"></param> /// <returns></returns> public static List<Instruction> Generate(Route route, IRoutingInterpreter interpreter, ILanguageGenerator languageGenerator) { OsmSharp.Routing.ArcAggregation.ArcAggregator aggregator = new OsmSharp.Routing.ArcAggregation.ArcAggregator(interpreter); AggregatedPoint point = aggregator.Aggregate(route); return InstructionGenerator.Generate(point, interpreter, languageGenerator); }
/// <summary> /// Creates a new planner. /// </summary> public MicroPlanner(ILanguageGenerator language_generator, IRoutingInterpreter interpreter) { _interpreter = interpreter; this.InitializeMachines(); this.InitializeMessagesStack(); this.SentencePlanner = new SentencePlanner(language_generator); }
/// <summary> /// Creates a router using interpreted edges. /// </summary> /// <param name="data">The data to route on.</param> /// <param name="basicRouter">A custom routing implementation.</param> /// <param name="interpreter">The routing interpreter.</param> /// <returns></returns> public static Router CreateCHFrom(IRoutingAlgorithmData <CHEdgeData> data, IRoutingAlgorithm <CHEdgeData> basicRouter, IRoutingInterpreter interpreter) { // creates the edge router. var typedRouter = new TypedRouterCHEdge( data, interpreter, basicRouter); return(new Router(typedRouter)); // create the actual router. }
public static bool IsTurn(RelativeDirectionEnum direction, IRoutingInterpreter interpreter) { switch (direction) { case RelativeDirectionEnum.StraightOn: return(false); } return(true); }
/// <summary> /// Creates a router using live interpreted edges. /// </summary> /// <param name="data">The data to route on.</param> /// <param name="basicRouter">A custom routing implementation.</param> /// <param name="interpreter">The routing interpreter.</param> /// <returns></returns> public static Router CreateCHFrom(IBasicRouterDataSource <CHEdgeData> data, IBasicRouter <CHEdgeData> basicRouter, IRoutingInterpreter interpreter) { // creates the live edge router. var liveEdgeRouter = new TypedRouterCHEdge( data, interpreter, basicRouter); return(new Router(liveEdgeRouter)); // create the actual router. }
/// <summary> /// Builds the edge difference. /// </summary> private EdgeDifference BuildEdgeDifference(IRoutingInterpreter interpreter) { DynamicGraphRouterDataSource <CHEdgeData> data = this.BuildData(interpreter); // do the pre-processing part. INodeWitnessCalculator witnessCalculator = new DykstraWitnessCalculator(data); return(new EdgeDifference( data, witnessCalculator)); }
/// <summary> /// Creates a new planner. /// </summary> public MicroPlanner(ILanguageGenerator languageGenerator, IRoutingInterpreter interpreter) { _interpreter = interpreter; _machines = new List<MicroPlannerMachine>(); this.InitializeMachines(_machines); this.InitializeMessagesStack(); this.SentencePlanner = new SentencePlanner(languageGenerator); }
public static bool IsRight(RelativeDirectionEnum direction, IRoutingInterpreter interpreter) { switch (direction) { case RelativeDirectionEnum.Right: case RelativeDirectionEnum.SharpRight: case RelativeDirectionEnum.SlightlyRight: return(true); } return(false); }
/// <summary> /// Returns true if the given direction can be considered 'right'. /// </summary> /// <param name="direction">The direction.</param> /// <param name="interpreter">The routing interpreter.</param> /// <returns></returns> public static bool IsRight(RelativeDirectionEnum direction, IRoutingInterpreter interpreter) { switch (direction) { case RelativeDirectionEnum.Right: case RelativeDirectionEnum.SharpRight: case RelativeDirectionEnum.SlightlyRight: return true; } return false; }
/// <summary> /// Generates instructions. /// </summary> /// <param name="route"></param> /// <param name="interpreter"></param> /// <param name="languageGenerator"></param> /// <returns></returns> public static List<Instruction> Generate(Route route, IRoutingInterpreter interpreter, ILanguageGenerator languageGenerator) { if (route == null) { throw new ArgumentNullException("route"); } if (route.Vehicle == null) { throw new InvalidOperationException("Vehicle not set on route: Cannot generate instruction for a route without a vehicle!"); } if (interpreter == null) { throw new ArgumentNullException("interpreter"); } if (languageGenerator == null) { throw new ArgumentNullException("languageGenerator"); } var aggregator = new ArcAggregator(interpreter); var point = aggregator.Aggregate(route); return InstructionGenerator.Generate(route, point, interpreter, languageGenerator); }
/// <summary> /// Calculates the shortest path from the given vertex to the given vertex given the weights in the graph. /// </summary> /// <param name="vehicle"></param> /// <param name="from"></param> /// <param name="to"></param> /// <param name="graph"></param> /// <param name="interpreter"></param> /// <param name="max"></param> /// <returns></returns> public double CalculateWeight(IBasicRouterDataSource <LiveEdge> graph, IRoutingInterpreter interpreter, Vehicle vehicle, PathSegmentVisitList from, PathSegmentVisitList to, double max) { PathSegment <long> closest = this.CalculateToClosest(graph, interpreter, vehicle, from, new PathSegmentVisitList[] { to }, max); if (closest != null) { return(closest.Weight); } return(double.MaxValue); }
/// <summary> /// Calculates the shortest path from the given vertex to the given vertex given the weights in the graph. /// </summary> /// <param name="vehicle"></param> /// <param name="from"></param> /// <param name="to"></param> /// <param name="graph"></param> /// <param name="interpreter"></param> /// <param name="max"></param> /// <param name="parameters"></param> /// <returns></returns> public double CalculateWeight(IRoutingAlgorithmData <Edge> graph, IRoutingInterpreter interpreter, Vehicle vehicle, PathSegmentVisitList from, PathSegmentVisitList to, double max, Dictionary <string, object> parameters) { PathSegment <long> closest = this.CalculateToClosest(graph, interpreter, vehicle, from, new PathSegmentVisitList[] { to }, max, null); if (closest != null) { return(closest.Weight); } return(double.MaxValue); }
/// <summary> /// Preprocesses the data from the given OsmStreamReader and converts it directly to a routable data source. /// </summary> /// <param name="reader"></param> /// <param name="tagsIndex"></param> /// <param name="interpreter"></param> /// <returns></returns> public static DynamicGraphRouterDataSource <LiveEdge> Preprocess(OsmStreamSource reader, ITagsIndex tagsIndex, IRoutingInterpreter interpreter) { var dynamicGraphRouterDataSource = new DynamicGraphRouterDataSource <LiveEdge>(tagsIndex); var targetData = new LiveGraphOsmStreamWriter(dynamicGraphRouterDataSource, interpreter, dynamicGraphRouterDataSource.TagsIndex); targetData.RegisterSource(reader); targetData.Pull(); return(dynamicGraphRouterDataSource); }
public static int GetRight(IList<MicroPlannerMessage> messages, IRoutingInterpreter interpreter) { int right = 0; foreach (MicroPlannerMessage message in messages) { if (message is MicroPlannerMessagePoint) { MicroPlannerMessagePoint point = (message as MicroPlannerMessagePoint); right = right + MicroPlannerHelper.GetRight(point, interpreter); } } return right; }
/// <summary> /// Calculates the shortest path from the given vertex to the given vertex given the weights in the graph. /// </summary> /// <param name="graph"></param> /// <param name="from"></param> /// <param name="to"></param> /// <param name="interpreter"></param> /// <param name="vehicle"></param> /// <returns></returns> public PathSegment <long> Calculate(IRoutingAlgorithmData <Edge> graph, IRoutingInterpreter interpreter, Vehicle vehicle, uint from, uint to) { var source = new PathSegmentVisitList(); source.UpdateVertex(new PathSegment <long>(from)); var target = new PathSegmentVisitList(); target.UpdateVertex(new PathSegment <long>(to)); // do the basic CH calculations. return(this.Calculate(graph, interpreter, vehicle, source, target, float.MaxValue, null)); }
/// <summary> /// Calculates all points that are at or close to the given weight. /// </summary> /// <param name="graph"></param> /// <param name="interpreter"></param> /// <param name="vehicle"></param> /// <param name="source"></param> /// <param name="weight"></param> /// <param name="forward"></param> /// <param name="parameters"></param> /// <returns></returns> public HashSet <long> CalculateRange(IRoutingAlgorithmData <Edge> graph, IRoutingInterpreter interpreter, Vehicle vehicle, PathSegmentVisitList source, double weight, bool forward, Dictionary <string, object> parameters) { PathSegment <long>[] result = this.DoCalculation(graph, interpreter, vehicle, source, new PathSegmentVisitList[0], weight, false, true, forward, parameters); var resultVertices = new HashSet <long>(); for (int idx = 0; idx < result.Length; idx++) { resultVertices.Add(result[idx].VertexId); } return(resultVertices); }
/// <summary> /// Calculates all points that are at or close to the given weight. /// </summary> /// <param name="graph"></param> /// <param name="interpreter"></param> /// <param name="vehicle"></param> /// <param name="source"></param> /// <param name="weight"></param> /// <param name="forward"></param> /// <returns></returns> public HashSet <long> CalculateRange(IDynamicGraphReadOnly <LiveEdge> graph, IRoutingInterpreter interpreter, Vehicle vehicle, PathSegmentVisitList source, double weight, bool forward) { PathSegment <long>[] result = this.DoCalculation(graph, interpreter, vehicle, source, new PathSegmentVisitList[0], weight, false, true, forward); var resultVertices = new HashSet <long>(); for (int idx = 0; idx < result.Length; idx++) { resultVertices.Add(result[idx].VertexId); } return(resultVertices); }
public static int GetLeft(IList <MicroPlannerMessage> messages, IRoutingInterpreter interpreter) { int left = 0; foreach (MicroPlannerMessage message in messages) { if (message is MicroPlannerMessagePoint) { MicroPlannerMessagePoint point = (message as MicroPlannerMessagePoint); left = left + MicroPlannerHelper.GetLeft(point, interpreter); } } return(left); }
public static int GetStraightOn(IList <MicroPlannerMessage> messages, IRoutingInterpreter interpreter) { int straight = 0; foreach (MicroPlannerMessage message in messages) { if (message is MicroPlannerMessagePoint) { MicroPlannerMessagePoint point = (message as MicroPlannerMessagePoint); straight = straight + MicroPlannerHelper.GetStraightOn(point, interpreter); } } return(straight); }
/// <summary> /// Returns true if the search can move beyond the given weight. /// </summary> /// <param name="graph"></param> /// <param name="interpreter"></param> /// <param name="vehicle"></param> /// <param name="source"></param> /// <param name="weight"></param> /// <param name="parameters"></param> /// <returns></returns> public bool CheckConnectivity(IRoutingAlgorithmData <Edge> graph, IRoutingInterpreter interpreter, Vehicle vehicle, PathSegmentVisitList source, double weight, Dictionary <string, object> parameters) { HashSet <long> range = this.CalculateRange(graph, interpreter, vehicle, source, weight, true, null); if (range.Count > 0) { range = this.CalculateRange(graph, interpreter, vehicle, source, weight, false, null); if (range.Count > 0) { return(true); } } return(false); }
/// <summary> /// Returns true if the search can move beyond the given weight. /// </summary> /// <param name="graph"></param> /// <param name="interpreter"></param> /// <param name="vehicle"></param> /// <param name="source"></param> /// <param name="weight"></param> /// <returns></returns> public bool CheckConnectivity(IBasicRouterDataSource <LiveEdge> graph, IRoutingInterpreter interpreter, Vehicle vehicle, PathSegmentVisitList source, double weight) { HashSet <long> range = this.CalculateRange(graph, interpreter, vehicle, source, weight, true); if (range.Count > 0) { range = this.CalculateRange(graph, interpreter, vehicle, source, weight, false); if (range.Count > 0) { return(true); } } return(false); }
public static int GetLeft(MicroPlannerMessagePoint point, IRoutingInterpreter interpreter) { int left = 0; if (point.Point.ArcsNotTaken != null) { foreach (KeyValuePair<RelativeDirection, AggregatedArc> arc_pair in point.Point.ArcsNotTaken) { if (MicroPlannerHelper.IsLeft(arc_pair.Key.Direction, interpreter)) { if (interpreter.EdgeInterpreter.IsRoutable(arc_pair.Value.Tags.ConvertToDictionary())) { left++; } } } } return left; }
public static int GetRight(MicroPlannerMessagePoint point, IRoutingInterpreter interpreter) { int right = 0; if (point.Point.ArcsNotTaken != null) { foreach (KeyValuePair<RelativeDirection, AggregatedArc> arc_pair in point.Point.ArcsNotTaken) { if (MicroPlannerHelper.IsRight(arc_pair.Key.Direction, interpreter)) { if (interpreter.EdgeInterpreter.IsRoutable(arc_pair.Value.Tags)) { right++; } } } } return right; }
/// <summary> /// Builds a raw data source. /// </summary> /// <returns></returns> public DynamicGraphRouterDataSource<PreProcessedEdge> BuildDykstraDataSource( IRoutingInterpreter interpreter, string embedded_name) { OsmTagsIndex tags_index = new OsmTagsIndex(); // do the data processing. DynamicGraphRouterDataSource<PreProcessedEdge> data = new DynamicGraphRouterDataSource<PreProcessedEdge>(tags_index); PreProcessedDataGraphProcessingTarget target_data = new PreProcessedDataGraphProcessingTarget( data, interpreter, data.TagsIndex, VehicleEnum.Car); XmlDataProcessorSource data_processor_source = new XmlDataProcessorSource( Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format( "OsmSharp.UnitTests.{0}", embedded_name))); DataProcessorFilterSort sorter = new DataProcessorFilterSort(); sorter.RegisterSource(data_processor_source); target_data.RegisterSource(sorter); target_data.Pull(); return data; }
/// <summary> /// Creates a router using live interpreted edges. /// </summary> /// <param name="data">The data to route on.</param> /// <param name="basicRouter">A custom routing implementation.</param> /// <param name="interpreter">The routing interpreter.</param> /// <returns></returns> public static Router CreateLiveFrom(IBasicRouterDataSource<LiveEdge> data, IRoutingAlgorithm<LiveEdge> basicRouter, IRoutingInterpreter interpreter) { // creates the live edge router. var liveEdgeRouter = new TypedRouterLiveEdge( data, interpreter, basicRouter); return new Router(liveEdgeRouter); // create the actual router. }
/// <summary> /// Creates a new microplanner. /// </summary> /// <param name="languageGenerator"></param> /// <param name="interpreter"></param> /// <returns></returns> public static MicroPlanner CreatePlanner(ILanguageGenerator languageGenerator, IRoutingInterpreter interpreter) { return new MicroPlanner(languageGenerator, interpreter); }
/// <summary> /// Creates a new TimeCalculator. /// </summary> /// <param name="interpreter"></param> public TimeCalculator(IRoutingInterpreter interpreter) :base(interpreter) { }
/// <summary> /// Builds the edge difference. /// </summary> private EdgeDifference BuildEdgeDifference(IRoutingInterpreter interpreter) { DynamicGraphRouterDataSource<CHEdgeData> data = this.BuildData(interpreter); // do the pre-processing part. INodeWitnessCalculator witness_calculator = new DykstraWitnessCalculator(data); return new EdgeDifference( data, witness_calculator); }
/// <summary> /// Builds the edge difference. /// </summary> private CHPreProcessor BuildCHPreProcessor(IRoutingInterpreter interpreter) { DynamicGraphRouterDataSource<CHEdgeData> data = this.BuildData(interpreter); // do the pre-processing part. INodeWitnessCalculator witness_calculator = new DykstraWitnessCalculator(data); EdgeDifference edge_difference = new EdgeDifference( data, witness_calculator); CHPreProcessor pre_processor = new CHPreProcessor( data, edge_difference, witness_calculator); return pre_processor; }
/// <summary> /// Creates a route tracker that tracks the given route and it's instructions. /// </summary> /// <param name="route"></param> /// <param name="interpreter"></param> /// <param name="languageGenerator"></param> public RouteTracker(Route route, IRoutingInterpreter interpreter, ILanguageGenerator languageGenerator) { _route = route; _instructions = InstructionGenerator.Generate(route, interpreter, languageGenerator); }
/// <summary> /// Creates a router using interpreted edges. /// </summary> /// <param name="data">The data to route on.</param> /// <param name="interpreter">The routing interpreter.</param> /// <returns></returns> public static Router CreateFrom(IRoutingAlgorithmData<Edge> data, IRoutingInterpreter interpreter) { // creates the edge router. var typedRouter = new TypedRouterEdge( data, interpreter, new Dykstra()); return new Router(typedRouter); // create the actual router. }
/// <summary> /// Generates instructions. /// </summary> /// <param name="route"></param> /// <param name="point"></param> /// <param name="interpreter"></param> /// <param name="languageGenerator"></param> /// <returns></returns> public static List<Instruction> Generate(Route route, AggregatedPoint point, IRoutingInterpreter interpreter, ILanguageGenerator languageGenerator) { if (point == null) { throw new ArgumentNullException("route"); } if (interpreter == null) { throw new ArgumentNullException("interpreter"); } if (languageGenerator == null) { throw new ArgumentNullException("languageGenerator"); } return InstructionGenerator.Generate(new MicroPlanner(languageGenerator, interpreter), route, point); }
/// <summary> /// Creates a router using live interpreted edges. /// </summary> /// <param name="data">The data to route on.</param> /// <param name="basicRouter">A custom routing implementation.</param> /// <param name="interpreter">The routing interpreter.</param> /// <returns></returns> public static Router CreateCHFrom(IBasicRouterDataSource<CHEdgeData> data, IBasicRouter<CHEdgeData> basicRouter, IRoutingInterpreter interpreter) { // creates the live edge router. var liveEdgeRouter = new TypedRouterCHEdge( data, interpreter, basicRouter); return new Router(liveEdgeRouter); // create the actual router. }
/// <summary> /// Generates instructions. /// </summary> /// <param name="point"></param> /// <param name="interpreter"></param> /// <param name="language_generator"></param> /// <returns></returns> public static List<Instruction> Generate(AggregatedPoint point, IRoutingInterpreter interpreter, ILanguageGenerator language_generator) { MicroPlanning.MicroPlanner planner = new MicroPlanning.MicroPlanner(language_generator, interpreter); return planner.Plan(point); }
/// <summary> /// Creates a new metrics calculator. /// </summary> /// <param name="interpreter"></param> protected OsmSharpRouteMetricCalculator(IRoutingInterpreter interpreter) { _interpreter = interpreter; }
/// <summary> /// Creates a router using live interpreted edges. /// </summary> /// <param name="data">The data to route on.</param> /// <param name="interpreter">The routing interpreter.</param> /// <returns></returns> public static Router CreateLiveFrom(IBasicRouterDataSource<LiveEdge> data, IRoutingInterpreter interpreter) { // creates the live edge router. var liveEdgeRouter = new TypedRouterLiveEdge( data, interpreter, new DykstraRoutingLive(data.TagsIndex)); return new Router(liveEdgeRouter); // create the actual router. }
/// <summary> /// Creates a router using interpreted edges. /// </summary> /// <param name="data">The data to route on.</param> /// <param name="basicRouter">A custom routing implementation.</param> /// <param name="interpreter">The routing interpreter.</param> /// <returns></returns> public static Router CreateCHFrom(IRoutingAlgorithmData<CHEdgeData> data, IRoutingAlgorithm<CHEdgeData> basicRouter, IRoutingInterpreter interpreter) { // creates the edge router. var typedRouter = new TypedRouterCHEdge( data, interpreter, basicRouter); return new Router(typedRouter); // create the actual router. }
/// <summary> /// Generates instructions. /// </summary> /// <param name="aggregatePoint"></param> /// <param name="interpreter"></param> /// <returns></returns> public static List<Instruction> Generate(AggregatedPoint aggregatePoint, IRoutingInterpreter interpreter) { return InstructionGenerator.Generate(aggregatePoint, interpreter, new OsmSharp.Routing.Instructions.LanguageGeneration.Defaults.SimpleEnglishLanguageGenerator()); }
/// <summary> /// Generates instructions. /// </summary> /// <param name="point"></param> /// <param name="interpreter"></param> /// <param name="languageGenerator"></param> /// <returns></returns> public static List<Instruction> Generate(AggregatedPoint point, IRoutingInterpreter interpreter, ILanguageGenerator languageGenerator) { if (point == null) { throw new ArgumentNullException("route"); } if (interpreter == null) { throw new ArgumentNullException("interpreter"); } if (languageGenerator == null) { throw new ArgumentNullException("languageGenerator"); } MicroPlanning.MicroPlanner planner = new MicroPlanning.MicroPlanner(languageGenerator, interpreter); return planner.Plan(point); }
/// <summary> /// Returns a router test object. /// </summary> /// <returns></returns> public abstract IRouter<RouterPoint> BuildRouter(IRoutingInterpreter interpreter, string embedded_name);
/// <summary> /// Builds the data source. /// </summary> /// <returns></returns> private DynamicGraphRouterDataSource<CHEdgeData> BuildData(IRoutingInterpreter interpreter) { DynamicGraphRouterDataSource<CHEdgeData> data = null; if (data == null) { OsmTagsIndex tags_index = new OsmTagsIndex(); // do the data processing. data = new DynamicGraphRouterDataSource<CHEdgeData>(tags_index); CHEdgeDataGraphProcessingTarget target_data = new CHEdgeDataGraphProcessingTarget( data, interpreter, data.TagsIndex, VehicleEnum.Car); XmlDataProcessorSource data_processor_source = new XmlDataProcessorSource( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.UnitTests.test_network.osm")); DataProcessorFilterSort sorter = new DataProcessorFilterSort(); sorter.RegisterSource(data_processor_source); target_data.RegisterSource(sorter); target_data.Pull(); } return data; }
/// <summary> /// Generates instructions. /// </summary> /// <param name="route"></param> /// <param name="interpreter"></param> /// <returns></returns> public static List<Instruction> Generate(Route route, IRoutingInterpreter interpreter) { return InstructionGenerator.Generate(route, interpreter, new OsmSharp.Routing.Instructions.LanguageGeneration.Defaults.EnglishLanguageGenerator()); }