MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / IsBetter

Method IsBetter

src/linkgraph/mcf.cpp:199–222  ·  view source on GitHub ↗

* Determines if an extension to the given Path with the given parameters is * better than this path. * @param base Other path. * @param free_cap Capacity of the new edge to be added to base. * @param dist Distance of the new edge. * @return True if base + the new edge would be better than the path associated * with this annotation. */

Source from the content-addressed store, hash-verified

197 * with this annotation.
198 */
199bool DistanceAnnotation::IsBetter(const DistanceAnnotation *base, uint,
200 int free_cap, uint dist) const
201{
202 /* If any of the paths is disconnected, the other one is better. If both
203 * are disconnected, this path is better.*/
204 if (base->distance == UINT_MAX) {
205 return false;
206 } else if (this->distance == UINT_MAX) {
207 return true;
208 }
209
210 if (free_cap > 0 && base->free_capacity > 0) {
211 /* If both paths have capacity left, compare their distances.
212 * If the other path has capacity left and this one hasn't, the
213 * other one's better (thus, return true). */
214 return this->free_capacity > 0 ? (base->distance + dist < this->distance) : true;
215 } else {
216 /* If the other path doesn't have capacity left, but this one has,
217 * the other one is worse (thus, return false).
218 * If both paths are out of capacity, do the regular distance
219 * comparison. */
220 return this->free_capacity > 0 ? false : (base->distance + dist < this->distance);
221 }
222}
223
224/**
225 * Determines if an extension to the given Path with the given parameters is

Callers 1

DijkstraMethod · 0.80

Calls 1

GetCapacityRatioMethod · 0.80

Tested by

no test coverage detected