gradient Cast
Computes a fast, self-healing gradient broadcast of local values from all source nodes, always retaining the data from the nearest source.
Starting from every device where source is true, this function propagates data of type Value along multiple overlapping spanning trees. At each device:
If
sourceistrue, initializes its ownlocalvalue at distancebottom.Otherwise, gathers neighbor-propagated
GradientPath<ID, Value, Distance>?values, filters out nulls, loops (viamaxDiameterand hop sets), and paths invalidated by inconsistent neighbor distances, then selects the minimal-distance, path-coherent route.Uses
accumulateDistanceto sum edge distances andaccumulateDatato update the data payload.Falls back to
localif no valid source path exists.
This algorithm employs fast repair and is not subject to the rising-value problem, but it incurs larger message sizes and more computation than bellmanFordGradientCast. To limit work and prevent infinite loops, supply an estimate of the network diameter via maxDiameter.
Return
The Value associated with the nearest source node, following a minimal-distance, loop-free path, or local if no source paths are found.
Parameters
true if this device is a source node; otherwise false.
The local data value for this device, or the default if no source path exists.
The zero-distance value at a source. Must be ≤ top.
The maximum allowed distance; incoming distances are clamped into [bottom, top].
A Field<ID, Distance> providing edge weights to each neighbor.
Upper bound on path hop count; paths longer than this are discarded. Defaults to Int.MAX_VALUE.
Function to update neighbor data when traversing an edge. Receives the neighbor’s distance from source, the edge distance, and the neighbor’s data, returning a new Value. Defaults to identity.
A reducer to sum two Distance values; used for accumulating path lengths.
The type used for neighbor identifiers.
The type of data being propagated.
The type representing path lengths; must be comparable.
See also
Broadcasts a fast-repair gradient of local values from all source nodes, always retaining the data from the nearest source.
This overload delegates to the full gradientCast(...) implementation using a default distance range of [0.0, +∞) and the standard addition reducer.
Return
The data associated with the nearest source node, following a minimal-distance, loop-free path, or local if no source is reachable.
Parameters
true if this device is a source node; otherwise false.
The local data value or the fallback if no source path exists.
A Field<ID, Double> that provides the edge weight (distance) to each neighbor.
Upper limit on path hop count; any path exceeding this is discarded. Defaults to Int.MAX_VALUE.
Function to update neighbor data when traversing an edge. Receives the neighbor’s distance from source, the edge distance, and the neighbor’s data, returning a new data value. Defaults to the identity function.
Function to combine two distances; defaults to Double::plus.