/// <summary> /// Generate the nearest neighbour list. /// </summary> /// <returns></returns> public SortedNearestNeighbours GetNearestNeighboursBackward(float weight, int id) { 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.Times.Length]; _backwardSortedNearestNeighbours.Add(weight, nearestNeighbours); } var result = nearestNeighbours[id]; if (result == null) { // not found, calculate. result = SortedNearestNeighbours.BackwardDirected(this.Times, weight, id); nearestNeighbours[id] = result; } return(result); }
/// <summary> /// Generate the nearest neighbour list. /// </summary> /// <returns></returns> public SortedNearestNeighbours GetNearestNeighboursForward(float weight, int customer) { if (_forwardSortedNearestNeighbours == null) { // not there yet, create. _forwardSortedNearestNeighbours = new Dictionary <float, SortedNearestNeighbours[]>(); } SortedNearestNeighbours[] nearestNeighbours = null; if (!_forwardSortedNearestNeighbours.TryGetValue(weight, out nearestNeighbours)) { // not found for n, create. nearestNeighbours = new SortedNearestNeighbours[this.Weights.Length]; _forwardSortedNearestNeighbours.Add(weight, nearestNeighbours); } var result = nearestNeighbours[customer]; if (result == null) { // not found, calculate. result = SortedNearestNeighbours.Forward(this.Weights, weight, customer); nearestNeighbours[customer] = result; } return(result); }