InterDyne Modelling Example

The InterDyne Simulator - Modelling Example

In early experiments all messages were sent using agent identifers.  It is still possible to do this, but we have since found it useful to refer to agents by name rather than by ID number, and we now recommend inclusion in the list of "runtime arguments" a function that when executed will convert an ID into a name or vice-versa.  This is included in the runtime arguments so that it can be used by any agent and so that the mapping of names to identifers is in the control of the experimenter.  The following example illustrates how the function sim can be called:

import Simulations.RuntimeArgFunctions as RTAFuns

exampleExperiment :: IO ()
  = do
    sim 60 myargs (map snd myagents)
    myargs = [ convert ]
    myagents = [ ("Trader",  (traderWrapper, [1])),
                 ("Broker",  (brokerWrapper, [3])),
                 ("Exchange",(exchangeWrapper, [2,3]))
    convert = RTAFuns.generateAgentBimapArg myagents

In the above example sim is instructed to run for 60 time steps; there is only one runtime argument called convert, and the third argument to sim is a list of agents and broadcast channels on which they will listen.  The convert function is a partial application of the library function generateAgentBimapArg (available in InterDyne v0.25 and later) to myagents - the result will be a function that will convert a name to an ID and vice versa.  The first agent subscribes to broadcast channel 1, the second subscribes to channel 3, and the third subscribes to channels 2 and 3.  This example does not illustrate how to define an output file for the results, nor how to use names instead of integers for broadcast channels, nor how to specify the legal communications topology and the delays that should be applied to each communication link.  It does however indicate the parsimonious style that can be achieved when using Haskell.

Agents are typically (but not always) written in two parts: (i) a "wrapper" function that manages the consumption of inbound messages, the generation of outbound messages, and the update of local state, and (ii) a "logic" function that is called by the wrapper function and which calculates the messages to be sent.  The "wrapper" function is the true agent function, and it must be of type Agent_t

Here is a simple agent wrapper that does nothing (at each time step it consumes an inbound item, and creates an empty outbound item).  It does not call a logic function:

f :: Agent_t
f st args ((t, msgs, bcasts) : rest) myid
     =  []  : (f st args rest myid)

The agent function is recursively defined and loops once per time step.  It takes four arguments: st is a local state variable (in this example it is never inspected and never changed), args is a copy of the runtime arguments (every agent is passed a copy of all the runtime arguments), the last argument myid is the ID of this agent (which is decided by the simulator and should never be changed) and the third argument is the list of inbound items - each item is a 3-tuple containing (i) the current time (an integer); (ii) a list of all one-to-one messages sent to this agent by other agents; and (iii) a list of all broadcast messages available at this time step on all the broadcast channels to which this agent is subscribed.

Christopher D. Clack
Department of Computer Science
Gower Street