Component Guide II: Containers

From Numerus
Jump to navigation Jump to search

Overview

Containers are components that hold one or more instances of a Capsule for use within a host (or parent) Capsule. The elements of a Container are called members or elements. Containers interface with the components in their parent through Connector Pins, which are represented as horizontal lines on the left and right side of the container body. (Left and right sides correspond to input and output pins, respectively.) Every Connector Pin is given a label, and they correspond roughly to the Input Pins and Output Pins of their Capules, although some Containers add pins.

Pins are addressed using dot notation. If Container X has Pin Y, then X.Y is a reference for that Pin.

Each container type extends and enriches the environment of its elements by assigning new functionalities that are only valid within the context of the container. These new functionalities are introduced through a set of primitive operators (Primops) provided by the Container. (In the language of computer science these kinds of Primops are called service providers.) The data structure of the container together with the service providers create a topological environment for the constituent Capsules. For example, the CellMatrix container holds a set of Capsules in a lattice or grid structure. Each Capsule is assigned row and column indices, and neighborhoods of Capsules can be identified and manipulated.

Every aggregator (i.e. a container hold more than one Capsule) assigns some form of identification to each of its constituents. For example, in the case of the CellMatrix, the index pair serves to uniquely specify a particular element. We'll use the term Aggregator Id to uniformly refer to this identification strategy.

Examples
  • A Chip binds the property Super to reference the Scope of the Chip's parent. This is used by the Chip's Input Pins to channel component data from the parent into the Chip.
  • An AgentVector assigns a unique Agent Id to each element (or agent) and provides the means for interaction between agents using these ids for indentification. It also represents location and trajectory parameters in the virtual space provided by the AgentVector in which its agents dwell. An AgentVector also supports agent lifetime management (i.e., births and deaths).
  • A CellMatrix assigns matrix Coordinates to each of its elements and supports interaction between its members (or cells) using these coordinates for identification.
  • A SimWorld combines an AgentVector with a CellMatrix, so that the virtual agent space of the AgentVector corresponds to the topological space created by the CellMatrix.
  • A NodeNetwork assigns a unique Node Id to each node of its graph.
  • A NetWorld combines an AgentVector with a NodeNetwork so that the virtual agent space of the AgentVector corresponds to the topological space created by the NodeNetork.

Connecting parent Capsule components to Input Connector Pins in a Container

Container Input Connection Table

The property pane of each container contains a table listing the inputs to that container.

To connect a component as an input to the container select the row containing the input and either select from the Select menu or right-click on the component.

Note: Output pins are accessed by connecting them as inputs to other components.


Common Aggregator I/O Protocol

Aggregator rules require that all member Capsules must implement the same interface; that is, they must contain identical Input/Output pin configurations. Consequently, most[1] aggregator Connector Pins corrspond directly to some input or output pin in each of the elements: each pin creates a one-to-many input connection or a many-to-one output connection between the Aggregator and some component in the parent Capsule. To provide maximum flexibility the following protocol is used:

Input to the Aggregator
  • If the source expression produces an ordinary NovaScript data structure (i.e., number, string, array, or object), that value is broadcast to all elements of the aggregator.
  • If the source expression is a function, that function is applied to the Aggregator Id of each element, and the resulting value is sent only to that element.
Output from the Aggregator
  • The output pin is acts like a function that inputs the Aggregator Id and returns the value for the Output Pin in the corresponding element.

Chip

Chip.png A Chip encapsulates an instance of a Capsule as a submodel within a host Capsule. More than one Chip containing instances of the same Capsule, or different Capsules, may appear in a single parent. Large Numerus models can be built using stacks of submodels based on a well-structured design pattern.

Each Chip has connector pins corresponding exactly to the set of Input and Output Pins in the encapsulated submodel.

To add a Chip to the current Capsule
  1. Press the mouse left button on the desired Capsule in the Capsule List and drag onto the Model Canvas to the desired location.
  2. Release the mouse and the Chip will appear.
Properties
  • Clocked Chip. If checked, turns this Chip into a Clocked Chip. See below.
Pins

The Connector Pins of a Chip provide direct access to the Interface (i.e., the Input/Out Pins) of the encapsulated submodel. Each pin is labeled with the name of the corresponding Interface component.

If an input pin is not connected in the parent model, the pin's value is used as a default.

Clocked Chip

Clockedchip.png Clocked Chips are paired with a dedicated clock (programmed by the parameters specified in the Properties Pane). Each timestep of the parent Capsule produces a complete run of the submodel contained in the Clocked Chip.

The user must provide complete clock and integration method specifications for the clocked chip.

Properties
  • Start, End, DT, Method. Runtime properties assigned to the Clocked Chip's dedicated clock.

See Using Clocked Chips

Introduction: Aggregators

Abstraction is the process of extracting a set of interacting elements which together create a well-defined computation over a given a set of inputs, and providing the ability to access that computation with different inputs from multiple points within the overall project. The simplest example of this in Numerus is the Capsule which is used in one or more chips to implement the instances of a particular submodel. Chips are less useful when large numbers of submodels are required. In such cases it is more efficient to use some form of container to hold a set of Capsule elements. This is analogous to using arrays to manage large sets of data. Like the array, an organizing structure (i.e., the index set) is required to provide a uniform means of access to these constituents.

We can actually take this one step further by adding a set of primitive properties and primitive operators that enforce a topological structure on the Capsules. For example, if we organize the Capsules into a two-dimensional lattice, each could represent a single cell in a cellular automaton. In order for this to be of any use, however, each cell must be able to identify its own coordinates and have some means of communicating with other cells in the lattice.

This is the role of Numerus’s aggregating components: 1) organize and provide access to a (possibly large) set of constituent Capsules; and 2) provide a set of properties and operators that foster information transfer among those constituents. Using this fundamental design the five aggregating components currently available with Numerus provide different topological organizations for their elements. Here are brief descriptions (note: all example properties and primops are restricted):

AgentVector
Organizes its Capsule set into a 1-dimensional array of agents. Each agent is assigned an agent id and contains a Capsule instance. Each agent is equipped to remember its location as a pair of x-y coordinates. Example property: myId, which returns the caller’s agent id; Example primop: MOVE(x, y) sets the current location of its caller to (x, y).
CellMatrix
Organizes its Capsule set into a 2 dimensional matrix of cells, with each assigned a row-column coordinate pair. Example property: Coords, which is bound to a Coord[2] object containing the row and column of the caller[3]. Example primop: RING(n), which returns the array containing the coordinates of all neighbors n units away from the caller.
SimWorld
Combines the topological spaces created by the CellMatrix and AgentVector aggregators into one that maps the (x, y) location of each agent to position within a cell. In this topology each CellMatrix is the size of a unit square, and so an agent with x-y coordinates (x, y) is mapped to the cell with row-column coordinates (r, c), where r = Math.floor(y) and c = Math.floor(x)[4]. Example property: rows is bound to the number of rows in the underlying CellMatrix (can be called from either a cell or an agent). Example primop: MYAGENTS() returns the list of agents currently within the calling cell.
NodeNetwork
Organizes its constituent set into a 1-dimensional array of nodes. Each node is assigned a node number and contains a Capsule instance and a set of weighted pointers referencing other nodes. Example property: myId, which returns the caller’s node number; Example primop: CONNECTIONS_IN returns a list of Objects, each containing the id and weight of a connection to this node.
Click here for an example of using a NodeNetwork.
NetWorld
Combines the topological spaces created by the NodeNetwork and the AgentVector, analogous to the SimWorld.

AgentVector

Notes

  1. AgentVectors add several special purpose pins.
  2. Coord object is one containing the properties row and col.
  3. by caller we mean that Capsule instance that is making the reference.
  4. Math.floor maps a real number to the largest integer less than that number; e.g., Math.floor(3.5) = 3.