Structuring the simulator - noware/simulatedcyborg GitHub Wiki

Person

A person is the basic unit in the cyborg network. The "person" class will contain the following:

  1. a real location function Xreal(t), which maps a time point to one of the following:
    • a location "staying[Xi]", or
    • between two locations "moving[Xi, Xj]"
  2. a scheduled location function Xsched(tnow, Δt), which is the person's expectation of where they will be in the future at tnow + Δt.
  3. some application-specific states S.
  4. a mutable set of connections to other people.

Location

A location consists of the latitude and longitude (and altitude?), or other encoding system.

It is possible to query the distance between two location, to determine whether two persons are close enough to have direct contact.

Time

All people share the same time t. This would be a global mutable variable. The value of t might be controlled by the applications in simulation, but it must be monotonically increasing.

One may let time progress with

  • {IncreaseTime Dt}

and register event handlers for time progression

  • {RegiterTimeChangeHandler proc {$ T} ... end}

Simulation

Each person is simulated as manipulating the "person" class, running in an individual Oz thread. The "person" class should expose the following methods:

  1. getCurrentLocation(location: ?Loc)
  2. getFutureLocation(secondsAfter: Dt location: ?Loc)
  3. getState(applicationId: Id state: ?S)
  4. updateState(applicationId: Id modifier: P)
  5. registerTimeChangeHandler(handler: proc {$ T} ... end)
  6. registerMessageHandler(applicationId: Id handler: fun {$ T FromPsId M} ... end)
  7. sendMessage(applicationId: Id person: PsId message: M)
  8. sendMessageWithReply(applicationId: Id person: PsId message: M reply: ?R)
  9. getConnections(people: ?PsIds)

Example: Hand-pass simulator

The application state will contain (a) mutable — a set of unique package ids, (b) immutable — a dictionary of the location, time range and person to pass the package to, (c) immutable — a set of the package id to receive from

These shall create an undirected chain to pass a package from one location to another.

The application may perform the following:

{Person registerMessageHandler(applicationId: xxxx   handler: fun {$ T FromPsId PackageId}
    PackageStatus = {NewCell ignored}
    {Person updateState(applicationId: xxxx   modifier: fun {$ S}
        if {Set.contains S.packageIdToReceive PackageId} then
            {Set.add S.packages PackageId}
            PackageStatus := received
        end
        S
    end)}
    PackageStatus
end)}

{Person registerTimeChangeHandler(handler: proc {$ T} 
    S = {Person getState(applicationId:xxxx)}
    L = {Person getCurrentLocation(location:$)}
    for PackageId in {Set.toList S.packages} do
        PackageInfo = {Set.get S.packageInfoToSend PackageId}
        if PackageInfo.location == L andthen {Between PackageInfo.timeRange T} andthen {IsPersonNearby PackageInfo.person L} then
            case {Person sendMessageWithReply(applicationId:xxxx person:PackageInfo.person message:PackageId reply:$)}
                of received then {Set.remove S.packages PackageId}
                [] ignored then skip
            end
        end
    end
end)}
⚠️ **GitHub.com Fallback** ⚠️