Class Accumulation
-
- All Implemented Interfaces:
public final class Accumulation
-
-
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. -
-
Method Detail
-
aggregation
final static <T extends Any> Unit aggregation(T local, Function2<T, T, T> reduce)
Aggregation of local information.
- Parameters:
local
- local informationreduce
- 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 treelocal
- local valuerange
- region rangenull
- 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 directionreduce
- functionlocal
- local valuenull
- 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 directionlocal
- local valuenull
- null valuereduce
- how to aggregate valuesdividend
- dividenddivisor
- divisorfraction
- 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 potentialf
- how to accumulate valueslocal
- local valuedefault
- 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 potentiallocal
- 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 potentiallocal
- 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 potentiallocal
- 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 valuef
- 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 treevalue
- what to gossipf
- 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 directioncondition
- device discriminantregion
- 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 directioncondition
- 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 componentmetric
- 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 followeddefault
- 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 followedf
- function to be applied to the childg
- function to be applied to the child valuedefault
- 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 followedcondition
- which children should be consideredf
- function to be applied to the childg
- function to be applied to the child valuedefault
- 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
- potentialf
- 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
- potentialf
- what to do with the parentg
- what to do with the valuelocal
- 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
- potentialf
- what to do with the parentg
- what to do with the valuelocal
- 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
- potentialcondition
- how to determine parent devicesf
- what to do with the parentg
- what to do with the valuelocal
- 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 valueepsilon
- epsilon- Returns:
value agreed upon consensus
-
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 informationreduce
- how to aggregatelocal
- local valuenull
- 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 informationmetric
- how to estimate distance to the other devicelocal
- local valuenull
- 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
- potentialzero
- value representing null potentiallocal
- local valuenull
- default value- Returns:
aggregated value
-
summarizeWithPotentialExt
final static Unit summarizeWithPotentialExt(Object potential, Object zero, Object accumulate, Object f, Object local, Object null)
-
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 directionthr
- thresholdunder
- what to do if quorum is under thresholdover
- 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 directionthr
- thresholdcondition
- whether to count a device or notunder
- what to do if quorum is under thresholdover
- what to do otherwise
-
-
-
-