Aggregate Operators and Field Operations
Fields
The Field
is a data structure that maps for each device inside a neighborhood1,
the device's ID to its local value.2
Each field contains the ID
of the device itself as well as its local value,
and the IDs of the neighbors and their values.
For example, the field shared by an isolated device with ID 0
in a network is:
ϕ(localId=0, localValue=0, neighbors={})
Note that, hence no neighbors are present, the neighbors
value is empty.
Suppose that there are three devices all connected to each other:
Device with ID 0
has a local value of 5
,
device with ID 1
has a local value of 10
,
and device with ID 2
has a local value of 15
.
Considering the following exchange
program:
exchange(initialValue) { field -> field }
These are the fields that each device perceives:
ϕ(localId=0, localValue=5, neighbors={1=10, 2=15}) // field perceived by device 0
ϕ(localId=1, localValue=10, neighbors={0=5, 2=15}) // field perceived by device 1
ϕ(localId=2, localValue=15, neighbors={0=5, 1=10}) // field perceived by device 2
Notice how the values of the neighbors are included in the field.
Now, let's consider a more complex scenario with four devices, where the device with ID 3
has as neighbor only the device with ID 0
:
With the same exchange
program as before, the fields perceived by each device are:
ϕ(localId=0, localValue=5, neighbors={1=10, 2=15, 3=20}) // field perceived by device 0
ϕ(localId=1, localValue=10, neighbors={0=5, 2=15}) // field perceived by device 1
ϕ(localId=2, localValue=15, neighbors={0=5, 1=10}) // field perceived by device 2
ϕ(localId=3, localValue=20, neighbors={0=5}) // field perceived by device 3
Note now that the device with ID 3
has only one neighbor, the device with ID 0
,
thus device 0
is the only one that has the device with ID 3
in its neighborhood,
while device 3
has just the device with ID 0
in its neighborhood.
Aggregate Operators
The main operators of the DSL
that can manipulate fields are:
Exchange
exchange
is the foundation of XC
3,
has the crucial aspect that can send different values to each neighbor,
allowing custom interaction between them.
It models the space-time evolution of the device.
Example
// when the id of the device is even,
// add 1 to the value perceived, else double the value.
exchange(initialValue) { field ->
field.mapWithId { id, value ->
if (id % 2 == 0) value + 1 else value * 2
}
}
After each iteration of every device, the resultant fields are the following:
ϕ(localId=0, localValue=5, neighbors={})
ϕ(localId=1, localValue=10, neighbors={0=6})
ϕ(localId=2, localValue=15, neighbors={0=6, 1=20})
ϕ(localId=3, localValue=20, neighbors={0=6, 1=20, 2=16})
Exchanging
Share
share models the device space-time evolution.
Sharing
Neighboring
neighboring
allows to access the values of the neighbours and send them information.
Neighboring via Exchange
Evolve
evolve
allows to model the state evolution of the device over time.
Evolving
Field Operations
TODO
Footnotes
-
The neighborhood is the set of devices that are directly connected to a given device. ↩
-
This is the definition of
field
inside Collektive, its definition from the Aggregate Computing perspective is slightly different. ↩ -
G. Audrito, R. Casadei, F. Damiani, G. Salvaneschi, and M. Viroli "The eXchange Calculus (XC): A functional programming language design for distributed collective systems." ↩