5.4 Specifying Sugarscape
5.4.3 State
In Z, modularisation is achieved by dividing the specification into schemas. In this case we divided the state into two main separate parts or schemas. The first schema
defines the information held by the lattice component of the simulation and the sec- ond schema defines the information held by the agents in the simulation. Although Lattice locations could also be viewed as a type of agent this division makes the state easier to comprehend and serves a useful purpose as some operations (known as rules or behaviours in Sugarscape terminology) act only on one of these two schemas (for example, the Growback rule/operation only affects the lattice and not the agents on the lattice).
The Lattice Schema
The Lattice is an M ×M grid or matrix of locations where each location contains an amount of sugar3and pollution. Each location can hold up to a maximum amount of sugar where this maximum amount can vary from location to location.
We can see that a schema has two parts. The top part is where the variables defining the state are declared. The bottom part lists all the invariant properties that the schema enforces.
Lattice
sugar : P OSIT ION → N (1)
maxSugar : P OSIT ION → N (2)
pollution : P OSIT ION → N (3)
∀ x : P OSIT ION • sugar(x) ≤ maxSugar(x) ≤ M AXSU GAR(4)
Taking each part of the schema in turn:
1. sugar is a mapping that stores the amount of sugar stored at each position in the lattice;
2. maxSugar is a mapping that records the maximum amount of sugar that can be stored in (carried by) each position;
3. pollution records the amount of pollution at each location;
4. This is the only invariant. It states that every position’s sugar level is less than or equal to the maximum allowed amount for that position which is in turn less than or equal to the M AXSU GAR constant;
3
Each function in the Lattice schema is a total function. Different types of function such as Total, Partial, Injective, etc. are defined within Z and each has its own symbol. Because they are total functions it is implictly implied that every position has a sugar level, a maximum level and a pollution amount.
The different function types are defined as follows:
X 7→ Y - Partial function: some members of X are paired with a member of Y
X → Y - Total function: every member of X is paired with a member of Y
X 7 Y - Partial injection: some members of X are paired with different members of Y X Y - Total injection: every member of X is paired with a different member of Y X → Y - Bijection: every member of X is paired with a different member of Y ,
covering all Y ’s The Agent Schema
The agent schema is more complex due to the amount of information held by each agent. The attributes that every agent has are:
Position Where the agent currently resides on the Lattice;
Vision How far in the four cardinal directions that an agent can see; Age Number of turns of the simulation that an agent has been alive;
Maximum Age Age at which an agent dies (assuming it has not being killed pre- viously by combat or starvation);
Sex Agents are either male or female;
Sugar Level The amount of sugar that an agent currently holds. There is no limit to how much sugar an agent can hold;
Metabolism The amount of energy, defined by sugar (or resource) consumption, used during every turn of the simulation;
Culture Tags A sequence of bits that represents the culture of an agent;
Children For each agent we track its children (if any). This is necessary as the Inheritancerule requires that we track each agent’s children;
Loans Under the credit rule agents are allowed lend and/or borrow sugar for set durations and interest rates so we need to track these loans. For each loan we need to know the lender, the borrower, the loan principal and the due date (represented as the step number);
Diseases Diseases are sequences of bits that can be passed between agents. An agent may carry more than one disease;
Immunity Each agent has an associated bit sequence that confers immunity against certain diseases. If the bit sequence representing a disease is a subsequence of an agents immunity bit sequence then that agent is considered immune to that disease.
We have listed here the full range of agent attributes. In practice we may only need to use a subset of these depending on which subset of rules we are implement- ing in our simulation. For example, Disease and Immunity attributes are required only if we are implementing the Disease rule so any simulation not using this rule will be simplified by not modelling these attributes.
Agents
population : P AGEN T
position : AGEN T 7 P OSIT ION sex : AGEN T 7→ SEX
vision : AGEN T 7→ N1
age : AGEN T 7→ N
maxAge : AGEN T 7→ N1
metabolism : AGEN T 7→ N agentSugar : AGEN T 7→ N
agentCulture : AGEN T 7→ seq BIT children : AGEN T 7→ P AGEN T
loanBook : AGEN T ↔ (AGEN T × (N, N)) agentImmunity : AGEN T 7→ seq BIT diseases : AGEN T 7→ P seq BIT population =
dom position = dom sex = dom vision
= dom maxAge = dom agentSugar = dom children = dom agentCulture = dom metabolism = dom age
= dom agentImmunity = dom diseases (1)
dom loanBook ⊆ population (2)
dom(ran loanBook) ⊆ population (3)
∀ x : AGEN T ; d : seq BIT •
x ∈ population ⇒ (4)
((age(x) ≤ maxAge(x) ∧ M IN AGE ≤ maxAge(x) ≤ M AXAGE ∧ # agentCulture(x) = CU LT U RECOU N T
∧ # agentImmunity(x) = IM M U N IT Y LEN GT H ∧ vision(x) ≤ M AXV ISION
∧ M IN M ET ABOLISM ≤ metabolism(x) ≤ M AXM ET ABOLISM )
d ∈ ran diseases(x) ⇒ # d < IM U N IT Y LEN GT H (5)
1. Every existing agent has an associated age, sex, vision, etc. Note that the population holds only the currently existing agent IDs. Once an agent dies it is no longer modelled and no longer part of the population;
3. Only agents that are alive (current members of the population) can be bor- rowers
4. For every agent in the population:
(a) It has a current age less than the maximum allowed age for that agent and this maximum age is less than or equal to the globally defined M AXAGE constant;
(b) Metabolism is always between the allowed limits and vision less than or equal to the maximum vision;
(c) The sequence of bits representing its culture tags is CU LT U RECOU N T in size while the string representing immunity is IM M U N IT Y LEN GT H in size.
5. All diseases are represented by sequences of bits that are shorter than the length of the immunity sequence.
We need to track the number of turns that have occurred in the simulation. Each turn consists of the application of all rules that form part of the simulation. This is specified in the simple Step schema. In this schema the variable step contains the current simulation step count.
Step step : N
The entire simulation consists of locations, agents and the counter holding the tick count. We combine them all in the schema SugarScape. This defines the entire state as consisting of both the agents state, the lattice state and a count indi- cating how many steps have been taken so far in the simulation. We note here that the inclusion of a schema name is taken to be shorthand for including all of that schema (both definitions and invariants). This schema contains every part of the three achemas: Step, Lattice and Agents.
SugarScape Agents Lattice Step