/// <summary> /// Generate the nearest neighbour list. /// </summary> /// <returns></returns> public SortedNearestNeighbours GetNearestNeighboursBackward(float weight, int customer) { if (_backwardSortedNearestNeighbours == null) { // not there yet, create. _backwardSortedNearestNeighbours = new Dictionary <float, SortedNearestNeighbours[]>(); } SortedNearestNeighbours[] nearestNeighbours = null; if (!_backwardSortedNearestNeighbours.TryGetValue(weight, out nearestNeighbours)) { // not found for n, create. nearestNeighbours = new SortedNearestNeighbours[this.Weights.Length]; _backwardSortedNearestNeighbours.Add(weight, nearestNeighbours); } var result = nearestNeighbours[customer]; if (result == null) { // not found, calculate. result = SortedNearestNeighbours.Backward(this.Weights, weight, customer); nearestNeighbours[customer] = result; } return(result); }