Package 

Class accumulationKt

    • Method Detail

      • aggregation

         final <T extends Any> Unit aggregation(T local, Function2<T, T, T> reduce)

        Aggregation of local information.

        Parameters:
        local - local information
        reduce - how to aggregate information
      • average

         final Number average(Boolean sink, Object value)

        Estimate and broadcast the average value within a spatial region.

        Parameters:
        sink - whether the device is the root of the spanning tree
      • boundAverage

         final Number boundAverage(Boolean sink, Number local, Number range, Number null)

        Estimate the average value across a bounded spatial region.

        Parameters:
        sink - whether the device is the root of the spanning tree
        local - local value
        range - region range
        null - default value
      • C

         final <T extends Any> T C(Number potential, Function2<T, T, T> reduce, T local, T null)

        Aggregate a field of type T within a spanning tree built according to the maximum decrease in potential. Accumulate the potential according to the reduce function.

        Parameters:
        potential - gradient of which gives aggregation direction
        reduce - function
        local - local value
        null - evaluated when the field is empty
      • cMultiDivisible

         final <T extends Any> T cMultiDivisible(Number potential, T local, T null, Function2<T, T, T> reduce, Function1<T, T> dividend, Function1<T, T> divisor, Function2<T, T, T> fraction)

        Parameters:
        potential - gradient of which gives aggregation direction
        local - local value
        null - null value
        reduce - how to aggregate values
        dividend - dividend
        divisor - divisor
        fraction - how to divide dividend by the divisor
      • cMultiIdempotent

         final <T extends Any> T cMultiIdempotent(Number potential, Function2<T, T, T> f, T local, T default)

        Parameters:
        potential - accumulate values descending this potential
        f - how to accumulate values
        local - local value
        default - default value
      • cMultiMin

         final Number cMultiMin(Number potential, Number local)

        The potential-source converges to the min value.

        Parameters:
        potential - minimize values descending this potential
        local - value
      • cMultiMax

         final Number cMultiMax(Number potential, Number local)

        The potential-source converges to the max values.

        Parameters:
        potential - minimize values descending this potential
        local - value
      • cMultiSum

         final Number cMultiSum(Number potential, Number local)

        The potential-source converges to the sum of other device values. C collects values over a spanning tree. Even small perturbations can cause loss or duplication of values with major transient impact on its result. When the accumulation operation for C is either idempotent (e.g., logical and, or) or separable (e.g., summation), this can be mitigated by using all paths down the potential function rather than just one. Can implement any other idempotent or separable function.

        Parameters:
        potential - sum values descending this potential
        local - value
      • consensus

         final Number consensus(Number init, Function1<Number, Number> f)

        Devices agree on a common value.

        Parameters:
        init - initial device value
        f - how to determine consensus
      • cossip

         final <T extends Any> T cossip(Boolean sink, T value, Function2<T, T, T> f)

        Gossip a value manipulated according to f.

        Parameters:
        sink - whether the device is the root of the spanning tree
        value - what to gossip
        f - how to manipulate value
      • countDevices

         final Number countDevices(Number potential)

        Count the devices.

        Parameters:
        potential - gradient of which gives aggregation direction
      • countDevicesInRegion

         final Number countDevicesInRegion(Number potential, Boolean condition, Boolean region)

        Count the devices in a region.

        Parameters:
        potential - gradient of which gives aggregation direction
        condition - device discriminant
        region - region discriminant
      • countDevicesWithCondition

         final Number countDevicesWithCondition(Number potential, Boolean condition)

        Count the devices with a given condition.

        Parameters:
        potential - gradient of which gives aggregation direction
        condition - discriminant
      • diameter

         final Object diameter(Boolean source)

        Gossip and estimate the diameter of the connected component joined by the current device.

        Parameters:
        source - source of the connected component
      • diameterWithMetric

         final Object diameterWithMetric(Boolean source, Function1<Unit, Number> metric)

        Gossip and estimate the diameter of the connected component joined by the current device.

        Parameters:
        source - source of the connected component
        metric - metric
      • diameterInRegion

         final Object diameterInRegion(Boolean source, Object region)

        Gossip and estimate the diameter of the connected component joined by the current device.

        Parameters:
        source - source of the connected component
      • diameterInRegionWithMetric

         final Object diameterInRegionWithMetric(Boolean source, Object region, Object metric)

        Gossip and estimate the diameter of the connected component joined by the current device.

        Parameters:
        source - source of the connected component
      • getAllChildren

         final <T extends Any> <ERROR CLASS> getAllChildren(Number potential, Object f, Object g, T default)

        Apply function to the all the children which potential is greater or equale to the potential of the current device. A child may have multiple parents.

        Parameters:
        potential - potential to be followed
        default - default value for devices which are not children
      • getAllChildrenIds

         final <ERROR CLASS> getAllChildrenIds(Number potential)

        Get the ids of all the children with a potential greater or equal the pontential of the current device.

        Parameters:
        potential - potential to be followed
      • getChildren

         final <E extends Any, C extends Any, U extends Any, T extends Any> <ERROR CLASS> getChildren(Number potential, Function1<ExecutionContext, U> f, Function1<T, T> g, T default)

        Apply function to the children of the current device. Use this function if every child has a single parent, see getAllChildren otherwise.

        Parameters:
        potential - potential to be followed
        f - function to be applied to the child
        g - function to be applied to the child value
        default - default value for devices which are not children
      • getChildrenExtended

         final <E extends Any, C extends Any, U extends Any, T extends Any> <ERROR CLASS> getChildrenExtended(Number potential, Function1<Unit, Boolean> condition, Function1<ExecutionContext, U> f, Function1<T, T> g, T default)

        Apply function to the children of the current device. A child may have multiple parents.

        Parameters:
        potential - potential to be followed
        condition - which children should be considered
        f - function to be applied to the child
        g - function to be applied to the child value
        default - default value for devices which are not children
      • getChildrenIds

         final <ERROR CLASS> getChildrenIds(Number potential)

        Get the ids of all the children of the current device.

        Parameters:
        potential - potential to be followed
      • getParent

         final <E extends Any, C extends Any, T extends Any> Object getParent(Number potential, Function1<ExecutionContext, T> f)

        Find the parent of the current device following the maximum decrease in potential.

        Parameters:
        potential - potential
        f - what to do with the parent
      • getParentExtended

         final <E extends Any, C extends Any, T extends Any, U extends Any> <ERROR CLASS> getParentExtended(Number potential, Function1<ExecutionContext, T> f, Function1<U, U> g, U local)

        Find the parent of the current device following the maximum decrease in potential.

        Parameters:
        potential - potential
        f - what to do with the parent
        g - what to do with the value
        local - local value
      • getParents

         final <E extends Any, C extends Any, T extends Any, U extends Any> <ERROR CLASS> getParents(Number potential, Function1<ExecutionContext, T> f, Function1<U, U> g, U local, Object default)

        Find the parents of the current device following the decrease in potential.

        Parameters:
        potential - potential
        f - what to do with the parent
        g - what to do with the value
        local - local value
      • getParentsExtended

         final <E extends Any, C extends Any, T extends Any, U extends Any> <ERROR CLASS> getParentsExtended(Number potential, Function1<Number, Boolean> condition, Function1<ExecutionContext, T> f, Function1<U, U> g, U local, Object default)

        Find the parents of the current device following the decrease in potential.

        Parameters:
        potential - potential
        condition - how to determine parent devices
        f - what to do with the parent
        g - what to do with the value
        local - local value
      • getParentId

         final Number getParentId(Number potential)

        Find the ID of the current-device parent by following the maximum decrease in potential.

        Parameters:
        potential - potential
      • getParentIds

         final <ERROR CLASS> getParentIds(Number potential)

        Find the IDs of the current-device parents by following a potential decrease.

        Parameters:
        potential - potential
      • idUnion

         final Unit idUnion(Object idField)

        This function MUST NOT be public as it is an utilities for both protelis:coord:accumulation and protelis:coord:tree. This function reduces a field of ids

      • summarize

         final <T extends Any> T summarize(Boolean sink, Function2<T, T, T> reduce, T local, T null)

        Broadcast the value accumulated by the sink. Example: 'summarize(distanceTo(sink), sum, 1, 0)' broadcast the sum number of devices in a region.

        Parameters:
        sink - whether the device should collect the aggregated information
        reduce - how to aggregate
        local - local value
        null - default value
      • summarizeWithMetric

         final <T extends Any> T summarizeWithMetric(Boolean sink, Function1<Unit, Number> metric, Object accumulate, T local, T null)

        Broadcast the value accumulated by the sink.

        Parameters:
        sink - whether the device should collect the aggregated information
        metric - how to estimate distance to the other device
        local - local value
        null - default value
      • summarizeWithPotential

         final <T extends Any> T summarizeWithPotential(Number potential, Number zero, Object accumulate, T local, T null)

        Broadcast the value accumulated by the sink.

        Parameters:
        potential - potential
        zero - value representing null potential
        local - local value
        null - default value
      • quorumSensing

         final <T extends Any> T quorumSensing(Number potential, Object zero, Number thr, Function1<Number, T> under, Function1<Number, T> over)

        Quorum sensing.

        Parameters:
        potential - gradient of which gives aggregation direction
        thr - threshold
        under - what to do if quorum is under threshold
        over - what to do otherwise
      • quorumSensingWithCondition

         final <T extends Any> T quorumSensingWithCondition(Number potential, Object zero, Number thr, Boolean condition, Function1<Number, T> under, Function1<Number, T> over)

        Quorum sensing.

        Parameters:
        potential - gradient of which gives aggregation direction
        thr - threshold
        condition - whether to count a device or not
        under - what to do if quorum is under threshold
        over - what to do otherwise