intGradientCast

inline fun <ID : Any, Type> Aggregate<ID>.intGradientCast(source: Boolean, local: Type, metric: Field<ID, Int>, maxDiameter: Int = Int.MAX_VALUE, noinline accumulateData: (fromSource: Int, toNeighbor: Int, data: Type) -> Type = { _, _, data -> data }, crossinline accumulateDistance: Reducer<Int> = Int::nonOverflowingPlus): Type

Broadcasts a fast-repair integer gradient of local values from all source nodes, always retaining the data from the nearest source.

This overload applies when distances are Int, using a default range of [0, Int.MAX_VALUE] and the standard non-overflowing addition reducer.

At each device:

  • If source is true, propagates its own local value with distance 0.

  • Otherwise, collects neighbor paths, accumulates distances via accumulateDistance, applies accumulateData to the neighbor’s data, and selects the path with minimal total distance.

  • If no source path exists, returns local.

Return

The data associated with the nearest source node along a minimal-distance, loop-free path, or local if no source is reachable.

This algorithm employs fast repair and is not subject to the rising value problem. It requires larger messages and more computation than bellmanFordGradientCast. To improve performance, provide an upper bound on the network diameter via maxDiameter.

Parameters

ID

The type used for neighbor identifiers.

Type

The type of data being propagated.

source

true if this device is a source node; otherwise false.

local

The local data value or fallback if no source is reachable.

metric

A Field<ID, Int> providing edge weights to each neighbor.

maxDiameter

Maximum allowed number of hops; paths longer than this are discarded. Defaults to Int.MAX_VALUE.

accumulateData

Function to update neighbor data on each hop: receives the neighbor’s distance from source, the edge distance, and the neighbor’s data. Defaults to the identity function.

accumulateDistance

Reducer to combine two distances; defaults to Int::nonOverflowingPlus.

See also