Package 

Class Accumulation

  • All Implemented Interfaces:

    
    public final class Accumulation
    
                        
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Constructor Detail

    • Method Detail

      • aggregation

         final static <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 static 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 static 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 static <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 static <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 static <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 static 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 static 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 static 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 static 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 static <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 static Number countDevices(Number potential)

        Count the devices.

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

         final static 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 static 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 static 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 static 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 static 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 static 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 static <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 static <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 static <E extends Any, C extends Any, U extends Any, T extends Any> <ERROR CLASS> getChildren(Number potential, Function1<<ERROR CLASS>, 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 static <E extends Any, C extends Any, U extends Any, T extends Any> <ERROR CLASS> getChildrenExtended(Number potential, Function1<Unit, Boolean> condition, Function1<<ERROR CLASS>, 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 static <ERROR CLASS> getChildrenIds(Number potential)

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

        Parameters:
        potential - potential to be followed
      • getParent

         final static <E extends Any, C extends Any, T extends Any> Object getParent(Number potential, Function1<<ERROR CLASS>, 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 static <E extends Any, C extends Any, T extends Any, U extends Any> <ERROR CLASS> getParentExtended(Number potential, Function1<<ERROR CLASS>, 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 static <E extends Any, C extends Any, T extends Any, U extends Any> <ERROR CLASS> getParents(Number potential, Function1<<ERROR CLASS>, 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 static <E extends Any, C extends Any, T extends Any, U extends Any> <ERROR CLASS> getParentsExtended(Number potential, Function1<Number, Boolean> condition, Function1<<ERROR CLASS>, 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 static Number getParentId(Number potential)

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

        Parameters:
        potential - potential
      • getParentIds

         final static <ERROR CLASS> getParentIds(Number potential)

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

        Parameters:
        potential - potential
      • idUnion

         final static 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 static <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 static <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 static <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 static <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 static <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