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
    • Method Summary

      Modifier and Type Method Description
      final static <T extends Any> Unit aggregation(T local, Function2<T, T, T> reduce) Aggregation of local information.
      final static Number average(Boolean sink, Object value) Estimate and broadcast the average value within a spatial region.
      final static Number boundAverage(Boolean sink, Number local, Number range, Number null) Estimate the average value across a bounded spatial region.
      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.
      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)
      final static <T extends Any> T cMultiIdempotent(Number potential, Function2<T, T, T> f, T local, T default)
      final static Number cMultiMin(Number potential, Number local) The potential-source converges to the min value.
      final static Number cMultiMax(Number potential, Number local) The potential-source converges to the max values.
      final static Number cMultiSum(Number potential, Number local) The potential-source converges to the sum of other device values.
      final static Number consensus(Number init, Function1<Number, Number> f) Devices agree on a common value.
      final static <T extends Any> T cossip(Boolean sink, T value, Function2<T, T, T> f) Gossip a value manipulated according to f.
      final static Number countDevices(Number potential) Count the devices.
      final static Number countDevicesInRegion(Number potential, Boolean condition, Boolean region) Count the devices in a region.
      final static Number countDevicesWithCondition(Number potential, Boolean condition) Count the devices with a given condition.
      final static Object diameter(Boolean source) Gossip and estimate the diameter of the connected component joined by the current device.
      final static Object diameterWithMetric(Boolean source, Function1<Unit, Number> metric) Gossip and estimate the diameter of the connected component joined by the current device.
      final static Object diameterInRegion(Boolean source, Object region) Gossip and estimate the diameter of the connected component joined by the current device.
      final static Object diameterInRegionWithMetric(Boolean source, Object region, Object metric) Gossip and estimate the diameter of the connected component joined by the current device.
      final static <T extends Any> <Error class: unknown 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.
      final static <Error class: unknown class> getAllChildrenIds(Number potential) Get the ids of all the children with a potential greater or equal the pontential of the current device.
      final static <E extends Any, C extends Any, U extends Any, T extends Any> <Error class: unknown class> getChildren(Number potential, Function1<<Error class: unknown class>, U> f, Function1<T, T> g, T default) Apply function to the children of the current device.
      final static <E extends Any, C extends Any, U extends Any, T extends Any> <Error class: unknown class> getChildrenExtended(Number potential, Function1<Unit, Boolean> condition, Function1<<Error class: unknown class>, U> f, Function1<T, T> g, T default) Apply function to the children of the current device.
      final static <Error class: unknown class> getChildrenIds(Number potential) Get the ids of all the children of the current device.
      final static <E extends Any, C extends Any, T extends Any> Object getParent(Number potential, Function1<<Error class: unknown class>, T> f) Find the parent of the current device following the maximum decrease in potential.
      final static <E extends Any, C extends Any, T extends Any, U extends Any> <Error class: unknown class> getParentExtended(Number potential, Function1<<Error class: unknown class>, T> f, Function1<U, U> g, U local) Find the parent of the current device following the maximum decrease in potential.
      final static <E extends Any, C extends Any, T extends Any, U extends Any> <Error class: unknown class> getParents(Number potential, Function1<<Error class: unknown class>, T> f, Function1<U, U> g, U local, Object default) Find the parents of the current device following the decrease in potential.
      final static <E extends Any, C extends Any, T extends Any, U extends Any> <Error class: unknown class> getParentsExtended(Number potential, Function1<Number, Boolean> condition, Function1<<Error class: unknown class>, T> f, Function1<U, U> g, U local, Object default) Find the parents of the current device following the decrease in potential.
      final static Number getParentId(Number potential) Find the ID of the current-device parent by following the maximum decrease in potential.
      final static <Error class: unknown class> getParentIds(Number potential) Find the IDs of the current-device parents by following a potential decrease.
      final static Boolean hasNoParent(Number id)
      final static Boolean hasParent(Number id)
      final static Number imRoot()
      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.
      final static Number laplacianConsensus(Number init, Number epsilon) Laplacian consensus.
      final static Number noParent()
      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.
      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.
      final static <T extends Any> T summarizeWithPotential(Number potential, Number zero, Object accumulate, T local, T null) Broadcast the value accumulated by the sink.
      final static Unit summarizeWithPotentialExt(Object potential, Object zero, Object accumulate, Object f, Object local, Object null)
      final static <T extends Any> T quorumSensing(Number potential, Object zero, Number thr, Function1<Number, T> under, Function1<Number, T> over) Quorum sensing.
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
        Returns:

        average value

      • 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
        Returns:

        average 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
        Returns:

        aggregated value

      • 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
        Returns:

        aggregated value

      • 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
        Returns:

        accumulated 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
        Returns:

        minimum 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
        Returns:

        maximum 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
        Returns:

        aggregated 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
        Returns:

        shared value

      • 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
        Returns:

        the value resulting from gossip

      • countDevices

         final static Number countDevices(Number potential)

        Count the devices.

        Parameters:
        potential - gradient of which gives aggregation direction
        Returns:

        number of devices

      • 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
        Returns:

        number of devices

      • 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
        Returns:

        number of devices

      • 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
        Returns:

        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
        Returns:

        of the connected component

      • 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
        Returns:

        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
        Returns:

        of the connected component

      • getAllChildren

         final static <T extends Any> <Error class: unknown 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: unknown 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
        Returns:

        list of children ids

      • getChildren

         final static <E extends Any, C extends Any, U extends Any, T extends Any> <Error class: unknown class> getChildren(Number potential, Function1<<Error class: unknown 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
        Returns:

        children

      • getChildrenExtended

         final static <E extends Any, C extends Any, U extends Any, T extends Any> <Error class: unknown class> getChildrenExtended(Number potential, Function1<Unit, Boolean> condition, Function1<<Error class: unknown 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
        Returns:

        children list

      • getChildrenIds

         final static <Error class: unknown class> getChildrenIds(Number potential)

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

        Parameters:
        potential - potential to be followed
        Returns:

        list of children ids

      • getParent

         final static <E extends Any, C extends Any, T extends Any> Object getParent(Number potential, Function1<<Error class: unknown 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
        Returns:

        imRoot()|noParent()|f(parent)

      • getParentExtended

         final static <E extends Any, C extends Any, T extends Any, U extends Any> <Error class: unknown class> getParentExtended(Number potential, Function1<<Error class: unknown 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
        Returns:

        imRoot()|noParent()|f(parent), g(value)

      • getParents

         final static <E extends Any, C extends Any, T extends Any, U extends Any> <Error class: unknown class> getParents(Number potential, Function1<<Error class: unknown 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
        Returns:

        [imRoot()|noParent()|f(parent), g(value)]

      • getParentsExtended

         final static <E extends Any, C extends Any, T extends Any, U extends Any> <Error class: unknown class> getParentsExtended(Number potential, Function1<Number, Boolean> condition, Function1<<Error class: unknown 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
        Returns:

        [imRoot()|noParent()|f(parent), g(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
        Returns:

        imRoot()|noParent()|parentId

      • getParentIds

         final static <Error class: unknown class> getParentIds(Number potential)

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

        Parameters:
        potential - potential
        Returns:

        list of parent ids

      • hasNoParent

         final static Boolean hasNoParent(Number id)
        Parameters:
        id - device id
        Returns:

        true if the device has no parent

      • hasParent

         final static Boolean hasParent(Number id)
        Parameters:
        id - device id
        Returns:

        true if the device has a parent

      • 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

      • laplacianConsensus

         final static Number laplacianConsensus(Number init, Number epsilon)

        Laplacian consensus.

        Parameters:
        init - initial value
        epsilon - epsilon
        Returns:

        value agreed upon consensus

      • noParent

         final static Number noParent()
        Returns:

        error finding parent

      • 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
        Returns:

        aggregated 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
        Returns:

        aggregated 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
        Returns:

        aggregated 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