private T[][] _weights; // the weights between all valid resolved points. /// <summary> /// Executes the algorithm. /// </summary> protected sealed override void DoRun(CancellationToken cancellationToken) { // run mass resolver if needed. if (!_massResolver.HasRun) { _massResolver.Run(cancellationToken); } // create error and resolved point management data structures. _correctedResolvedPoints = _massResolver.RouterPoints; _errors = new Dictionary <int, RouterPointError>(_correctedResolvedPoints.Count); _correctedIndices = new List <int>(_correctedResolvedPoints.Count); for (var i = 0; i < _correctedResolvedPoints.Count; i++) { _correctedIndices.Add(i); } // calculate matrix. var nonNullInvalids = new HashSet <int>(); _weights = _router.CalculateWeight(_profile, _weightHandler, _correctedResolvedPoints.ToArray(), nonNullInvalids); // take into account the non-null invalids now. if (nonNullInvalids.Count > 0) { // shrink lists and add errors. foreach (var invalid in nonNullInvalids) { _errors[invalid] = new RouterPointError() { Code = RouterPointErrorCode.NotRoutable, Message = "Location could not routed to or from." }; } _correctedResolvedPoints = _correctedResolvedPoints.ShrinkAndCopyList(nonNullInvalids); _correctedIndices = _correctedIndices.ShrinkAndCopyList(nonNullInvalids); _weights = _weights.SchrinkAndCopyMatrix(nonNullInvalids); } this.HasSucceeded = true; }
/// <summary> /// Executes the algorithm. /// </summary> protected override void DoRun() { _errors = new Dictionary <int, LocationError>(_locations.Length); _resolvedPoints = new List <RouterPoint>(_locations.Length); _resolvedPointsIndices = new List <int>(_locations.Length); // resolve all locations. var resolvedPoints = new RouterPoint[_locations.Length]; var profiles = new Profile[] { _profile }; for (var i = 0; i < _locations.Length; i++) { Result <RouterPoint> resolveResult = null; if (_matchEdge != null) { // use an edge-matcher. resolveResult = _router.TryResolve(profiles, _locations[i], (edge) => { return(_matchEdge(edge, i)); }, this.SearchDistanceInMeter); } else { // don't use an edge-matcher. resolveResult = _router.TryResolve(profiles, _locations[i], this.SearchDistanceInMeter); } if (!resolveResult.IsError) { // resolving was succesful. resolvedPoints[i] = resolveResult.Value; } } // remove all points that could not be resolved. for (var i = 0; i < resolvedPoints.Length; i++) { if (resolvedPoints[i] == null) { // could not be resolved! _errors[i] = new LocationError() { Code = LocationErrorCode.NotResolved, Message = "Location could not be linked to the road network." }; } else { // resolve is ok. resolvedPoints[i].Attributes.AddOrReplace("index", i.ToInvariantString()); _resolvedPointsIndices.Add(i); _resolvedPoints.Add(resolvedPoints[i]); } } // calculate matrix. var nonNullResolvedArray = _resolvedPoints.ToArray(); var nonNullInvalids = new HashSet <int>(); _weights = _router.CalculateWeight(_profile, _weightHandler, nonNullResolvedArray, nonNullInvalids); // take into account the non-null invalids now. if (nonNullInvalids.Count > 0) { // shrink lists and add errors. foreach (var invalid in nonNullInvalids) { _errors[_resolvedPointsIndices[invalid]] = new LocationError() { Code = LocationErrorCode.NotRoutable, Message = "Location could not routed to or from." }; } _resolvedPoints = _resolvedPoints.ShrinkAndCopyList(nonNullInvalids); _resolvedPointsIndices = _resolvedPointsIndices.ShrinkAndCopyList(nonNullInvalids); _weights = _weights.SchrinkAndCopyMatrix(nonNullInvalids); } this.HasSucceeded = true; }