Tutorials › Quantitative Systems Pharmacology (QSP) › Defining Rules in Agent-Based Models

Spatial and Agent-Based Approaches · Tutorial 230 of 799

Defining Rules in Agent-Based Models

Learn to specify agent states, local movement and signaling rules, update schedules, and environmental fields in an agent-based model, then check that the combined rules are interpretable and consistent.

Advanced 11 min read

What You'll Learn

  • Distinguish an agent’s internal state from its position and from environmental fields.
  • Write local rules with explicit inputs, conditions, actions, and units.
  • Specify the order and timing of field, state, and position updates.
  • Work through a hypothetical signal-dependent movement rule.
  • Identify diagnostics and limitations of a rule-based model.

From a Biological Question to Executable Rules

An agent-based model (ABM) represents a system as individual agents whose states change through specified rules, in an environment that may itself change over time. In a cell model, an agent might represent one cell; its state could include activation or viability, while its position describes where it is. A signaling molecule may instead be represented as a field: a concentration defined across the environment and available for cells to sense.

The central task is to make each rule unambiguous. “Cells move when signaling is high” is not executable until the model specifies what counts as high, where the signal is measured, which positions are allowed, how conflicts are resolved, and when the rule is applied. Clear definitions also make assumptions visible: a threshold may represent a simplified biological response, not a directly observed switch.

Definition: An agent state is the set of properties assigned to an individual agent at a given time. A local interaction rule maps the agent’s state and relevant nearby information to an action or state change. An environmental field is a spatially defined quantity, such as ligand concentration, that can be changed by sources, sinks, or transport and can be sampled by agents. An update schedule specifies when and in what order these changes are applied.

A useful rule specification names four elements: the information read, the condition evaluated, the action taken, and the time at which the action occurs. Keep agent-owned quantities, such as activation state, separate from field quantities, such as extracellular concentration. This prevents ambiguity about whether a rule changes one cell, the shared environment, or both.

Specify State, Rules, and Timing

Suppose each cell \(j\) has position \(x_j\) and a binary motility-activation state \(A_j\), where \(A_j=1\) means movement is enabled and \(A_j=0\) means it is not. Let \(C(x,t)\) denote the local concentration of a signaling molecule. A simple rule can set activation by comparing the concentration at the cell’s position with a threshold \(C_{\mathrm{th}}\):

$$ A_j^{n+1} = \begin{cases} 1, & C(x_j^n,t^n) \ge C_{\mathrm{th}},\\ 0, & C(x_j^n,t^n) < C_{\mathrm{th}}. \end{cases} $$

Here \(n\) indexes update steps. This rule assumes that activation responds immediately to the sampled concentration, has no memory, and changes sharply at the threshold. Those assumptions may be convenient, but they are biological simplifications. A gradual response or delayed activation would require a different state variable and rule.

To define movement without tying the rule to a particular spatial representation, let the geometry component provide an ordered list of candidate positions for each cell. A candidate is admissible if it satisfies the model’s stated geometric and occupancy constraints. If \(A_j^{n+1}=1\), the cell moves to the first currently admissible candidate; if none is admissible, it remains at \(x_j^n\). If activation is zero, it also remains in place. The candidate-generation method and admissibility test must be specified by the model, but the rule’s logic can be stated independently of those choices.

Timing is part of the model, not a coding detail. For example, one schedule could update the field, calculate every cell’s activation using the resulting field, and then process movement one cell at a time in a fixed order. A cell moved earlier in that pass may affect the available positions for a cell processed later. By contrast, a synchronous movement pass would calculate all destinations from the same pre-movement configuration and apply them together, requiring an explicit rule for conflicts. These schedules can produce different outcomes even when they use the same local movement condition.

Worked Example: Writing a Signal-Triggered Movement Rule

Hypothetical model. Cells sample signal concentration in nanomoles per liter (nM). Set \(C_{\mathrm{th}}=2.0\) nM. At each step, first update activation for all cells, then process cells in a fixed order. An activated cell moves to its first admissible candidate position; a cell with no admissible candidate stays put.

Cell A samples \(2.4\) nM, and its first candidate is admissible. Since \(2.4 \ge 2.0\), the activation rule sets \(A_A^{n+1}=1\). The movement rule therefore moves Cell A to that candidate.

Cell B samples \(1.6\) nM. Since \(1.6 < 2.0\), the rule sets \(A_B^{n+1}=0\), so Cell B stays in place regardless of whether a candidate position is available.

Cell C samples \(2.3\) nM, so \(A_C^{n+1}=1\), but none of its candidates is admissible when it is processed. It remains at its current position. Thus signal activation is not itself a guarantee of movement: the movement rule also requires an admissible destination.

This specification does not say that cells move toward higher signal. The field sets whether movement is enabled; the candidate ordering and geometry rule determine where an enabled cell can go. That distinction keeps a simple activation rule separate from a directional migration mechanism.

Representing the Environmental Field

A field needs its own definition of sources, losses, spatial transport, units, and timing. A general signal model may include diffusion, degradation, and secretion by cells. In continuous form, one common specification is:

$$ \frac{\partial C}{\partial t} = D\nabla^2 C-kC+q\sum_j \delta(x-x_j). $$

Here \(D\) is a diffusion coefficient, \(k\) is a first-order degradation rate, \(q\) is secretion per cell in a compatible concentration-rate representation, and the source term places secretion at cell locations. This equation assumes that diffusion and degradation adequately describe extracellular transport and loss; it does not, by itself, specify how cells respond. Boundary and initial conditions, as well as numerical solution choices, must also be set. The field-update approach should be consistent with the model’s spatial scale and the assumptions of the reaction-diffusion representation.

In an agent model, a field can be updated over a time interval and then sampled by agents, or agent sources can be incorporated at specified points during the interval. These choices matter: a cell that secretes during a step cannot affect another cell’s response during that same step unless the schedule explicitly updates the field before that response is evaluated.

Worked Example: Updating a Uniform Signal Field

Consider a hypothetical, well-mixed local region with concentration \(C=1.0\) nM, two secreting cells, secretion rate \(q=0.40\) nM per hour per cell, and first-order degradation rate \(k=0.20\) per hour. Assume no spatial concentration gradients, so the diffusion contribution is zero. Over \(\Delta t=0.50\) hours, use a forward Euler update:

$$ C^{n+1}=C^n+\Delta t(Nq-kC^n). $$

Substituting \(N=2\), \(q=0.40\) nM per hour per cell, \(k=0.20\) per hour, and \(C^n=1.0\) nM gives:

$$ C^{n+1} =1.0\ \mathrm{nM} +0.50\ \mathrm{h} \left[ 2(0.40\ \mathrm{nM\,h^{-1}\,cell^{-1}}) -(0.20\ \mathrm{h^{-1}})(1.0\ \mathrm{nM}) \right] =1.3\ \mathrm{nM}. $$

The rate inside the brackets is \(0.80-0.20=0.60\) nM per hour, so the concentration increases by \(0.50(0.60)=0.30\) nM. If cells evaluate their activation rule after this field update and \(C_{\mathrm{th}}=1.2\) nM, a cell in this region is activated because \(1.3 \ge 1.2\). This calculation assumes a uniform field and a single explicit update; it is not a general spatial solver.

Why Update Order Changes the Result

A short schedule specification prevents a common source of hidden model behavior. Consider two activated cells, A and B, and one admissible candidate position that only one cell can occupy. If the model processes A first and updates occupancy immediately, A moves into the candidate and B remains. If it processes B first, B moves and A remains. A fixed order makes the computation reproducible, but it can create a systematic advantage for cells early in that order. Randomized order may reduce that particular bias, but introduces stochastic scheduling and requires a separate specification of how randomness is generated and used.

A synchronous alternative first computes both movement intentions from the same configuration. Since both cells select the same position, the model must then resolve the conflict—for example, by a stated priority rule or by rejecting both moves. “Update simultaneously” is not a complete rule unless these conflicts are addressed.

Justification: The schedule affects the outcome whenever an earlier update changes information read by a later rule. In the example, moving A changes whether the candidate is admissible for B. Therefore the two possible orders evaluate B under different occupancy states, even though the cells began with identical conditions. If updates do not affect one another’s inputs, reordering them may not matter; otherwise, order is part of the model’s definition.

When the intended biology does not imply a processing order, document the chosen computational convention and test whether conclusions depend on it. A strong sensitivity to arbitrary order can indicate that the time step is too coarse, that the conflict rule dominates the biology, or that the model needs a different representation of movement.

Worked Example: Comparing Sequential and Synchronous Outcomes

In a hypothetical model, two activated cells, A and B, each have the same sole candidate position, P. Only one cell may occupy P. Under a sequential schedule, candidates are checked and occupancy is updated immediately.

A processed first: P is empty, so A moves to P. B is then processed, finds P occupied, and stays. The final occupancy of P is one cell, A.

B processed first: the same reasoning gives a final occupancy of one cell, B. The schedule’s ordering determines which cell moves.

Under a synchronous schedule, both cells select P from the initial configuration. If the stated conflict rule is “reject every move involved in a destination conflict,” neither moves and P remains empty. The different final configurations are not arithmetic errors: they follow from different, explicit scheduling and conflict rules. The example shows why a schedule must be reported alongside the agent-level movement condition.

Diagnostics, Alternatives, and Limitations

Before interpreting results, check whether the rules behave as their definitions imply. Track agent counts, allowed state values, field concentrations, and the number of accepted and rejected moves. For a signal-dependent rule, inspect whether cells just below and above \(C_{\mathrm{th}}\) behave as intended. For an explicit field update, check for negative concentrations or implausibly large step-to-step changes. A negative value is not a biological prediction; it may indicate an unsuitable time step or update method.

  • Threshold ambiguity: Confirm that the comparison is specified as \(>\) or \(\ge\), and use the same units for sampled signal and threshold.
  • Order dependence: Repeat a comparison under a reversed or otherwise altered processing order. Large changes suggest that ordering or conflict resolution is influential.
  • Unintended field timing: Verify whether secretion affects the current response or only a later update, according to the schedule.
  • Invalid destinations: Record why a proposed move is rejected, such as a geometry constraint or an occupied position, instead of treating all rejections as unexplained.

Agent rules are useful when individual identity, local context, or discrete events matter to the question. A continuum model may be a more compact alternative when individual differences and local occupancy are not essential and average spatial densities are sufficient. A hybrid representation can be appropriate when cells must remain individual agents but signals are more naturally represented as fields. These alternatives answer different modeling needs; none is automatically more biologically faithful.

A rule-based model also has limitations. A binary threshold can hide gradual responses, and an assumed candidate ordering can impose behavior not justified by biology. Agent-level detail does not guarantee that parameters can be estimated from available measurements or that predictions are identifiable. Document which rules are biological hypotheses, which are computational conventions, and which are simplifications. The introductory material on representing tissue geometry and microenvironments provides the spatial context; here, the emphasis is on defining what agents and fields do within that context.

Common Mistake

A frequent mistake is to write “each cell moves toward the signal when the signal is high” and treat that sentence as a complete model rule. It leaves unclear whether signal enables movement or sets its direction, what concentration is sampled, how high is defined, and how competing cells are handled. The correction is to separate the rule into explicit pieces: define the signal field and sampling location, state the activation condition and threshold, define candidate positions and admissibility, and specify the schedule and conflict handling. These choices make the model testable and reproducible.

Check Your Understanding

Answer each question, then compare with the brief solutions.

  1. A cell samples \(0.9\) nM and the activation threshold is \(1.0\) nM. Under the rule \(C\ge C_{\mathrm{th}}\), what is its activation state?
  2. Two cells compete for one candidate position under immediate sequential occupancy updates. What additional information is needed to determine the outcome?
  3. In the uniform-field example, what is the net concentration rate when \(C=1.0\) nM, \(N=2\), \(q=0.40\) nM per hour per cell, and \(k=0.20\) per hour?
  4. Why must a model specify whether field secretion is applied before or after cell responses in a time step?
  5. Name one diagnostic for detecting whether movement outcomes depend strongly on the processing order.

Solutions. (1) The cell is inactive, \(A=0\), because \(0.9<1.0\). (2) The processing order and the rule for checking and updating occupancy are needed; whichever cell is processed first may take the position. (3) The net rate is \(Nq-kC=2(0.40)-0.20(1.0)=0.60\) nM per hour. (4) The schedule determines whether newly secreted signal can affect a response in the same step or only a later one. (5) Compare outcomes after reversing or varying the processing order while keeping the initial configuration and rules fixed.

Clinical Biostats