Skip to content

ASSIGN

Sets attributes on a part, order or customer, or a model variable, from expressions as it passes, for example a due date, a type or a counter.

Takes an ordered list of assignments, each is {"target": "entity.<attr>" | "entity.agent.<attr>" | "<variable>", "expr": "<expression>"}.

Assignments run in order, so a later one sees what an earlier one wrote. Targets and expressions both go through core/expressions.py -- a model file never executes Python.

Family: data. Python builder: m.assign(...).

Typical uses

Use ASSIGN to stamp data on an entity or to set a model variable as the entity passes. Typical jobs are a due date, a priority, a product type, a counter or a flag that a later DECIDE reads. It takes no simulated time. To measure something without changing the model, use RECORD. To change a stock, use TRANSFER.

Behaviour and rules

Assignments run in the listed order, so a later one sees what an earlier one wrote. A target entity.<name> sets an attribute of the entity. A target entity.agent.<name> writes a column of the entity's agent. Any other name sets a model variable, which must be declared in variables.

Assigning entity.sequence restarts the entity's routing at step 0. Writing a variable wakes any HOLD that waits on a condition reading it, and updates the levels and agents that depend on it.

A bad target or expression raises an error that names the block and the assignment. The error appears when the first entity reaches the block, not when the file loads, unless a check of the model catches it earlier.

Ports

  • Inputs: any number of incoming links.
  • Outputs: one outgoing link.

Parameters

Parameter Type Default Required Quantity Unit key Description
assignments list [] Ordered list of {"target": "entity."

Statistics

Every run fills system and entity_summary (see the KPI reference). The example below also fills:

Frame Columns
resource_summary Run, Resource, Total Seizes, Usage % (snapshot), Idle %, Scheduled Capacity Avg, Down %, Busy Cost, Idle Cost, Usage Cost, Total Cost, Queue Length Avg, Queue Length Max, Queue Length at End, Queue Length Mode, Queue Length Mode %, Queue Len P95, Queue Len P99, Queue Len Std, Time in Queue Avg, Time in Queue Avg (incl. waiting), Time in Queue Max, Time in Queue Mode, Time in Queue Mode %, Wait P95, Wait P99, Wait Std, Bottleneck Score, Bottleneck %
material_flow_summary Run, From, To, Entities

Problem codes

A check of the model reports these about this block:

Code Meaning
E_ASSIGN_KEY An ASSIGN entry has a key other than target and expr (it would be ignored).
E_ASSIGN_TARGET An ASSIGN target is not a writable entity.<attr> or variable name.
E_SEQUENCE_UNKNOWN A CREATE or ASSIGN names a sequence the model does not declare.
E_UNDECLARED_VARIABLE An expression or ASSIGN target names a variable the model does not declare.

Example

The snippet seeds itself; its output is from a run made when this page was generated.

from nagasim import build as nb

m = nb.Model(time_limit=300)
m.add_resource(name="Press")
arrive = m.create(distribution=nb.Exponential(rate=0.2))
size = m.assign(assignments=[{"target": "entity.size", "expr": "UNIF(1, 3)"}])
press = m.process(resource_name="Press", distribution=nb.Constant(value="entity.size"))
arrive >> size >> press >> m.dispose()

results = m.run(seed=1)
print(round(results.kpi("resource/Press/Usage % (snapshot)"), 1), "% busy; service time is entity.size, 2 on average")
37.1 % busy; service time is entity.size, 2 on average

Used in

Bundled models: Berth: shore power, Biogas plant (library assets), Emergency department: staffing game, Supply line: order-rate management game, Hub day: electrifying the ground support equipment, Container terminal: electrification and 9 more.

Guides: Entities and attributes, Continuous quantities: levels, flows and time-series inputs, Model file format, Expressions and variables, Coming from AnyLogic, Coming from Arena and 5 more.

See also