47 CancellationToken cancellationToken =
default)
49 ArgumentNullException.ThrowIfNull(problem);
50 cancellationToken.ThrowIfCancellationRequested();
55 ArrayPool<double>.Shared.Rent(
59 ArrayPool<int>.Shared.Rent(
62 var predecessorBuffer =
63 ArrayPool<int>.Shared.Rent(
69 costToGoBuffer.AsSpan(
74 successorBuffer.AsSpan(
79 predecessorBuffer.AsSpan(
84 double.PositiveInfinity);
89 costToGo[horizon] = 0.0;
90 successor[horizon] = horizon;
98 for (var start = horizon - 1;
102 cancellationToken.ThrowIfCancellationRequested();
105 double.PositiveInfinity;
110 if (demands[start] == 0.0)
119 for (var end = start;
136 if (!
double.IsFinite(candidate))
138 throw new ArithmeticException(
139 "Numerical overflow in Zangwill shortest path.");
142 if (candidate < best ||
143 (candidate == best &&
151 if (!
double.IsFinite(best) ||
154 throw new ArithmeticException(
155 $
"No finite Zangwill path from node {start}.");
158 costToGo[start] = best;
159 successor[start] = bestNext;
164 while (node < horizon)
166 cancellationToken.ThrowIfCancellationRequested();
174 throw new InvalidOperationException(
175 "Invalid Zangwill successor chain.");
202 ArrayPool<double>.Shared.Return(
206 ArrayPool<int>.Shared.Return(
210 ArrayPool<int>.Shared.Return(