/// <summary> /// Checks if the given point is connected to the rest of the network. Use this to detect points on routing islands. /// </summary> /// <param name="radius">The radius metric, that can be a distance, time or custom metric.</param> /// <returns></returns> public sealed override Result <bool> TryCheckConnectivity(IProfileInstance profileInstance, RouterPoint point, float radius, bool?forward = null) { try { if (!_db.Supports(profileInstance.Profile)) { return(new Result <bool>("Routing profile is not supported.", (message) => { return new Exception(message); })); } // get the weight handler. var weightHandler = this.GetDefaultWeightHandler(profileInstance); var checkForward = forward == null || forward.Value; var checkBackward = forward == null || !forward.Value; if (checkForward) { // build and run forward dykstra search. var dykstra = new Dykstra(_db.Network.GeometricGraph.Graph, weightHandler, null, point.ToEdgePaths(_db, weightHandler, true), radius, false); dykstra.Run(); if (!dykstra.HasSucceeded || !dykstra.MaxReached) { // something went wrong or max not reached. return(new Result <bool>(false)); } } if (checkBackward) { // build and run backward dykstra search. var dykstra = new Dykstra(_db.Network.GeometricGraph.Graph, weightHandler, null, point.ToEdgePaths(_db, weightHandler, false), radius, true); dykstra.Run(); if (!dykstra.HasSucceeded || !dykstra.MaxReached) { // something went wrong or max not reached. return(new Result <bool>(false)); } } return(new Result <bool>(true)); } catch (Exception ex) { return(new Result <bool>(ex.Message, (m) => ex)); } }
/// <summary> /// Returns true if all of the given profiles are supported. /// </summary> /// <returns></returns> public static bool SupportsAll(this RouterDb db, params Profiles.Profile[] profiles) { for (var i = 0; i < profiles.Length; i++) { if (!db.Supports(profiles[i])) { return(false); } } return(true); }
/// <summary> /// Checks if the given point is connected to the rest of the network. Use this to detect points on routing islands. /// </summary> /// <returns></returns> public sealed override Result <bool> TryCheckConnectivity(IProfileInstance profileInstance, RouterPoint point, float radiusInMeters) { if (!_db.Supports(profileInstance.Profile)) { return(new Result <bool>("Routing profile is not supported.", (message) => { return new Exception(message); })); } // get the weight handler. var weightHandler = this.GetDefaultWeightHandler(profileInstance); // build and run dykstra search. var dykstra = new Dykstra(_db.Network.GeometricGraph.Graph, weightHandler, null, point.ToEdgePaths(_db, weightHandler, true), radiusInMeters, false); dykstra.Run(); if (!dykstra.HasSucceeded) { // something went wrong. return(new Result <bool>(false)); } return(new Result <bool>(dykstra.MaxReached)); }
/// <summary> /// Returns true if the given profile is supported. /// </summary> public static bool Supports(this RouterDb db, Profiles.Profile profile) { return(db.Supports(profile.Parent.Name)); }
/// <summary> /// Checks if the given point is connected to the rest of the network. Use this to detect points on routing islands. /// </summary> /// <param name="radiusInMeter">The radius metric, that's always a distance in meters.</param> /// <returns></returns> public sealed override Result <bool> TryCheckConnectivity(IProfileInstance profileInstance, RouterPoint point, float radiusInMeter, bool?forward = null) { try { if (!_db.Supports(profileInstance.Profile)) { return(new Result <bool>("Routing profile is not supported.", (message) => { return new Exception(message); })); } // get the weight handler. var getGetFactor = this.GetDefaultGetFactor(profileInstance); Func <ushort, Factor> getShortestFactor = (p) => { // only keep directional information, get factor to 1 for distance metrics only. var factor = getGetFactor(p); if (factor.Value == 0) { return(new Factor() { Direction = factor.Direction, Value = 0 }); } return(new Factor() { Direction = factor.Direction, Value = 1 }); }; var weightHandler = new DefaultWeightHandler(getShortestFactor); var checkForward = forward == null || forward.Value; var checkBackward = forward == null || !forward.Value; if (checkForward) { // build and run forward dykstra search. var dykstra = new Algorithms.Default.EdgeBased.Dykstra(_db.Network.GeometricGraph.Graph, weightHandler, _db.GetGetRestrictions(profileInstance.Profile, true), point.ToEdgePaths(_db, weightHandler, true), radiusInMeter, false); dykstra.Run(); if (!dykstra.HasSucceeded || !dykstra.MaxReached) { // something went wrong or max not reached. return(new Result <bool>(false)); } } if (checkBackward) { // build and run backward dykstra search. var dykstra = new Algorithms.Default.EdgeBased.Dykstra(_db.Network.GeometricGraph.Graph, weightHandler, _db.GetGetRestrictions(profileInstance.Profile, false), point.ToEdgePaths(_db, weightHandler, false), radiusInMeter, true); dykstra.Run(); if (!dykstra.HasSucceeded || !dykstra.MaxReached) { // something went wrong or max not reached. return(new Result <bool>(false)); } } return(new Result <bool>(true)); } catch (Exception ex) { return(new Result <bool>(ex.Message, (m) => ex)); } }