/// <summary> /// Called when a forward vertex was found. /// </summary> /// <returns></returns> private bool ForwardVertexFound(Dykstra <T> dykstra, int i, uint pointer, uint vertex, T weight) { Dictionary <int, EdgePath <T> > bucket; if (!_buckets.TryGetValue(vertex, out bucket)) { bucket = new Dictionary <int, EdgePath <T> >(); _buckets.Add(vertex, bucket); bucket[i] = dykstra.GetPath(pointer); } else { EdgePath <T> existing; if (bucket.TryGetValue(i, out existing)) { if (_weightHandler.IsSmallerThan(weight, existing.Weight)) { bucket[i] = dykstra.GetPath(pointer); } } else { bucket[i] = dykstra.GetPath(pointer); } } return(false); }
/// <summary> /// Called when a backward vertex was found. /// </summary> /// <returns></returns> private bool BackwardVertexFound(Dykstra <T> dykstra, int i, uint pointer, uint vertex, T weight) { Dictionary <int, EdgePath <T> > bucket; if (_buckets.TryGetValue(vertex, out bucket)) { foreach (var pair in bucket) { var existing = _solutions[pair.Key][i]; var total = _weightHandler.Add(weight, pair.Value.Weight); var existingWeight = _weightHandler.Infinite; if (existing.Path != null) { existingWeight = existing.Path.Weight; } else if (existing.Path1 != null && existing.Path2 != null) { existingWeight = _weightHandler.Add(existing.Path1.Weight, existing.Path2.Weight); } if (_weightHandler.IsSmallerThan(total, existingWeight)) { // append the backward to the forward path. _solutions[pair.Key][i] = new Solution() { Path1 = pair.Value, Path2 = dykstra.GetPath(pointer) }; } } } return(false); }