aa r X i v : . [ c s . M A ] N ov THE SPECIFICATION OF SUGARSCAPE
JOSEPH KEHOE
Abstract.
Sugarscape is a well known and influential Agent Based Social Sim-ulation (ABSS). Various parts of Sugarscape are supplied as examples in almostall Agent Based Model (ABM) toolkits. It has been used for demonstratingthe applicability of different approaches to ABM. However a lack of agreementon the precise definition of the rules within Sugarscape has curtailed its useful-ness. We provide a formal specification of Sugarscape using the Z specificationlanguage. This demonstrates the ability of formal specification to capture thedefinition of an ABM in a precise manner. It shows that formal specificationscould be used as an approach to tackle the replication problem in the field ofABM. It also provides the first clear interpretation of Sugarscape identifyingareas where information is missing and/or ambiguous. This enables researchersto make proper comparisons between different implementations of this model. Introduction
Overview.
First we give an short informal summary of Sugarscape. Wefollow with a brief introduction to formal specification. We then specify the singleresource simulation. Following the standard Z patterns of development we listthe basic types and constants first, followed by the specification of the basic stateattributes and invariant properties. Then the rules are presented in order.After this we present the extended specification, that is the specification withtwo resources. Here we highlight the differences between the single resource andtwo resource specifications by presenting the specifications in bold face wheneverthe specification changes from the original.2.
Sugarscape
Agent Based social Simulations.
Sugarscape was the first large scaleAgent Based Social Simulation (ABSS). It was developed by Epstein and Axtelland presented in their book
Growing Artificial Societies [Epstein and Axtell, 1996].The release of this simulation is considered an important event in the emergingfield of Agent Based Social Simulation.The Sugarscape ABSS was used to investigate how individual behaviour caninfluence and cause different social dynamics within large populations. It has beenused to show how, for example, inheritance of wealth affects resource distribution
Date : 9/03/2015. in populations and how disease can spread through a population. It remains influ-ential today and every major simulation toolkit (Swarm, Repast, Mason and Net-Logo) [Railsback et al., 2006, Berryman, 2008, Inchiosa and Parker, 2002] comeswith a partial implementation of Sugarscape that demonstrates that toolkit’s ap-proach to simulation. Since Sugarscape first appeared ABSSs have been appliedto fields as diverse as Anthropology[Campillo et al., 2012], Biomedical Science,Ecology, Social Science [Axtell and Axtell, 2000], Epidemic modelling and MarketAnalysis[Macal and North, 2009, Troitzsch, 2009, Gilbert, 2004].ABSS’s employs a bottom-up approach to modelling populations. Instead of pre-computing the overall population behaviour, as done in equation based models,individual agents and their local interactions within the population are modelled.The behaviour of the overall population is left to emerge from these local inter-actions. This approach allows us to address failings in the top-down approachand demonstrates the causal factors behind the emergence of group dynamics. Incases where we do not know what the overall behaviour will be or where we aretrying to find out the causes of this behaviour, bottom-up based ABSSs are theonly possible approach.2.2.
Issues with Sugarscape.
Currently, social science simulations are start-ing to embrace concurrency in an effort to allow for bigger, more complete andfaster implementations of ABMs. Different concurrency researchers have used theSugarscape model as a testbed for benchmarking different approaches to parallelis-ing ABMs [Lysenko and D’Souza, 2008, Perumalla, 2006, Richmond et al., 2010].However although the rules of Sugarscape have been defined there is no generalagreement on their exact meaning. These difficulties hamper the ability of re-searchers both to properly compare their approaches, provide complete implemen-tations of Sugarscape or replicate their results.Most of the rules require some form of conflict resolution. We have specifiedthe rules in a manner consistent with the original intention (agents acting con-currently) but independent of any particular approach to how this concurrencyis implemented. That is, we have refrained from imposing any specific conflictresolution rules.By formalising Sugarscape and providing a single precisely defined reference forthe rules we can produce a standard definition of Sugarscape. Compliance withthis single reference will allow proper comparisons to be made between differentapproaches. It also leaves it open to the implementer to decide what approach toconflict resolution they wish to take. We detected ambiguities present in the cur-rent rule definitions, provided precise interpretations, where possible, and flaggedirresolvable problems where not.We made the decision to restrict the initial specification to one pollution typeand one resource type in an effort to guarantee clarity. While the rules weredesigned so that they could be extended to arbitrary numbers of resources andpollutants, explicitly specifying for an arbitrary number of resources and pollutants
HE SPECIFICATION OF SUGARSCAPE 3 would make the specification even more difficult to understand and thus more likelyto either contain or cause mistakes.Once we had a specification for the single resource scenario we extended thespecification to a two resource situation. This allowed us to specify the final rule,
T rade , as that rule requires two resources to function.This allowed for:(1) A simpler and easier to understand specification of the rules that use onlyone resource (trading clarity against completeness);(2) A complete (but separate) specification for simulations that use two re-sources.We do not provide specifications for multiple pollutants as multiple pollutants werenever actually implemented in Sugarscape .Similarly we did not provide a specification for more than two resources as wedeem the benefits of doing so counterbalanced by both the complexity of the result-ing specification and the lack of any requirement to use such a complex simulationfor benchmarking purposes. Sugarscape has only ever been implemented with tworesources types, known respectively as sugar and spice . Anyone wishing to extendSugarscape further can use the two resource specification for guidance.2.3. Synchronous and Asynchronous Updating.
Originally the rules werestated with an explicit assumption that the underlying implementation would besequential. Concurrency was simulated through randomisation of the order of eachrule application on the individual agents, and models that follow this regime aretermed asynchronous.All results reported here have been produced by running the modelon a serial computer; therefore only one agent is“active” at anyinstant. In principle the model could be run on parallel hardware,permitting agents to move simultaneously (although M would haveto be supplemented with a conflict resolution rule to handle cases inwhich two or more agents simultaneously decide to inhabit the samesite).[Footnote 12, Chapter II]The alternative to asynchronous updating is synchronous updating. Synchro-nous updating assumes that all updates occur concurrently. While it is clear thatthe original authors have no objection to employing synchronous updating on sug-arscape it is well known that asynchronous and synchronous updating producedifferent results. What is not known is how divergent these results are in thecase of complex ABMs such as Sugarscape or indeed how to apply synchronousupdating to all the complex interaction types in Sugarscape. We leave this open as an exercise for the reader.
JOSEPH KEHOE
In order to answer these questions we present initially a specification that as-sumes a synchronous updating regime, as this is the most novel approach. Follow-ing this we give the equivalent Asynchronous updating version for comparison.3.
Single Resource Sugarscape
Sugarscape is a discrete turn based simulation composed of a set of interactingagents that move across an environment. The environment, or simulation space, ismodelled as a two dimensional M by M grid or matrix of discrete locations knownas the lattice . This lattice is toroidal in nature, that is, it wraps around on all fouredges. Every lattice location has a position denoted by its x and y coordinates.For any lattice location [i, j] there are four direct (von Neumann) neighbours (up,down, left and right) at positions [ i, ( j + 1)% M ] , [ i, ( j − M ] , [( i − M, j ] and[( i + 1)% M, j ]. We denote this set of von Neumann neighbours as N ( i, j ), andfurther use N k ( i, j ) to denote the set of von Neumann neighbours where each is amaximum distance of k locations from the location [i,j].Each location can hold a number of resource and pollution types. While there isno limit placed on how many resource or pollution types can exist in a Sugarscapesimulation we are unaware of any Sugarscape derived simulation that uses morethan two resource types and one pollution type. When there is only one resourcetype it is called sugar and if there are two then the second resource is known as spice . These amounts are measured as natural numbers ( ≥ Metabolism Rate (one per resource type):
The rate at which an agentsresource stores decrease during each simulation step. Different resourcetypes have independent metabolism rates. Once an agent runs out of re-sources it dies (is removed from the simulation);
Age:
The number of steps that the agent has been present in the simulation;
Maximum Age:
The maximum number of steps that an agent is allowed toexist during the simulation run. Once an agent reaches its maximum ageit is removed from the simulation;
Resource Store (one for each resource type):
The amount of each re-source that the agent currently has;
Vision:
How far in each of the cardinal directions that the agent can see.An agent can only interact with locations and agents that are in its neigh-bourhood N vision . To ensure locality all agent values for vision will be less HE SPECIFICATION OF SUGARSCAPE 5 than some predefined maximum and this maximum will be much smallerthan the lattice dimension size ( M ).In the more complex versions of Sugarscape agents can also have a “culture”identifier (identifying which tribe the agent belongs to), a set of outstanding loansof resources that the agent has given to (or received from) other agents, a set ofdiseases that the agent has contracted and, an immunity system that gives eachagent immunity from certain diseases.A simulation run consist of a series of turns or steps during which certain rulesare applied to each location and agent. Each rule is applied concurrently andinstantaneously to each agent and/or location. The rules are generally fairly simpleand the only information that an agent (or location) can use when deciding howto apply a rule is local information, that is an agent or location at position [i,j]can only access information from locations and/or agents that are within the set N k , where k ≤ vision (in most cases k=1).The rules for locations decide how resources are replenished and how pollutionis created or spread. The rules for agents are more varied and determine agentmovement and interaction. Agent interaction can range from spreading disease,trading, entering financial agreements and even combat. There are a large numberof rules but not all rules need to be (or indeed can be) applied in the same simula-tion run. The rules are chosen based on what we wish to model. A simulation thatwishes to see the effect of trading on wealth distribution would have no need forthe combat or culture rules while one modelling disease transmission would onlyrequire the movement and disease transmission rules.3.1. Basic Types and Constants.
First we identify the basic types and anyrequired constants. Many are self explanatory or will become clear when theirassociated rules are specified. A simulation is defined by the values given to theseconstants and the combination of rules employed.
JOSEPH KEHOE M : N (1) CU LT U RECOU N T : N (2) M AXV ISION : N (3) M IN M ET ABOLISM, M AXM ET ABOLISM : N (4) SU GARGROW T H : N (5) M AXAGE, M IN AGE : N (6) M AXSU GAR : N (7) DU RAT ION : N (8 a ) RAT E : A (8 b ) IN IT IALSU GARM IN, IN IT IALSU GARM AX : N (9) W IN T ERRAT E, SEASON LEN GT H : N (10) P RODU CT ION, CON SU M P T ION : N (11) COM BAT LIM IT : N (12) IM M U N IT Y LEN GT H : N (13) IN IT IALP OP U LAT ION SIZE : N (14) P OLLU T ION RAT E : N (15) CHILDAM T : N (16) CU LT U RECOU N T mod 2 = 1
M IN M ET ABOLISM < M AXM ET ABOLISMM AXAGE < M IN AGEM AXV ISION < MIN IT IALSU GARM IN < IN IT IALSU GARM AXIN IT IALP OP U LAT ION SIZE ≤ M ∗ M (1) The simulation space is represented by a two dimensional M by M matrixof locations. Each location in the simulation space is referenced by twoindices representing its position in this matrix;(2) CU LT U RECOU N T determines the size of the bit sequence used to rep-resent cultural allegiances. This is always equal to an odd number so thatthe number of 1’s in the sequence is never equal to the number of 0’s;(3) Agents can only “see” in the four cardinal directions, that is the locations tothe north, south, east and west. Agents are endowed with a random visionstrength that indicates how many locations the can “see” in each direction.This endowment is always less than
M AXV ISION and
M AXV ISION is always less than M ;(4) Agents consume an amount of sugar (resources) during each turn. Thissugar represents the amount of energy required to live. Each agent is en-dowed, on creation, with a random metabolism between M IN M ET ABOLISM and
M AXM ET ABOLISM ;(5) Agents consume sugar (resources) from the location they occupy. Eachlocation can renew its sugar at a rate determined by
SU GARGROW T H . HE SPECIFICATION OF SUGARSCAPE 7
After each turn up to a maximum of
SU GARGROW T H units of sugarare added to each location (in accordance with the
Growback rule);(6)
M AXAGE and
M IN AGE are, respectively, the maximum and minimumallowable lifespan for any agent;(7)
M AXSU GAR is the maximum amount of sugar that any location canpossibly hold. This is known as the carrying capacity of a location;(8)
RAT E and
DU RAT ION are used for determining the rate of interestcharged for loans and the duration of a loan;(9)
IN IT IALSU GARM IN and
IN IT IALSU GARM AX are the lower andupper limits for initial endowment of sugar given to a newly created agent;(10) If seasons are enabled then two seasons, winter and summer are allowedwith a duration of
SEASON LEN GT H turns (ticks) and a new separatelower seasonal grow back rate calculated using
W IN T ERRAT E (as de-termined by the
SeasonalGrowback rule);(11) Pollution can occur at a rate determined by the production and consump-tion of resources determined by the
P RODU CT ION and
CON SU M P T ION constants respectively;(12) The combat rule posits the maximum reward
COM BAT LIM IT that canbe given to an agent through killing another agent;(13) Immunity in agents is represented using a fixed size sequence of bits oflength
IM M U N IT Y LEN GT H ;(14) We have some predetermined initial population size
IN IT IALP OP U LAT ION SIZE that is used to initialise the simulation;(15)
P OLLU T ION RAT E determines the number of steps that elapse beforepollution levels diffuse to their neighbours;(16) A certain amount of sugar reserves,
CHILDAM T , are required for anagent to have children.[
AGEN T ] (1)
P OSIT ION == 0 . . M − × . . M − SEX ::= male | f emale (3) BIT ::= 0 | af f iliation ::= red | blue (5) boolean ::= true | f alse (1) AGEN T is used as a unique identifier for agents;(2)
P OSIT ION is also used to make specifying indices within the grid so asto make the schemas easier to read and more compact;(3) All agents have a sex attribute;(4)
BIT s are used to encode both culture preferences and diseases of agents;
JOSEPH KEHOE (5) Every agent has a cultural affiliation of either belonging to the blue tribeor red tribe.Agents can, using the Mating rule, have offspring if they are fertile. Fertility isdetermined by the age of the agent, where fertility starts at some predefined ageand ends at another. These boundaries are defined for all agents. The numbersare set out by Epstein and Axtelland although there appears to be no special sig-nificance attached to these numbers we will stick with the originals. Male fertilityends 10 turns later than female fertility.
F EM ALEF ERT ILIT Y ST ART, F EM ALEF ERT ILIT Y EN D : N M ALEF ERT ILIT Y ST ART, M ALEF ERT ILIT Y EN D : N ≤ F EM ALEF ERT ILIT Y ST ART ≤ ≤ F EM ALEF ERT ILIT Y EN D ≤ ≤ M ALEF ERT ILIT Y ST ART ≤ ≤ M ALEF ERT ILIT Y EN D ≤ M ALEF ERT ILIT Y EN D = F EM ALEF ERT ILIT Y EN D + 10The replacement rule requires a sugar allocation be given to new agents setbetween 5 and 25. Again there appears to be no special significance attached tothese numbers.
ST ART SU GARM IN, ST ART SU GARM AX : N ST ART SU GARM IN = 5
ST ART SU GARM AX = 253.2.
The Sugarspace Lattice.
The simulation space in Sugarscape consists ofa finite discrete two-dimensional array of locations. Each location is identified itsrow and column value. Each location contains a number of resources. While onlytwo resources are ever used it is clear that the intention of the original authors wasthat the simulation could be extended so that any number of different resourcescan be present.Similarly each location can contain a number of pollutant levels. In practice,although the rule is explicitly defined for an arbitrary number of pollution typesonly one is ever used. Again, in line with actual Sugarscape usage and to makethe specification more readable we assume only one pollution type. Pollutionfluxes are used in the rules to help calculate how pollution levels change overtime. Although explicitly referenced in the Pollution rule these do not need to beexplicitly modelled in the specification.
HE SPECIFICATION OF SUGARSCAPE 9
Latticesugar : P OSIT ION N (1) maxSugar : P OSIT ION N (2) pollution : P OSIT ION N (3)dom sugar = dom maxSugar = dom pollution = P OSIT ION (4) ∀ x : P OSIT ION • sugar ( x ) ≤ maxSugar ( x ) ≤ M AXSU GAR (5)(1) sugar is a mapping that stores the amount of sugar stored at each position;(2) maxSugar is a mapping that records the maximum amount of sugar thatcan be stored (carried) in each position;(3) pollution records the amount of pollution at each location;(4) Every position has a sugar level, a maximum allowed sugar level (or carry-ing load) and a pollution level;(5) Every position’s sugar level is less than or equal to the maximum al-lowed amount for that position which is in turn less than or equal to the
M AXSU GAR constant;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.
Stepstep : N Agents.
Every agent is situated on a location within the grid and each lo-cation is capable of containing only one agent at a time (putting an upper limiton the number of possible agents). Agents are mobile, that is they can move toa new location if a suitable unoccupied location is available. Movement is bothdiscrete and instantaneous, it is possible for an agent to move to a new locationinstantly while skipping over all intermediate locations. The attributes that everyagent has are:
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;
Sex:
Agents are either male or female;
Sugar Level:
The amount of sugar that an agent currently holds. There isno limit to how much sugar an agent can hold;
Initial Sugar:
The amount of sugar the agent was initialised with on cre-ation;
Metabolism:
The amount of energy, defined by sugar (or resource) con-sumption, 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). To apply the In-heritance rule the full list of an agents children is required.
Loans:
Under the credit rule agents are allowed lend and/or borrow sugarfor set durations and interest rates so we need to track these loans. Foreach loan we need to know the lender, the borrower, the loan principal andthe 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 immu-nity against certain diseases. If the bit sequence representing a diseaseis a subsequence of an agents immunity bit sequence then that agent isconsidered immune to that disease.
HE SPECIFICATION OF SUGARSCAPE 11
Agentspopulation : P AGEN Tposition : AGEN T P OSIT IONsex : AGEN T SEXvision : AGEN T N age : AGEN T N maxAge : AGEN T N metabolism : AGEN T N agentSugar : AGEN T N initialSugar : AGEN T N agentCulture : AGEN T seq BITchildren : AGEN T P AGEN TloanBook : AGEN T ↔ ( AGEN T × ( N , N )) agentImmunity : AGEN T seq BITdiseases : AGEN T P seq BITpopulation =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, y : AGEN T ; d : seq BIT • x, y ∈ population ∧ x = y ⇒ (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 ∧ position ( x ) = position ( y ) ⇔ x = y ) d ∈ ran diseases ( x ) ⇒ d < IM U N IT Y LEN GT H (1) Every existing agent has an associated age, sex, vision, etc. Note that thepopulation holds only the currently existing agent IDs;(2) Only current members of the population can be lenders;(3) Only current members of the population can be borrowers(4) Every agent in the population is guaranteed to have a current age less thanthe maximum allowed age for that agent, a maximum age less than orequal to the global M AXAGE , a metabolism between the allowed limitsand vision less than or equal to the maximum vision. The sequence of bitsrepresenting its culture tags is
CU LT U RECOU N T in size while thoserepresenting immunity is
IM M U N IT Y LEN GT H in size. All diseases are represented by sequences of bits that are shorter than the immunitysequence.The entire simulation consists of locations, agents and a counter holding the tickcount. We combine them all in the schema
SugarScape . SugarScapeAgentsLatticeStep
The initial state of the schema when the simulation begins must also be stated.
InitialSugarScapeSugarscape ′ step ′ = 0 (1) population ′ = IN IT IALP OP U LAT ION SIZE (2) loanBook ′ = ∅ (3) ∀ a : AGEN T • (4) a ∈ population ′ ⇒ ( age ( a ) = 0 ∧ diseases ′ ( a ) = ∅ ∧ children ′ ( a ) = ∅ ∧ IN IT IALSU GARM IN ≤ agentSugar ′ ( a ) ≤ IN IT IALSU GARM AX ) ∧ initialSugar ′ ( a ) = agentSugar ′ ( a )(1) step is set to zero;(2) The population is set to some initial size;(3) There are no loans as yet;(4) Every agent in the starting population has an age of zero, no diseases orchildren and some initial sugar level within the agreed limits. The otherattributes have random values restricted only by the invariants;3.4. Rules.
There are a number of rules that can be employed in different com-binations to give different simulations. We will quote each rule as laid out in theappendix of [Epstein and Axtell, 1996] and follow, where necessary, with a moredetailed explanation of the rule. In many cases the simple rule definitions are notcomplete. Extra information, embedded in the original text, has been extractedwhere necessary to help complete these rules. The majority of rule definitionsassume only one resource (sugar) and it is these that are specified in this section.The simulation is discrete with each time interval representing one complete setof rule applications. We use the step variable in the
SugarScape schema to keeptrack of the current time interval number.Where there exist ambiguities in the rule definitions we will identify them andpropose one or more possible interpretations consistent with what we believe to
HE SPECIFICATION OF SUGARSCAPE 13 be the authors intentions. Throughout the rule definitions constants such as α, β are used but they have different meanings in each rule. For the sake of clarity wewill give each constant a meaningful and globally unique name.3.5.
Tracking Steps.
While not defined explicitly as a rule, we must ensure thatwe record the current step number. We increment the
Step variable before everysequence of rule applications that compose a single turn of the simulation.There is an issue with metabolism in that every turn of the simulation requiresthat agents use up their sugar reserves at a rate determined by their metabolism.It is not explicitly stated when or where this sugar deduction occurs within therules. It could be placed, for example, in the movement rule but it can also beplaced, just as validly, within any rule that is guaranteed to be applied duringevery turn. Since there is no obvious reason why one is superior to the other, aslong as it is consistently applied, we choose to place the metabolism deductionwithin the
T ick schema. This new rule can be stated simply as follows:
Tick:
At the start of every time interval increase every agents age by oneand decrease every agents sugar level by their metabolism rate.
T ick ∆ Agents ∆ Steppopulation ′ = populationposition ′ = positionsex ′ = sexvision ′ = visionmaxAge ′ = maxAgemetabolism ′ = metabolisminitialSugar ′ = initialSugaragentCulture ′ = agentCulturechildren ′ = childrenloanBook ′ = loanBookagentImmunity ′ = agentImmunitydiseases ′ = diseasesstep ′ = step + 1 (1) ∀ x : AGEN T • x ∈ population ⇒ age ′ ( x ) = age ( x ) + 1 (2) ∧ agentSugar ′ ( x ) = agentSugar ( x ) − metabolism ( x ) (3)(1) Add one to the step count;(2) Increase everyone’s age by one;(3) Decrease everyone’s agentSugar by their metabolism. Sugarscape Growback α .Sugarscape Growback α : At each Lattice position, sugar grows back at arate of α units per time interval up to the capacity at that position.Growback determines the rate at which location resources are replenished. Theinteger constant α indicates the amount by which resources grow during a singlestep or time interval. If α = ∞ then each resource returns to its maximum valueduring each turn, i.e. it is instantly fully replenished after each step. The ruleonly refers to a single resource, sugar , but the book explicitly defines one otherresource spice and it is clear that generalisations allowing an arbitrary number ofresource types to be held at each Lattice position are acceptable.Since we are dealing only with one resource, sugar, we only need to define α forthis resource . The constant SU GARGROW T H represents alpha in this rule andwe use this to update the sugar level of each position.Since the maximum carrying level of each resource cannot be exceeded we willset the resource levels to its maximum value if application of the replenishmentrate would result in a value greater than this maximum. With these definitions wecan express the
Growback rule in a simple manner. The last line in the schema(see below) does the work of updating the resource levels of every location.
Growback ∆ Latticepollution ′ = pollutionmaxSugar ′ = maxSugarsugar ′ = { x : P OSIT ION • x min ( { sugar ( x ) + SU GARGROW T H, maxSugar ( x ) } ) } (1)(1) The new sugar levels are calculated using a simple formula to either,the maximum possible level for that location or the old level plus the SU GARGROW T H whichever is the smaller.3.7.
Seasonal Growback S α,β,γ .Seasonal Growback S α,β,γ : Initially it is summer in the top, half of theSugarscape and winter in the bottom half. Then every γ time periods theseasons flip - in the region where it was summer it becomes winter and viceversa. For each site, if the season is summer then sugar grows back at arate of α units per time interval; if the season is winter then the grow backrate is α units per β time intervals.Seasonal growback is an alternative to the previous grow back rule. Which ruleis chosen will depend on what the simulation is trying to demonstrate. Seasonalgrow back allow us to introduce seasonal factors into the original Growback rule.There are two seasons (representing summer and winter) and each lasts γ turns HE SPECIFICATION OF SUGARSCAPE 15 before switching. We rename γ to SEASON LEN GT H . α is the summer season SU GARGROW T H rate and α/β is the winter season rate. We use the existing
SU GARGROW T H to hold the summer rate and introduce
W IN T ERRAT E as β . Determining what season it is during a turn is fairly trivial. When seasonLength divides into the Step variable evenly it is summer in the top half and winter in thebottom half (and vice versa).
SeasonalGrowback ∆ Lattice Ξ Steppollution ′ = pollutionmaxSugar ′ = maxSugar ∀ x : P OSIT ION • ( step div SEASON LEN GT H ) mod 2 = 0 ⇒ sugar ′ = (1) { x : P OSIT ION | f irst ( x ) < M div 2 • x min ( { sugar ( x ) + SU GARGROW T H, maxSugar ( x ) } ) } (1 a ) ∪{ x : P OSIT ION | f irst ( x ) ≥ M div 2 • (1 b ) x min ( { sugar ( x ) + SU GARGROW T H div
W IN T ERRAT E, maxSugar ( x ) } ) } ( step div SEASON LEN GT H ) mod 2 = 0 ⇒ sugar ′ = (2) { x : P OSIT ION | f irst ( x ) < M div 2 • x min ( { sugar ( x ) + SU GARGROW T H div
W IN T ERRAT E, maxSugar ( x ) } ) } (2 a ) ∪{ x : P OSIT ION ; y : N | f irst ( x ) ≥ M div 2 • x min ( { sugar ( x ) + SU GARGROW T H, maxSugar ( x ) } ) } (2 b )(1) If the season is summer then:a) Top half of grid is updated as normal;b) Bottom half is updated at winter rate.(2) Otherwise if it is winter:a) Top half of grid is updated at winter rate;b) Bottom half is updated as normal.3.8. Movement - M .Movement - M : • Look out as far as vision permits in each of the four lattice directions,north, south, east and west; • Considering only unoccupied lattice positions, find the nearest positionproducing maximum welfare; • Move to the new position • Collect all resources at that location
The previous rules affected only the locations but the remaining rules affectagents as well as locations. The Movement rule determines how agents selecttheir next location. There are a number of different versions of this rule. We willspecify the simplest rule first as it is the only movement rule explicitly defined inthe appendix but we will also specify the other movement rules defined in the text.We add a subscript to the rule title ( M basic ) to distinguish between the differentmovement rule specifications.Not explicitly stated within the rule but stated as a footnote to the rule is therestriction that the order in which the lattice directions are searched should berandom. This comes into play when two or more available sites exist with thesame welfare score.This rule does not guarantee that an agent will move to the best location.To see why this is the case consider what happens if two agents both try tomove to the same location. Only one can succeed and the other will have tomove to a less advantageous location. How we decide which agent succeeds isnot defined. We assume that either a conflict resolution or conflict avoidance ruleis available to make this decision but it is not stated what this rule should be.The original implementation is sequential with agents assumed to be moving ina random order thus enforcing collision avoidance. No guidance is provided forconcurrent implementations.To help make the specification clear we define some simple helper functions.The distance between two positions is only defined for positions that are directlyhorizontal or vertical to each other. This function must take into account thetorus-like (wrap around) structure of the simulation. distance : P OSIT ION × P OSIT ION → N ∀ x , x , y , y N • distance (( x , y , ( x , y min ( {| y − y | , M − | y − y |} ) distance (( x , y , ( x , y min ( {| x − x | , M − | x − x |} ) distance (( x , y , ( x , y ∞ ⇔ x = x ∧ y = y HE SPECIFICATION OF SUGARSCAPE 17
We use this to define the adjacent function that lets us know if two agents aredirectly beside each other. adjacent : P OSIT ION × P OSIT ION → boolean ∀ a, b : P OSIT ION • adjacent ( a, b ) ⇔ distance ( a, b ) = 1 visibleAgents takes an agent, a function mapping agents to positions and thevision range of the agent and returns the set of agents that are within that agent’sneighbourhood. visibleAgents : AGEN T × ( AGEN T P OSIT ION ) × N F AGEN T ∀ agent : AGEN T ; pos : AGEN T P OSIT ION ; range : N • visibleAgents ( agent, pos, range ) = { ag : AGEN T | ag ∈ dom pos ∧ ≤ distance ( pos ( ag ) , pos ( agent )) ≤ range } M ovement basic ∆ SugarScapestep ′ = steppopulation ′ = populationmaxSugar ′ = maxSugarpollution ′ = pollutionsex ′ = sexvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentCulture ′ = agentCultureloanBook ′ = loanBookdiseases ′ = diseasesagentImmunity ′ = agentImmunitychildren ′ = childrenmetabolism ′ = metabolisminitialSugar ′ = initialSugar ∀ a : AGEN T ; l : P OSIT ION • a ∈ population ′ ⇒ (1) distance ( position ′ ( a ) , position ( a )) ≤ vision ( a )( distance ( position ( a ) , l ) ≤ vision ( a ) ∧ ( l ran position ′ )) ⇒ (2) sugar ( l ) ≤ sugar ( position ′ ( a )) (2 a ) ∧ ( distance ( l, position ( a )) < distance ( position ′ ( a ) , position ( a ))) (2 b ) ⇒ sugar ( l ) < sugar ( position ′ ( a )) agentSugar ′ = {∀ a : AGEN T | a ∈ population ′ • a agentSugar ( a ) + sugar ( position ′ ( a )) } (3) sugar ′ = sugar ⊕ {∀ l : P OSIT ION | l ∈ ran position ′ • l } (4)After the rule is applied the following will be the case for every agent:(1) They will be located within one of the locations in their original neighbour-hood (possibly the same position as before);(2) After every agent has moved:a) There will exist no remaining available locations from the original neigh-bourhood of an agent that would have given a better welfare score thanthe location that agent now inhabits (we picked the maximum reward);b) If there was more than one location with maximum reward then theagent moved to the closest location.(3) Agent sugar levels increase because they consume all the sugar at their newlocation (even if the new location is the same as their old location); HE SPECIFICATION OF SUGARSCAPE 19 (4) Location sugar levels are set to zero everywhere there is an agent present.The specification states what is true after the application of the rule but not howwe achieve that state. In any implementation some conflict resolution strategy willbe needed but in this specification we remain agnostic as to what it should be.The rule is well stated but requires that we precisely define welf are . For a singleresource simulation welfare is precisely equal to the amount of sugar available ata location. We will define welfare for multiple resource simulations later.3.9.
Pollution Formation P Π ,χ .Pollution Formation P α,β : When sugar quantity s is gathered from theSugarscape, an amount of production pollution is gathered in quantity αs .When sugar amount m is consumed (metabolised), consumption pollutionis generated according to βm . The total pollution on a site at time t , p t ,is the sum of the pollution present at the previous time, plus the pollutionresulting from production and consumption activities, that is, p t = p t − + αs + βm .This single resource pollution rule is easiest to understand and the most commonform of the pollution rule. When pollution is incorporated into the Sugarscape themovement rule is changed so that the welfare of a location is now defined usingthe sugar to pollution ratio - the greater the ratio the greater the welfare. Thisratio is defined as sugar/ (1 + pollution ) where the “plus one” prevents division byzero.As the pollution rule requires that we know both the sugar consumed and sugarmetabolised during the last move of an agent to that location it is simpler toincorporate the P ollutionF ormation rule into the movement rule. The alternativeis to track the sugar consumed during each move which would require anotherattribute defined in the
Agent schema.
M ovement pollution ∆ SugarScapestep ′ = stepmaxSugar ′ = maxSugarsex ′ = sexpopulation ′ = populationvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentCulture ′ = agentCultureloanBook ′ = loanBookchildren ′ = childrenagentImmunity ′ = agentImmunitydiseases ′ = diseasesmetabolism ′ = metabolisminitialSugar ′ = initialSugar ∀ a : AGEN T ; l : P OSIT ION • a ∈ population ′ ⇒ distance ( position ′ ( a ) , position ( a )) ≤ vision ( a )( distance ( position ( a ) , l ) ≤ vision ( a ) ∧ ( l ran position ′ )) ⇒ [ sugar ( l ) / (1 + pollution ( l ))] ≤ [ sugar ( position ′ ( a )) / (1 + pollution ( position ′ ( a )))] (1) ∧ ( distance ( l, position ( a )) < distance ( position ′ ( a ) , position ( a ))) ⇒ sugar ( l ) / (1 + pollution ( l )) < sugar ( position ′ ( a )) / (1 + pollution ( position ′ ( a ))) sugar ′ = sugar ⊕ {∀ l : P OSIT ION | l ∈ ran position ′ • l } agentSugar ′ = {∀ a : AGEN T | a ∈ population • a agentSugar ( a ) + sugar ( position ′ ( a )) } pollution ′ = pollution ⊕ {∀ l : P OSIT ION ; x : AGEN T | position ′ ( x ) = l • l ( P RODU CT ION ∗ sugar ( l ) + CON SU M P T ION ∗ metabolism ( x )) } (2)(1) We use our new formula to calculate the desirability of a location;(2) The new pollution value for any location that an agent is present at iscalculated as per rule definition.The rule as stated in the appendix is the generalised rule defined for an arbitrarynumber of pollutants and resources. We have specified the simpler version as itis easier to grasp. The more complex version has not been used in any of theSugarscape simulations. We state the generalised rule below for completeness butdo not present a formal specification of it. HE SPECIFICATION OF SUGARSCAPE 21
Pollution Formation P Π ,χ : For n resources and m pollutants, when n-dimensional resource vector r is gathered from the Sugarscape the m-dimensional pollution production vector p is produced according to p = Πr ,where Π is an m × n matrix; when n-dimensional (metabolism) vector m isconsumed then m-dimensional consumption pollution vector c is producedaccording to c = χ m , where χ is an m × n matrix.3.10. Pollution Diffusion D α .Pollution Diffusion D α : • Each α time periods and at each site, compute the pollution flux theaverage pollution level over all its von Neumann neighbouring sites; • Each site’s flux becomes its new pollution level.This rule determines how pollution diffuses over grid. Pollution diffusion iscalculated every α turns and is computed as the average pollution level of all thelocations von Neumann neighbours. We use the constant P OLLU T ION RAT E in place of alpha .The von Neumann neighbours of a location are those immediately above, below,left and right of the current locations (aka north, south, east and west). We definethe four cardinal directions taking into account to fact that the grid wraps aroundat its edges (i.e. it is a torus). north : P OSIT ION → P OSIT IONsouth : P OSIT ION → P OSIT IONeast : P OSIT ION → P OSIT IONwest : P OSIT ION → P OSIT ION ∀ x, y : N • west (( x, y )) = (( x −
1) mod
M, y ) east (( x, y )) = (( x + 1) mod M, y ) south (( x, y )) = ( x, ( y −
1) mod M ) north (( x, y )) = ( x, ( y + 1) mod M )We use this to define a function that returns true if two agents are von Neumannneighbours. It takes as parameters the two agents and a function that maps eachagent onto their location in the simulation. vonN eumanN eighbour : ( AGEN T × AGEN T × ( AGEN T P OSIT ION )) → boolean ∀ a, b : AGEN T ; position : AGEN T P OSIT ION • vonN eumanN eighbour ( a, b, position ) ⇔ position ( a ) = north ( position ( b )) ∨ position ( a ) = south ( position ( b )) ∨ position ( a ) = east ( position ( b )) ∨ position ( a ) = west ( position ( b )) P ollutionDif f usion ∆ Lattice Ξ StepmaxSugar ′ = maxSugarsugar ′ = sugar ( step mod P OLLU T ION RAT E = 0) ⇒ pollution ′ = pollution ( step mod P OLLU T ION RAT E = 0) ⇒ pollution ′ = {∀ l : P OSIT ION • l ( pollution ( north ( l )) + pollution ( south ( l ))+ pollution ( east ( l )) + pollution ( west ( l ))) div 4 } The
P ollution Dif f usion
Rule can be simplified slightly, by removing the re-dundant mention of f lux . Pollution Diffusion D α : After every α time periods and at each location,the average pollution level over all a site’s von Neumann neighbouringlocations becomes its new pollution level.3.11. Replacement - R [ a,b ] .Replacement - R [ a,b ] : When an agent dies it is replaced by an agent of age0 having random genetic attributes, random position on the Sugarscape,random initial endowment, and a maximum age selected from the range[a,b].The two constants a and b we have defined already as LOW ERAGELIM IT and
U P P ERAGELIM IT and we assume that the range is inclusive. It is not statedwhether the new agents immediately consume the resources at the location they areplaced in. We assume they do not, but accept that the alternative interpretation isequally valid. Although not part of the rule definition in the appendix it is statedelsewhere in the book that new agents will have initial resource levels set between5 and 25. We have defined
ST ART SU GARM IN and
ST ART SU GARM AX forthis purpose.Although the simulation can be run without employing the replacement rule (inan effort, for example, to determine the total carrying load - maximum tolerable
HE SPECIFICATION OF SUGARSCAPE 23 population of agents - of a simulation space) there is no stated separate death rule.We will first add a schema that defines “death” explicitly to ensure consistency.
Death :
When an agent reaches its maximum allowed age or runs out ofresources it is removed from the simulation and all its associated loans(either as borrower or lender) are considered void.
Death ∆ Agentspopulation ′ = population \{ a : AGEN T | age ( a ) = maxAge ( a ) ∨ agentSugar ( a ) = 0 } (1) loanBook ′ = population ′ ⊳ loanBook ⊲ (2) { x : AGEN T × ( N × N ) | f irst ( x ) ∈ population ′ }∀ a : AGEN T • (3) a ∈ population ′ ⇒ ( sex ( a ) = sex ′ ( a ) ∧ vision ( a ) = vision ′ ( a ) ∧ maxAge ( a ) = maxAge ′ ( a ) ∧ agentCulture ( a ) = agentCulture ′ ( a ) ∧ position ( a ) = position ′ ( a ) ∧ age ( a ) = age ′ ( a ) ∧ agentSugar ( a ) = agentSugar ′ ( a ) ∧ metabolism ′ ( a ) = metabolism ( a ) ∧ diseases ′ ( a ) = diseases ( a ) ∧ agentImmunity ′ ( a ) = agentImmunity ( a ) ∧ children ′ ( a ) = children ( a )) ∧ initialSugar ′ ( a ) = initialSugar ( a )(1) We remove from the population all agents who have reached their maximumage or who have no sugar reserves;(2) We remove all loans owed by or owing to these dying agents;(3) Any agent not being removed still has all attributes completely unchanged.The replacement rule follows readily from this rule, the only addition beingthe generation of new agents to replace the agents being removed. In effect wehave broken the replacement rule into two parts Death followed by
Replacement ;although the
Death rule may be used in isolation the
Replacement rule mustalways be preceded by the application of the
Death rule.
Replacement ∆ Agents population ′ = IN IT IALP OP U LAT ION SIZE (1) loanBook ′ = loanBook ∀ a : AGEN T • a ∈ population ⇒ (2)( a ∈ population ′ ∧ sex ( a ) = sex ′ ( a ) ∧ vision ( a ) = vision ′ ( a ) ∧ maxAge ( a ) = maxAge ′ ( a ) ∧ agentCulture ( a ) = agentCulture ′ ( a ) ∧ position ( a ) = position ′ ( a ) ∧ age ( a ) = age ′ ( a ) ∧ agentSugar ′ ( a ) = agentSugar ( a ) ∧ metabolism ′ ( a ) = metabolism ( a ) ∧ diseases ′ ( a ) = diseases ( a ) ∧ agentImmunity ′ ( a ) = agentImmunity ( a ) ∧ children ′ ( a ) = children ( a )) ∧ initialSugar ′ ( a ) = initialSugar ( a ) a ∈ population ′ \ population ⇒ ( age ′ ( a ) = 0 (3) ∧ ST ART SU GARM IN ≤ agentSugar ′ ( a ) ≤ ST ART SU GARM AX ∧ initialSugar ′ ( a ) = agentSugar ′ ( a ) ∧ diseases ′ ( a ) = ∅ ∧ children ′ ( a ) = ∅ )(1) The new population has the correct number of members;(2) The existing agents remain unchanged and part of the new population;(3) All new agents have new values initialised within the allowed limits (thosenot stated explicitly are random values within the ranges set by the speci-fication invariants.We do not state the positions of any new agents because they are chosen randomly.Our schema invariants ensure that they are on the grid in a location not occupiedby any other agent.We need to add some extra information to this rule definition to ensure that:(1) Newly created agents have no diseases, children or loans;(2) Their initial endowment of resources is within a set range.3.12. Agent Mating S .Agent Mating S : • Select a neighboring agent at random; • If the neighboring agent is of the opposite sex and if both agents arefertile and at least one of the agents has an empty neighboring sitethen a newborn is produced by crossing over the parents’ genetic andcultural characteristics;
HE SPECIFICATION OF SUGARSCAPE 25 • Repeat for all neighbors.This rule determines how mating takes place amongst agents to produce off-spring. An agent is fertile if its age is within preset boundaries. This is representedby the simple isF ertile function below. isF ertile : ( N × SEX ) boolean ∀ age : N • isF ertile ( age, male ) ⇔ M ALEF ERT ILIT Y ST ART ≤ age ≤ M ALEF ERT ILIT Y EN DisF ertile ( age, f emale ) ⇔ F EM ALEF ERT ILIT Y ST ART ≤ age ≤ F EM ALEF ERT ILIT Y EN D
We define two functions that take in an agent and a mapping from parents tooffspring and returns the father or mother of the agent. f ather : AGEN T × (( AGEN T × AGEN T ) AGEN T ) AGEN Tmother : AGEN T × (( AGEN T × AGEN T ) AGEN T ) AGEN T ∀ x, m, f : AGEN T ; Of f spring : (
AGEN T × AGEN T ) AGEN T • f ather ( x, Of f spring ) = m ⇔ Of f spring (( m, f )) = xmother ( x, Of f spring ) = f ⇔ Of f spring (( m, f )) = x The issues encountered with the mating rule are similar to those with movement.If two sets of parent try to produce offspring in the same vacant location only onecan succeed. As there is no preferred conflict resolution rule we cannot state anypreference for which agents succeed in producing children and which do not. Allwe can state is that the maximum number of offspring will be produced given thespace constraints but we cannot always be sure which offspring make it into thisset. Neighbours in this rule refers to von Neumann Neighbours only.Mating although proceeding concurrently throughout the population is an ex-clusive event. That is, if agent A is mating with agent B then A cannot be matingwith any other agent at the same time: you can only ate with one partner at atime. The rule itself specifies that each agent will mate with all available partnersso the execution of the rule can involve a sequence of mating events for specificagents.Although it is not stated in the rule definition the accompanying book mentionsthat each parent should gift half of its sugar to its offspring and will only mate ifit has a sugar level equal to or greater than its initial sugar level (that is its sugarlevel on creation). This significantly complicates the rule and dramatically changesits definition and characteristics. However we will assume that this informationwas inadvertently omitted from the rule definition as the rule makes more sense ifwe include these extra factors. Since each individual agent can involve itself in a sequence of up to four matingevents during rule execution we require a specification that retains global concur-rency while still imposing a sequential ordering based on these constraints. Wedo this by collecting all possible potential mating partners into a set and then di-viding this set into a sequence of maximally sized sets where each subset containsonly mating events that can occur concurrently. These sets are produced using aconflict resolution rule that ensures that only pairing that can occur simultane-ously appear within each such subset. The rule then proceeds by executing matingevents within each subset concurrently while the sets are evaluated in sequence.
AgentM ating Ξ Lattice ∆ AgentsloanBook ′ = loanBook ∃ potentialM atingP airs : P ( AGEN T × AGEN T ) | potentialM atingP airs = { ( a : AGEN T, b : AGEN T ) | sex ( a ) = sex ( b ) ∧ isF ertile ( age ( a ) , sex ( a )) ∧ isF ertile ( age ( head ) , sex ( head )) ∧ adjacent ( position ( a ) , position ( head )) } ( population ′ , position ′ , vision ′ , agentSugar ′ , agentCulture ′ , metabolism ′ , children ′ , diseases ′ , agentImmunity ′ , age ′ , sex ′ , initialSugar ′ ) = concurrentM ating ( getConf ictF reeP airs ( potentialM atingP airs ) , population, position, vision,agentSugar, agentCulture, metabolism, children,diseases, agentImmunity, age, maxAge, sex, initialSugar )(1) Generate the set of all possible mating pairs;(2) Recursively proceed with concurrent mating within the conflict free subsets. HE SPECIFICATION OF SUGARSCAPE 27 getConf ictF reeP airs : P ( AGEN T × AGEN T ) → seq( P ( AGEN T × AGEN T )) ∀ AllP airs : P ( AGEN T × AGEN T ); a : AGEN T ; •∃ conf lictF reeSet : P ( AGEN T × AGEN T ) | conf lictF reeSet ⊆ AllP airs (1) ∧ a ∈ ran conf lictF reeSet ⇒ a dom conf lictF reeSet ∧ a ∈ dom conf lictF reeSet ⇒ a ran conf lictF reeSet ∀ otherSet : P ( AGEN T × AGEN T ) | (2) otherSet ⊆ AllP airs ∧ a ∈ dom otherSet ⇒ a ran AllP airs ∧ a ∈ ran otherSet ⇒ a dom AllP airs • otherSet ≤ conf listF reeSetgetConf ictF reeP airs ( ∅ ) = ∅ getConf ictF reeP airs ( AllP airs ) = (3) h conf lictF reeSet i a getConf ictF reeP airs ( AllP airs \ conf lictF reeSet )(1) Generate a collision free (conflict resolved) set where each agent can onlyonce within the set;(2) Ensure this set is as large as possible;(3) Recurse through the remaining pairs dividing them into more conflict freesets. concurrentM ating : seq P ( AGEN T × AGEN T ) × P AGEN T × AGEN T P OSIT ION × AGEN T N × AGEN T N × AGEN T seq BIT × AGEN T N × AGEN T P AGEN T × AGEN T P seq BIT × AGEN T seq BIT × AGEN T N × AGEN T N × AGEN T SEX × AGEN T N ↔ P AGEN T × AGEN T P OSIT ION × AGEN T N × AGEN T N × AGEN T seq BIT × AGEN T N × AGEN T P AGEN T × AGEN T P seq BIT × AGEN T seq BIT × AGEN T N × AGEN T N × AGEN T SEX × AGEN T N ∀ tail : seq P ( AGEN T × AGEN T ); head : P ( AGEN T × AGEN T ); population : P AGEN T ; position : AGEN T P OSIT ION ; vision : AGEN T N ; agentSugar : AGEN T N ; agentCulture : AGEN T seq BIT ; metabolism : AGEN T N ; children : AGEN T P AGEN T ; diseases : AGEN T P seq BIT ; agentImmunity : AGEN T seq BIT ; age : AGEN T N ; maxAge : AGEN T N ; sex : AGEN T SEX ; initialSugar : AGEN T N ; HE SPECIFICATION OF SUGARSCAPE 29 ∃ newpopulation : P AGEN T ; newposition : AGEN T P OSIT ION ; newvision : AGEN T N ; newagentSugar : AGEN T N ; newagentCulture : AGEN T seq BIT ; newmetabolism : AGEN T N ; newchildren : AGEN T P AGEN T ; newdiseases : AGEN T P seq BIT ; newagentImmunity : AGEN T seq BIT ; newage : AGEN T N ; newmaxAge : AGEN T N ; newsex : AGEN T SEX ; newinitialSugar : AGEN T N ; | ( newpopulation, newposition, newvision, newagentSugar, newagentCulture,newmetabolism, newchildren, newdiseases, newagentImmunity, newage, newmaxAge,newsex, newinitialSugar ) = applyM ating ( asSeq ( head ) , population, position, vision,agentSugar, agentCulture, metabolism, children,diseases, agentImmunity, age, maxAge, sex, initialSugar ) • concurrentM ating ( hi , population, position, vision,agentSugar, agentCulture, metabolism, children,diseases, agentImmunity, age, maxAge, sex, initialSugar ) =( population, position, vision, agentSugar, agentCulture, metabolism,children, diseases, agentImmunity, age, maxAge, sex, initialSugar ) concurrentM ating ( h head i a tail, population, position, vision,agentSugar, agentCulture, metabolism, children,diseases, agentImmunity, age, maxAge, sex, initialSugar ) = concurrentM ating ( tail, newpopulation, newposition, newvision,newagentSugar, newagentCulture, newmetabolism, newchildren,newdiseases, newagentImmunity, newage, newmaxAge, newsex, newinitialSugar ) applyM ating : seq( AGEN T × AGEN T ) × P AGEN T × AGEN T P OSIT ION × AGEN T N × AGEN T N × AGEN T seq BIT × AGEN T N × AGEN T P AGEN T × AGEN T P seq BIT × AGEN T seq BIT × AGEN T N × AGEN T N × AGEN T SEX × AGEN T N ↔ P AGEN T × AGEN T P OSIT ION × AGEN T N × AGEN T N × AGEN T seq BIT × AGEN T N × AGEN T P AGEN T × AGEN T P seq BIT × AGEN T seq BIT × AGEN T N × AGEN T N × AGEN T SEX × AGEN T N ∀ population : P AGEN T ; position : AGEN T P OSIT ION ; sex : AGEN T SEX ; vision : AGEN T N ; age : AGEN T N ; initialSugar : AGEN T N ; maxAge : AGEN T N ; metabolism : AGEN T N ; agentSugar : AGEN T N ; agentCulture : AGEN T seq BIT ; children : AGEN T P AGEN T ; agentImmunity : AGEN T seq BIT ; diseases : AGEN T P seq BIT ; head : AGEN T × AGEN T ; tail : seq( AGEN T × AGEN T ); • HE SPECIFICATION OF SUGARSCAPE 31 ∃ of f spring, a, b : AGEN T ; newsex : AGEN T SEX ; newvision : AGEN T N ; newmetabolism, newagentSugar, newinitialSugar : AGEN T N ; newmaxAge : AGEN T N ; newagentCulture : AGEN T seq BIT ; newchildren : AGEN T P AGEN T ; newagentImmunity : AGEN T seq BIT ; inheritedImmunity : seq BIT ; inheritedCulture : seq BIT ; | of f spring populationa = f irst ( head ) ∧ b = second ( head ) newchildren : children ∪ { of f spring ∅ a children ( a ) ∪ { of f spring } ,b children ( b ) ∪ { of f spring }} newsex = sex ∪ { of f spring male }∨ newsex = sex ∪ { of f spring f emale } newvision = vision ∪ { of f spring vision ( a ) }∨ newvision = vision ∪ { of f spring vision ( b ) } newmaxAge = maxAge ∪ { of f spring maxAge ( a ) }∨ newmaxAge = maxAge ∪ { of f spring maxAge ( b ) } newmetabolism = metabolism ∪ { of f spring metabolism ( a ) }∨ newmetabolism = metabolism ∪ { of f spring metabolism ( b ) } newinitialSugar = initialSugar ⊕{ of f spring initialSugar ( a ) / initialSugar ( b ) / , a initialSugar ( a ) / , b initialSugarnewagentSugar = agentSugar ∪ { of f spring initialSugar }∧ ∀ n : 1 . . IM M U N IT Y LEN GT H • ( inheritedImmunity ( n ) = agentImmunity ( a )( n ) ∨ inheritedImmunity ( n ) = agentImmunity ( b )( n )) newagentImmunity : agentImmunity ∪ { of f spring inheritedImmunity }∧ ∀ n : 1 . . CU LT U RECOU N T • ( inheritedCulture ( n ) = agentCulture ( a )( n ) ∨ inheritedCulture ( n ) = agentCulture ( b )( n )) newagentCulture : agentCulture ∪ { of f spring inheritedCulture } applyM ating ( hi , population, position, vision, agentSugar, agentCulture,metabolism, children, diseases, agentImmunity, age, maxAge, sex, initialSugar ) =( population, position, vision, agentSugar, agentCulture, metabolism,children, diseases, agentImmunity, age, maxAge, sex, initialSugar ) applyM ating ( h head i a tail, population, position, vision, agentSugar, agentCulture,metabolism, children, diseases, agentImmunity, age, maxAge, sex, initialSugar ) = if (( ∃ loc : P OSIT ION | ( adjacent ( loc, position ( ag ))) ∨ adjacent ( loc, position ( head )) ∧ loc dom position ) ∧ ( agentSugar ( head ) > initialSugar ( head )) ∧ ( agentSugar ( ag ) > initialSugar ( agapplyM ating ( tail, population ∪ { of f spring } , position ∪ { of f spring loc } ,newvision, newagentSugar, newagentCulture, newmetabolism,newchildren, diseases ∪ { of f spring ∅ } , newagentImmunity,age ∪ { of f spring } , newmaxAge, newsex, initialSugar ) else applyM ating ( tail, population, position, vision, agentSugar, agentCulture,metabolism, children, diseases, agentImmunity, age, maxAge, sex, initialSugar )3.13. Agent Inheritance I .Agent Inheritance I : When an agent dies its wealth is equally distributedamong all its living children.The rule definition is deceptively simple but some assumptions must be made inorder to give it a precise definition. These assumptions are required because of thediscrete nature of the simulation. Only living children can inherit from a parent.If a child is alive but scheduled to die at the same time as their parent then(because all agents who are due to die will die simultaneously) this child shouldnot inherit from their parent. If we were to allow them to inherit we would eitherhave to impose an ordering on the allocation of inheritance making the rule morecomplex or accept than the ordering will sometimes result in part of an inheritancedisappearing. This extra complexity brings no real benefit to the simulation so wediscount it.The second assumption is that we allow for rounding errors. Resources ( sugar )come in discrete amounts so division between children requires integer division.This is also true of division of the loans amongst an agents children. We justaccept any rounding errors as part of the discrete nature of the simulation.Finally we note that inheritance is separate from the actual death or replacementrule, it reallocates the resources of agents due to die but it does not remove thoseagents from the simulation. We leave that to the actual Replacement or Deathrule and assume that one of these rules is applied after the inheritance rule. Thissimplifies the
Inheritance schema.To enable inheritance to handle the loan book (when an agent dies its loans arepassed on to its children) we introduce some helper functions. The asSeq function
HE SPECIFICATION OF SUGARSCAPE 33 turns a set of items into a sequence of items. It does not specify the ordering inthe sequence.[ X ] asSeq : P X → seq X ∀ x : P X ; y : seq X • asSeq ( x ) = y ⇔ (ran y = x ∧ y = x )The second function disperseLoans takes in the loan book, a sequence contain-ing all the dying agents and the children of the agents and produces an updatedloan book with the loans of the dying agents now dispersed amongst their children.To do this it employs a third function oneAgentLoans that takes in a single agent(who is marked for removal) the loans (in a sequence) held by that agent and theset containing its children. It outputs a new set of loans generated by dispersingall this agents loans amongst its children. In both cases we use sequences for theparameter we are recursing over as it makes the recursion easier to specify. disperseLoans : ( P ( AGEN T × ( AGEN T × ( N × N ))) × seq AGEN T × ( AGEN T P AGEN T )) → P ( AGEN T × ( AGEN T × ( N × N ))) ∀ Loans : P ( AGEN T × ( AGEN T × ( N × N ))); a : AGEN T ; tail : seq AGEN T ; Children : AGEN T P AGEN T • disperseLoans ( Loans, hi , Children ) = LoansdisperseLoans ( Loans, h a i a tail, Children ) = disperseLoans (( { a } − ⊳ Loans ) ∪ oneAgentLoans ( a, asSeq (ran( { a } ⊳ Loans )) ,Children ( a )) , tail, Children ) oneAgentLoans : AGEN T × seq( AGEN T × ( N × N )) × P AGEN T P ( AGEN T × ( AGEN T × ( N × N ))) ∀ a, borrower, inheritor : AGEN T ; Children : P AGEN T ; amt, dur, newAmt : N ; tail : seq( AGEN T × ( N × N )) • oneAgentLoans ( a, hi , Children ) = ∅ oneAgentLoans ( a, h ( borrower, ( amt, dur )) i a tail, Children ) = { x : AGEN T | x ∈ Children • ( x, ( borrower, ( amt div Children, dur ))) }∪ oneAgentLoans ( a, tail, Children )The getMother and getFather functions simply take in an agent and the children set and finds the mother (father) of the agent from this set. getM other : AGEN T × ( AGEN T P AGEN T ) × AGEN T SEX AGEN TgetF ather : AGEN T × ( AGEN T P AGEN T ) × AGEN T SEX AGEN T ∀ child, parent : AGEN T ; children : AGEN T P AGEN T • getM other ( child, children, sex ) = parent ⇔ child ∈ children ( parent ) ∧ sex ( parent ) = f emalgetF ather ( child, children, sex ) = parent ⇔ child ∈ children ( parent ) ∧ sex ( parent ) = male An agent can inherit from at most two different agents, one male and one female.We use this to facilitate the specification by treating each sex separately.
Inheritance ∆ Agentspopulation ′ = population ∧ sex ′ = sexposition ′ = position ∧ vision ′ = visionage ′ = age ∧ maxAge ′ = maxAgeagentCulture ′ = agentCulture ∧ children ′ = childrenmetabolism ′ = metabolism ∧ diseases ′ = diseasesagentImmunity ′ = agentImmunityinitialSugar ′ = initialSugar ∃ dying : P AGEN T ; inheritF romF emale, inheritF romM ale : AGEN T N ; ∀ x : AGEN T ; ∃ p : AGEN T | x ∈ population \ dying • (1)dom inheritF romF emale = dom inheritF romM ale = population \ dyingdying = { x : AGEN T | x ∈ population ∧∧ ( age ( x ) = maxAge ( x ) ∨ agentSugar ( x ) = 0) } getM other ( x, children, sex ) dying ⇒ (1 a ) inheritF romF emale ( x ) = 0 p = getM other ( x, children, sex ) ∧ p ∈ dying ⇒ inheritF romF emale ( x ) = agentSugar ( p ) div population ∩ children ( p ) \ dying )) getF ather ( x, children, sex ) dying ⇒ (1 b ) inheritF romM ale ( x ) = 0 p = getF ather ( x, children, sex ) ∧ p ∈ dying ⇒ inheritF romM ale ( x ) = agentSugar ( p ) div population ∩ children ( p ) \ dying )) x ∈ dying (3) ⇒ agentSugar ′ ( x ) = 0 x dying (4) ⇒ agentSugar ′ ( x ) = agentSugar ( x )+ inheritF romM ale ( x ) + inheritF romF emale ( x ) loanBook ′ = disperseLoans ( loanBook, asSeq ( dying ) , children ) (5) HE SPECIFICATION OF SUGARSCAPE 35 (1) First we construct the set of dying agents. Then using this set of dyingagents we can construct two functions, one mapping amounts inheritedfrom a female parent and one mapping amounts inherited from a maleparent. These sets are then used to update the sugar of each agent;a) The function giving the amount each inheriting agent gets from its fe-male parent is constructed by finding all healthy agents who have a dyingmother and determining their share of their dying mother’s resources;b) The function listing amounts each agent gets from a male parent isconstructed in an almost identical manner.(2) If an agent is dying its sugar level is set to zero (because it is being real-located to its children);(3) Otherwise the agents sugar level is its old level plus whatever it inheritsfrom both dying parents;(4) Finally we update the loanBook using our disperseLoans function.3.14.
Agent Culture K .Agent cultural transmission: • Select a neighboring agent at random; • Select a tag randomly; • If the neighbor agrees with the agent at that tag position, no changeis made; if they disagree, the neighbor’s tag is flipped to agree withthe agent’s tag; • Repeat for all neighbors.
Group membership:
Agents are defined to be members of the Blue groupwhen 0s outnumber 1s on their tag strings, and members of the Red groupin the opposite case.
Agent Culture K : Combination of the “agent cultural transmission” and“agent group membership” rules given immediately above.Group membership is defined with the assumption that there are always an oddnumber of tags. tribe returns the affiliation of an agent based on the number ofbits of each type in its culture sequence. If the majority of bits in a sequence are0 then it belongs to the blue tribe, otherwise it belongs to the red tribe. This isused by the culture rule. tribe : seq
BIT → af f iliation ∀ aSeq : seq BIT • tribe ( aSeq ) = blue ⇔ aSeq ⊲ { } ) > aSeq ⊲ { } ) tribe ( aSeq ) = red ⇔ aSeq ⊲ { } ) < aSeq ⊲ { } ) f lipT ags is a recursive function that takes in a culture tag sequence belongingto an agent, a sequence of neighbouring agents and the mapping containing allagent’s culture tag sequences. It returns a new tag sequence generated by each neighbouring agent flipping one bit chosen at random of the original agent’s tagsequence. It is aided in this by the function f lipBit that takes in two bit sequencesand returns a new sequence equal to the first bit sequence with one bit changedat random to match the other sequence at that position. f lipBit : seq BIT × seq BIT ↔ seq BIT ∀ original, other, new : seq BIT • f lipBit ( original, other ) = new ⇔ original = other = new ∧∃ i : 0 . . original • ∀ j : 0 . . original • ( i = j ⇒ new ( j ) = original ( j )) ∧ new ( i ) = other ( i ) f lipT ags : seq BIT × seq AGEN T × ( AGEN T seq BIT ) ↔ seq BIT ∀ aSeq : seq BIT ; ag : AGEN T ; tail : seq AGEN T ; culturalResources : AGEN T seq BIT • f lipT ags ( aSeq, hi , culturalResources ) = aSeqf lipT ags ( aSeq, h ag i a tail, culturalResources ) = f lipT ags ( f lipBit ( aSeq, culturalResources ( ag )) , tail, culturalResources )The sequence of neighbours is provided by the Culture scheme which employsthe asSeq function to convert a set of neighbours into a sequence.
HE SPECIFICATION OF SUGARSCAPE 37
Culture ∆ Agentspopulation ′ = populationsex ′ = sexposition ′ = positionvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentSugar ′ = agentSugarchildren ′ = childrenloanBook ′ = loanBookdiseases ′ = diseasesmetabolism ′ = metabolismagentImmunity ′ = agentImmunityinitialSugar ′ = initialSugar ∀ a : AGEN T • a ∈ population ⇒ agentCulture ′ ( a ) = f lipT ags ( agentCulture ( a ) , (1) asSeq ( { b : AGEN T | adjacent ( position ( a ) , position ( b )) } ) , agentCulture )(1) For every agent a in the population we allow each other agent that counts a as a neighbour to flip one bit at random of a ’s culture bit sequence.3.15. Combat C α .Agent Combat C α : • Look out as far as vision permits in the four principle lattice directions; • Throw out all sites occupied by members of the agent’s own tribe; • Throw out all sites occupied by members of different tribes who arewealthier then the agent; • The reward of each remaining site is given by the resource level atthe site plus, if it is occupied, the minimum of α and the occupant’swealth; • Throw out all sites that are vulnerable to retaliation; • Select the nearest position having maximum reward and go there; • Gather the resources at the site plus the minimum of α and the occu-pants wealth if the site was occupied; • If the site was occupied then the former occupant is considered “killed”- permanently removed from play. reward is used by the combat rule and values a position based on its sugarcontent and the sugar reserves held by any agent at that position. The combatrule is really an extension of the movement rule where we are now allowed to moveto locations occupied by other agents under certain predefined conditions. reward : P OSIT ION × ( P OSIT ION N ) × ( AGEN T P OSIT ION ) × ( AGEN T N ) × N → N ∀ l : P OSIT ION ; sugar : P OSIT ION N ; agentSugar : AGEN T N ; positions : AGEN T P OSIT ION • if l ∈ ran positions then reward ( l, sugar, positions, agentSugar, COM BAT LIM IT ) = sugar ( l ) + min ( { COM BAT LIM IT, agentSugar ( positions ∼ ( l )) } ) else reward ( l, sugar, positions, agentSugar, COM BAT LIM IT ) = sugar ( l ) availM oves returns the set of all safe moves that an agent can make. availM oves : AGEN T × ( AGEN T P OSIT ION ) × ( P OSIT ION N ) × ( AGEN T N ) × ( AGEN T seq BIT ) × N P P OSIT ION ∀ agent : AGEN T ; positions : AGEN T P OSIT ION ; vision : N ; sugar : P OSIT ION N ; agentSugar : AGEN T N ; culture : AGEN T seq BIT • availM oves ( agent, positions, sugar, agentSugar, culture, vision ) = { l : P OSIT ION ; x : AGEN T | distance ( l, positions ( agent )) ≤ vision (1) ∧ positions ( x ) = l ⇒ ( agentSugar ( x ) < agentSugar ( agent ) (2) ∧ tribe ( culture ( x )) = tribe ( culture ( agent ))) ∧ (( distance ( positions ( x ) , l ) ≤ vision ) (3) ∧ tribe ( culture ( x )) = tribe ( culture ( agent ))) ⇒ agentSugar ( x ) < agentSugar ( agent )+ reward ( l, sugar, positions, agentSugar, COM BAT LIM IT )) • l } (1) Only locations within an agents neighbourhood are considered;(2) If a location is occupied it must be occupied by an agent belonging to adifferent tribe who has lower sugar levels;(3) We only consider a position already containing an agent from another tribeif there are no other agents from a different tribe within the neighbourhoodof that location who are stronger than we will be once we have consumedthe resources of the new location (that is agents who may retaliate againstus for killing an agent belonging to their own tribe).We note that the rule as stated means we consider retaliation under all conditionseven if we are just moving to an empty location. It is unclear from the definitiongiven as to how exactly we check for retaliation. Do we base our check on agentsvisible from our current position or from the proposed position. We have assumedthat it is based on the proposed position but it could easily be otherwise. We HE SPECIFICATION OF SUGARSCAPE 39 also assume that the range used is based on the vision of the moving agent as thisseems logical.The synchronous version of the combat rule assumes that all combat occursinstantaneously (concurrently). We note that it is simpler to specify in that wejust state the before and after states and make no mention of orderings of combat.
Combat
Synchronous ∆ SugarScapestep ′ = stepmaxSugar ′ = maxSugarpollution ′ = pollutionloanBook ′ = population ′ ⊳ loanBook ⊲ ( population ′ ⊳ (ran loanBook )) (1) population ′ ⊆ population (2) sugar ′ = sugar ⊕ { p : P OSIT ION | p ∈ ran position ′ • p } (3) ∀ ag : AGEN T ; l : P OSIT ION • ag ∈ population ′ ⇒ (4)( sex ′ ( ag ) = sex ( ag ) ∧ vision ′ ( ag ) = vision ( ag ) ∧ age ′ ( ag ) = age ( ag ) ∧ maxAge ′ ( ag ) = maxAge ( ag ) ∧ children ′ ( ag ) = children ( ag ) ∧ agentCulture ′ ( ag ) = agentCulture ( ag ) ∧ agentImmunity ′ ( ag ) = agentImmunity ( ag ) ∧ metabolism ′ ( ag ) = metabolism ( ag ) ∧ diseases ′ ( ag ) = diseases ( ag ) ∧ initialSugar ′ ( a ) = initialSugar ( a ) ∧ agentSugar ′ ( ag ) = agentSugar ( ag ) (5)+ reward ( position ′ ( ag ) , sugar, position, agentSugar, COM BAT LIM IT ) ∧ position ′ ( ag ) ∈ (6) availM oves ( ag, position, sugar, agentSugar, agentCulture, vision ( ag )))) ag ∈ population \ population ′ ⇒ (7) ∃ x : AGEN T • position ′ ( x ) = position ( ag ) ∧ tribe ( culture ( x )) = tribe ( culture ( ag ))( l ∈ availM oves ( ag, position, sugar, agentSugar, agentCulture, vision ( ag )) (8) ∧ reward ( l, sugar, position, agentSugar, COM BAT LIM IT ) ≥ reward ( position ′ ( ag ) , sugar, position, agentSugar, COM BAT LIM IT ) ∧ distance ( position ( ag ) , l ) < distance ( position ( ag ) , position ′ ( ag ))) ⇒ ∃ x : AGEN T • position ′ ∼ ( l ) = x ∧ position ( x ) = l (1) Every agent that is removed from the simulation is also removed from the loanBook ;(2) No new agents are introduced;(3) Location sugar levels are updated;(4) Every agent that remains in the population has all its attributes unchangedapart from (possibly) position and sugar;(5) We update the sugar levels of each agent using the reward function;(6) Every agent has moved somewhere within their old neighbourhood;(7) Every agent that is no longer part of the population was removed by com-bat, that is, there is another agent (the agent that killed them) now situatedin their old position;(8) If a location available to an agent and the reward of that location is betteror equal to that agent’s new position and it was closer than that agents newposition to its old position then it must be the case that some other agenthas just moved to that location (otherwise we would have moved there);We have had to make some assumptions here. It is not stated what happenswhen there are no available moves, for example if all sites are subject to retaliation.We have assumed that a move is preferable to staying still and that the only timethat an agent stays in the same position is when there are no available moves.That is, if every site, including our current one, is subject to retaliation then wedo not move anywhere. A more complex interpretation would be to for an agentthat cannot escape retaliation to attack another agent anyway and hope for thebest but purely in the interests of simplicity we have agents remain where theyare.3.16. Credit L d r .Credit L d r : • An agent is a potential lender if it is too old to have children, in whichcase the maximum amount it may lend is one-half of its current wealth; • An agent is a potential lender if it is of childbearing age and has wealthin excess of the amount necessary to have children, in which case themaximum amount it may lend is the excess wealth; • An agent is a potential borrower if it is of childbearing age and hasinsufficient wealth to have a child and has income (resources gathered,minus metabolism, minus other loan obligations) in the present periodmaking it credit-worthy for a loan written at terms specified by thelender; • If a potential borrower and a potential lender are neighbors then aloan is originated with a duration of d years at the rate of r percent,and the face value of the loan is transferred from the lender to theborrower;
HE SPECIFICATION OF SUGARSCAPE 41 • At the time of the loan due date, if the borrower has sufficient wealthto repay the loan then a transfer from the borrower to the lender ismade; else the borrower is required to pay back half of its wealth anda new loan is originated for the remaining sum; • If the borrower on an active loan dies before the due date then thelender simply takes a loss; • If the lender on an active loan dies before the due date then the bor-rower is not required to pay back the loan, unless inheritance rule I isactive, in which case the lender’s children now become the borrower’screditors. totalOwed calculates the total amount owed from a given sequence of loans. Wehave assumed that interest is simple interest and not compound. totalOwed : seq( AGEN T × ( N × N )) → N ∀ a : AGEN T ; amt, dur : N ; tail : seq( AGEN T × ( N × N )) • totalOwed ( hi ) = 0 totalOwed ( h ( a, ( amt, dur )) i a tail ) = ( amt + amt ∗ RAT E ∗ DU RAT ION )+ totalOwed ( tail ) canLend and willBorrow are simple rules. The definition of what determinescredit-worthiness is missing so we have assumed it means an agent has enoughmoney to pay all their outstanding loans. canLend : N × SEX × N → boolean ∀ age, sugar : N • canLend ( age, male, sugar ) ⇔ age > M ALEF ERT ILIT Y EN D ∨ ( M ALEF ERT ILIT Y ST ART ≤ age ≤ M ALEF ERT ILIT Y EN D ∧ sugar > CHILDAM T ) canLend ( age, f emale, sugar ) ⇔ age > F EM ALEF ERT ILIT Y EN D ∨ ( F EM ALEF ERT ILIT Y ST ART ≤ age ≤ F EM ALEF ERT ILIT Y EN D ∧ sugar > CHILDAM T ) willBorrow : N × SEX × N × P ( AGEN T × ( N × N )) → boolean ∀ age, sugar : N ; loans : P ( AGEN T × ( N × N )) • willBorrow ( age, male, sugar, loans ) ⇔ ( M ALEF ERT ILIT Y ST ART ≤ age ≤ M ALEF ERT ILIT Y EN D ∧ sugar < CHILDAM T ) ∧ sugar > totalOwed ( asSeq ( loans )) willBorrow ( age, f emale, sugar, loans ) ⇔ ( F EM ALEF ERT ILIT Y ST ART ≤ age ≤ F EM ALEF ERT ILIT Y EN D ∧ sugar < CHILDAM T ) ∧ sugar > totalOwed ( asSeq ( loans )) amtAvail depends on whether an agent can still have children. If they are nolonger fertile then they can loan out half their available sugar. If that are stillfertile then they have to retain enough sugar to have children. amtAvail : N × SEX × N → N ∀ age, sugar : N • amtAvail ( age, male, sugar ) = if ( age > M ALEF ERT ILIT Y EN D ) then sugar div 2 else if ( isF ertile ( age, male ) ∧ sugar > CHILDAM T ) then sugar − CHILDAM T else amtAvail ( age, f emale, sugar ) = if ( age > F EM ALEF ERT ILIT Y EN D ) then sugar div 2 else if ( isF ertile ( age, f emale ) ∧ sugar > CHILDAM T ) then sugar − CHILDAM T else amtReq is the amount that a lender requires. This is not defined so we canonly use a best guess as to what it is. We assume that the amount required isthat which gives the borrower enough sugar to have children. This is the simplestsensible definition we can think of. amtReq : N → N ∀ sugar : N • amtReq ( sugar ) = CHILDAM T − sugar We supply some simple helper functions that extract the borrower and lenderfrom a loanBook entry, calculate the amount due from a loan, the principal andthe due date (defined as the step when payment is due).
HE SPECIFICATION OF SUGARSCAPE 43 lender : AGEN T × ( AGEN T × ( N × N )) AGEN Tborrower : AGEN T × ( AGEN T × ( N × N )) AGEN TamtDue : AGEN T × ( AGEN T × ( N × N )) N principal : AGEN T × ( AGEN T × ( N × N )) N due : AGEN T × ( AGEN T × ( N × N )) N ∀ l, b : AGEN T ; p, d : N • lender ( l, ( b, ( p, d ))) = lborrower ( l, ( b, ( p, d ))) = bamtDue ( l, ( b, ( p, d ))) = p + p ∗ RAT E ∗ DU RAT IONprincipal ( l, ( b, ( p, d ))) = pdue ( l, ( b, ( p, d ))) = d Finally, using these functions we can present the
P ayLoans schema.
P ayLoans ∆ Agents Ξ Steppopulation ′ = populationsex ′ = sexposition ′ = positionvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentCulture ′ = agentCultureagentImmunity ′ = agentImmunitychildren ′ = childrendiseases ′ = diseasesmetabolism ′ = metabolisminitialSugar ′ = initialSugar ∃ dueLoans, newLoans : ( AGEN T ↔ ( AGEN T × ( N × N ))) • dueLoans = loanBook ⊲ (ran( loanBook ) ⊲ { a : ( N × N ) | second ( a ) = step } )( loanBook ′ , agentSugar ′ ) = payExclusiveLoans ( chooseConf lictF reeSets ( dueLoans ) , agentSugar, loanBook )This schema is complicated by the fact that it is possible that an agent has aloan due and cannot pay this loan off. In this case, according to the rule defini-tion, the borrower must pay half of its sugar to the lender and renegotiate anotherloan to cover the remainder of its debt. Under this rule some issues will arise ifthe borrower has more than one due loan and cannot pay these loans off. Thelender must pay each borrower in sequence the amount of half its sugar. This cannot be performed simultaneously (for example if we owe three loans we can-not give each lender half our sugar as this would mean giving out more sugarthan we actually have). In order to remain true to the rule definition we must,when we have more than one loan due, pay each loan in some sequence (definedusing a conflict resolution rule e.g. pay biggest loan first). The helper function chooseConf lictF reeLoans returns a sequence of groups of loans that are conflictfree (i.e. a borrower can only appear once in each group).The function payExclusiveLoans takes in this sequence of loan sets and pro-cesses each set concurrently in the same manner as the M ating rule. chooseConf lictF reeLoans : (
AGEN T ↔ ( AGEN T × ( N × N ))) ↔ seq( AGEN T ↔ ( AGEN T × ( N × N ))) ∀ a : AGEN T ; dueLoans : ( AGEN T ↔ ( AGEN T × ( N × N ))) • chooseConf lictF reeLoans ( ∅ ) = hi chooseConf lictF reeLoans ( dueLoans ) = ∃ maxSet : ( AGEN T ↔ ( AGEN T × ( N × N ))) | maxSet ⊆ dueLoans ∧ { a } ⊳ (ran dueLoans )) > ⇒ { a } ⊳ (ran maxSet )) = 1 (1) h maxSet i a chooseConf lictF reeLoans ( dueLoans \ maxSet )(1) We choose the largest convict free set possible where a set is deemed conflictfree if all borrowers only appear in that set at most once. payExclusiveLoans : seq( AGEN T ↔ ( AGEN T × ( N × N ))) × AGEN T N × ( AGEN T ↔ ( AGEN T × ( N × N ))) ↔ (( AGEN T ↔ ( AGEN T × ( N × N ))) × AGEN T N ) ∀ tail : seq( AGEN T ↔ ( AGEN T × ( N × N ))); head, loanBook : ( AGEN T × ( AGEN T × ( N × N ))); agentSugar : AGEN T N • payExclusiveLoans ( hi , agentSugar, loanBook ) =( loanBook, agentSugar ) payExclusiveLoans ( h head i a tail, agentSugar, loanBook ) = ∃ newAgentSugar : AGEN T N ; newLoans : ( AGEN T ↔ ( AGEN T × ( N × N ))) | ( newLoans, newAgentSugar ) = makeP ayments ( asSeq ( head ) , ∅ , agentSugar ) • payExclusiveLoans ( tail, newAgentSugar, ( LoanBook \ head ) ∪ newLoans ) makeP ayments is a recursive function that goes through a sequence of loansand makes the final payment on each one. It is used in the P ayLoans schema
HE SPECIFICATION OF SUGARSCAPE 45 where it takes in a sequence of the due loans and the agents current sugar levelsand returns a set of renegotiated loans, where payment is unable to be made, andthe new agent sugar levels. makeP ayments : seq(
AGEN T × ( AGEN T × ( N × N ))) × P ( AGEN T × ( AGEN T × ( N × N ))) × ( AGEN T N ) → ( P ( AGEN T × ( AGEN T × ( N × N ))) × ( AGEN T N )) ∀ renegotiatedLoans, new : P ( AGEN T × ( AGEN T × ( N × N ))); updatedSugar, agentSugar : AGEN T N ; loan : ( AGEN T × ( AGEN T × ( N × N ))); tail : seq( AGEN T × ( AGEN T × ( N × N ))) • makeP ayments ( hi , renegotiatedLoans, updatedSugar ) = (1)( renegotiatedLoans, updatedSugar ) makeP ayments ( h loan i a tail, new, agentSugar ) = (2) if amtDue ( loan ) ≤ agentSugar ( borrower ( loan )) then (2 a ) makeP ayments ( tail, new, agentSugar ⊕{ lender ( loan ) agentSugar ( lender ( loan )) + amtDue ( loan ) ,borrower ( loan ) agentSugar ( borrower ( loan )) − amtDue ( loan ) } ) else (2 b ) makeP ayments ( tail, new ∪ { ( lender ( loan ) , ( borrower ( loan ) , ( amtDue ( loan ) − agentSugar ( borrower ( loan )) div 2 ,due ( loan ) + DU RAT ION ))) } ,agentSugar ⊕ { lender ( loan ) agentSugar ( lender ( loan ))+ agentSugar ( borrower ( loan )) div 2 ,borrower ( loan ) agentSugar ( borrower ( loan )) div 2 } )For the final part of the Credit rule we need to be able to work out the totalowed by an agent over all loans. First we define two helper functions: sumLoans and totalOwed . sumLoans : seq( AGEN T × ( AGEN T × ( N × N ))) N ∀ tail : seq( AGEN T × ( AGEN T × ( N × N ))); top : AGEN T × ( AGEN T × ( N × N )) • sumLoans ( hi ) = 0 sumLoans ( h top i a tail ) = sumLoans ( tail ) + amtDue ( top ) totalOwed : AGEN T × ( AGEN T × ( AGEN T × ( N × N ))) N totalLoaned : AGEN T × ( AGEN T × ( AGEN T × ( N × N ))) N ∀ agent : AGEN T ; loans : AGEN T × ( AGEN T × ( N × N )) • totalOwed ( agent, loans ) = sumLoans ( asSeq ( loans ⊲ ( { agent } ⊳ (ran loans )))) totalLoaned ( agent, loans ) = sumLoans ( asSeq ( { agent } ⊳ loans )) HE SPECIFICATION OF SUGARSCAPE 47
M akeLoans ∆ Agents Ξ Steppopulation ′ = population ∧ sex ′ = sexposition ′ = position ∧ vision ′ = visionage ′ = age ∧ maxAge ′ = maxAgeinitialSugar ′ = initialSugaragentCulture ′ = agentCulture ∧ agentImmunity ′ = agentImmunitydiseases ′ = diseases ∧ children ′ = children ∧ metabolism ′ = metabolism ∃ newLoans : P ( AGEN T × ( AGEN T × ( N × N ))); ∀ ag, lender, borrower : AGEN T ; amt, due : N • loanBook ′ = loanBook ∪ newLoans (1) ag ∈ dom newLoans ⇒ agentSugar ′ ( ag ) = agentSugar ( ag ) − totalLoaned ( ag, newLoans ) (2 a ) ag ∈ dom(ran newLoans ) ⇒ (2 b ) agentSugar ′ ( ag ) = agentSugar ( ag ) + totalOwed ( ag, newLoans ) ag dom( newLoans ) ∪ dom(ran newLoans ) ⇒ (2 c ) agentSugar ′ ( ag ) = agentSugar ( ag ) willBorrow ( age ( ag ) , sex ( ag ) , agentSugar ′ ( ag ) , ran( loanBook ′ ∩ { a : AGEN T × ( AGEN T × ( N × N )) | borrower ( a ) = borrower ( loan ) } )) ⇒ (2 d ) ¬ ∃ ag AGEN T • canLend ( age ( ag , sex ( ag , agentSugar ′ ( ag ∧ adjacent ( position ( ag , position ( ag )) totalLoaned ( ag, newLoans ) ≤ amtAvail ( age ( ag ) , sex ( ag ) , agentSugar ( ag ))(3) totalOwed ( ag, newLoans ) ≤ amtReq ( agentSugar ( ag )) (4)( lender, ( borrower, ( amt, due ))) ∈ newLoans ⇒ (5)( canLend ( age ( lender ) , sex ( lender ) , agentSugar ( lender )) (5 a ) ∧ willBorrow ( age ( borrower ) , sex ( borrower ) , agentSugar ( borrower ) , { borrower } ⊳ (ran loanBook )) ∧ amt ≤ min ( { amtAvail ( age ( lender ) , sex ( lender ) , agentSugar ( lender )) ,amtReq ( agentSugar ( borrower )) } ) (5 b ) ∧ due = step + DU RAT ION (5 c ) ∧ adjacent ( position ( lender ) , position ( borrower ))) (5 d )(1) The new loan book is the old book plus the new loans;(2) The following properties ensure sugar is updated correctly and that thecorrect amount of borrowing has taken place:a) If an agent is a lender then their new sugar levels decrease by the amountthe have lent;b) If an agent is a borrower then their sugar has increased by the amountthey have borrowed; c) Any agent that neither borrowed or lent has the same sugar levels asbefore;d) If there remain any agents who still need to borrow then it is becausethere are no agents in their neighbourhood who are still in a position toborrow.(3) The total amount loaned by any agent is no greater than the amount thatagent had available;(4) The total amount borrowed is less than or equal to the amount requiredby the borrower;(5) Every loan in this set must have the following properties:a) The lender must be in a position to lend;b) The borrower must need to borrow;c) The amount is less than or equal to the minimum of (i) the amountrequired by the borrower and (ii) the maximum amount available fromthe lender;d) The due date of the loan is set by the DU RAT ION constant;e) the borrower and lender must be neighbours.3.17.
Agent Disease E .Agent immune response: • If the disease is a substring of the immune system then end (the agentis immune), else (the agent is infected) go to the following step; • The substring in the agent immune system having the smallest Ham-ming distance from the disease is selected and the first bit at which itis different from the disease string is changed to match the disease.
Disease transmission:
For each neighbor, a disease that currently afflictsthe agent is selected at random and given to the neighbor.
Agent disease processes E : Combination of “agent immune response” and“agent disease transmission” rules given immediately above subseq is a function for determining whether one sequence is a subsequence ofanother. hammingDist determines the number of bit differences in two sequencesof the same size. subseq : seq
BIT × seq BIT → boolean ∀ mid, aSequence : seq BIT • subseq ( mid, aSequence ) ⇔∃ pref ix, suf f ix : seq BIT • pref ix a mid a suf f ix = aSequence HE SPECIFICATION OF SUGARSCAPE 49 hammingDist : seq
BIT × seq BIT → N ∀ tail, rest : seq BIT • hammingDist ( hi , hi ) = 0 hammingDist ( h i a tail, h i a rest ) = hammingDist ( tail, rest ) hammingDist ( h i a tail, h i a rest ) = hammingDist ( tail, rest ) hammingDist ( h i a tail, h i a rest ) = 1 + hammingDist ( tail, rest ) hammingDist ( h i a tail, h i a rest ) = 1 + hammingDist ( tail, rest ) applyDiseases takes in a bit sequence representing the immunity of an agent anda list of diseases that affect the agent and produces a new immunity bit sequencethat is updated by the disease list. More precisely, for every disease not in theimmunity sequence a single bit in the closest subsequence that matches the diseaseis flipped to make the sequence more closely match the disease. It uses anotherfunction processInf ection to process each disease in the disease set. applyDiseases : seq BIT × seq seq BIT → seq BIT ∀ I, d : seq
BIT ; tail : seq seq BIT • applyDiseases ( I, hi ) = IapplyDiseases ( I, h d i a tail ) = applyDiseases ( processInf ection ( I, d ) , tail ) processInf ection : seq BIT × seq BIT → seq BIT ∀ I, d : seq
BIT • if subseq ( d, I ) then processInf ection ( I, d ) = I else ∃ a, b, c : seq BIT ; ∀ x : seq BIT • a a b a c = I ( b = x ∧ subseq ( x, I )) ⇒ hammingDist ( b, d ) ≤ hammingDist ( x, d ) ∃ i : 1 . . I • ( y ( i ) = d ( i ) ∧ ∀ j : N • j < i ⇒ d ( j ) = y ( j )) processInf ection ( I, d ) = I ⊕ { ( i + a ) b ( i ) } ) ImmuneResponse is the simplest part of this rule to specify. The recursivefunction applyDiseases does all the work.
ImmuneResponse ∆ AgentsloanBook ′ = loanBookpopulation ′ = populationsex ′ = sexposition ′ = positionvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentCulture ′ = agentCulturediseases ′ = diseaseschildren ′ = childrenagentSugar ′ = agentSugarmetabolism ′ = metabolisminitialSugar ′ = initialSugaragentImmunity ′ = { a : AGEN T | a ∈ population • a applyDiseases ( agentImmunity ( a ) , asSeq ( diseases ( a ))) }∀ x : AGEN T • x ∈ population ⇒ agentSugar ′ ( x ) = agentSugar ( x ) − { d : seq BIT | d ∈ diseases ( a ) ∧ ¬ subseq ( d, agentImmunity ( a ) } (1)Although not stated in the rule definition careful reading of the accompanyingtext [Epstein and Axtell, 1996] shows that there is a penalty that is applied toeach agent carrying diseases that it has no immunity to. The text states that forevery disease carried by an agent that it has no immunity to, sugar metabolismis increased by one. So if an agent carried two diseases that it has no immu-nity to then its metabolism rate increases by two. This extra cost can equallybe deducted by the metabolism rule or the disease rule. Purely for the sake ofnarrative it is placed in the ImmuneResponse rule where it is first referenced inthe original Sugarscape book. This is implemented by the final two lines (1) of the
ImmuneResponse schema.The transmission of diseases is the more complex part of this rule. We willagain use a recursive helper function newDiseases to construct a set of diseasesthat an agent can catch from its neighbours. It takes the set of neighbours andtheir current diseases as input and constructs a set of diseases where one diseaseis chosen from each neighbour.
HE SPECIFICATION OF SUGARSCAPE 51 newDiseases : seq
AGEN T × ( AGEN T P (seq BIT )) → P seq BIT ∀ a : AGEN T ; tail : seq AGEN T ; diseases : AGEN T P (seq BIT ) • newDiseases ( hi , diseases ) = ∅ newDiseases ( h a i a tail, diseases ) = if diseases ( a ) = ∅ then newDiseases ( tail, diseases ) else ∃ d : seq BIT | d ∈ diseases ( a ) • { d } ∪ newDiseases ( tail, diseases )) T ransmission ∆ AgentsloanBook ′ = loanBookpopulation ′ = populationsex ′ = sexposition ′ = positionvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentCulture ′ = agentCultureagentImmunity ′ = agentImmunitychildren ′ = childrenagentSugar ′ = agentSugarmetabolism ′ = metabolisminitialSugar ′ = initialSugar ∀ a : AGEN T • a ∈ population ⇒ diseases ′ ( a ) = diseases ( a ) ∪ (1) newDiseases ( asSeq ( visibleAgents ( a, position, , diseases )(1) visibleAgents returns the set of neighbours of an agent and this set is thenpassed to the newDisease function which returns a set of diseases, onechosen from each agent in the neighbour set.3.18. Rule Application Sequence.
Each tick of simulation time consists of theapplication of a set sequence of rules. Not all rules can be used together so weidentify the allowable sequences of rules. We note that it is not stated in the bookwhat order the rules are to be applied. In the absence of this information we willpick one ordering and restrict ourselves to this ordering.The display the different allowable combinations of rules in any given simulationwe use the following terminology. { Rule } : The indicates that
Rule is optional. We can choose to include it ornot in a simulation;
RuleA | RuleB : This indicates that there is a choice of which rule to apply- either one or the other but not both.This rule ordering is for simulations using only a single resource and so omits the
T rade rule.
T ick [ Growback | SeasonalGrowback ][ M ovement basic | ( M ovement pollution
P ollutionDif f usion ) | Combat ] { Inheritance }{ Death { [ Replacement | AgentM ating ] }}{ Culture }{ P ayLoans
M akeLoans }{ T ransmission
ImmuneResponse } Asynchronous Sugarscape Specification
AU is the sequential application of rules to agents during a simulation step.If, for example, all agents move during a single step then a sequential ordering isimposed on all of the agents and they will move one at a time (that is, sequentially)based on that ordering. This is in contrast to SU where all agents will attemptto move simultaneously (concurrently). AU is easier to implement that SU as itmaps directly onto the current standard sequential programming practice. AUrequires no collision detection and resolution (as for example when two agents tryto simultaneously move to the same location) because concurrency is excluded -only one agent can move at any one time. It is well know that the AU and SUapproaches can deliver different simulation results.Although AU and SU are both commonly used in CA based simulations, whereagent interactions are simple in nature, AU is prevelent in ABM. This is due tothe lack of any good SU algorithms that can handle the complex interactions suchas
M ovement , Combat or T rade that can appear in ABM based simulations.We have provided a specification of Sugarscape that assumes SU. For the sake ofcompleteness and to allow us to make comparisons between synchronous and asyn-chronous updating in Sugarscape we will now present an AU based specificationof the rules of Sugarscape.4.1.
Variants of Asynchronous Updating.
There are a number of varieties ofAU. These variations differ in how they sequentially order agents for updating.The best known variations are [ ? ]: Fixed Direction Line-By-Line:
The locations in the lattice representingthe simulation space are updated in the order they appear in the lattice(usually left to right, top-down);
HE SPECIFICATION OF SUGARSCAPE 53
Fixed Random Sweep:
The order that is used is determined randomlyat the start of the simulation and this order is used for every step in thesimulation;
Random New Sweep:
The order that the agents are updated in is deter-mined randomly at the start of each step (each step uses a different order);
Uniform Choice:
Each agent has an equal probability of being chosen.If there are n agents, then n agents are chosen randomly during a step.During any single step an agent may not be picked at all or may be pickedmore than once (in contrast Random New Sweep guarantees every agent ispicked exactly once per step); Exponential Waiting Time:
This is a
Time Driven method, all the oth-ers are step driven . Every agent has its own clock which rings when theagent is to be updated. The waiting times for the clock are exponentiallydistributed (with mean 1). The probability that an event occurs at time t follows e − t where t is a real number, t ≥
0. This is most similar to
UniformChoice .We will provide a specification for each variation in turn.Fixed Direction Line-by-Line takes in a set of agents and their positions on thelattice. It produces a sequence of agents where every agent appears once and onlyonce in the sequence and the order of the sequence is determined by the agentsposition on the lattice. lineByLine : AGEN T P OSIT ION → seqAGEN T ∀ theP ositions : AGEN T P OSIT ION ; theSequence : seq AGEN T • lineByLine ( theSet ) = theSequence ⇔ ran theSequence = dom theP ositions ∧ theSequence = theP ositions (1)( n, a ) ∈ theSequence ⇔ n = f irst ( theP ositions ( a )) ∗ DIM + second ( theP ositions ( a )) (2)(1) Each agent in the population appears in the sequence once and only once;(2) If one agent appears before another in the sequence then it also appearsbefore that agent on the lattice.Fixed Random Sweep returns a sequence of the agents in some fixed randomordering. This random ordering is chosen once at the start of the simulation andis fixed for the entire simulation run. RAN DOM ORDER : seq
P OSIT ION
RAN DOM ORDER =
P OSIT ION (1) ∀ n, m : N • RAN DOM ORDER ( n ) = RAN DOM ORDER ( m ) (2) ⇔ n = m (1) RAN DOM ORDER is a globally defined sequence containing an orderingof positions on the lattice;(2) Each position on the lattice appears once and only once in this sequence.Any ordering that satisfies these constrains is allowable according to our specifi-cation. This introduces the randomness into the sequence. f ixedRandom : AGEN T P OSIT ION ↔ seqAGEN T ∀ theP ositions : AGEN T P OSIT ION ; theSequence : seq AGEN T • f ixedRandom ( theP ositions ) = theSequence ⇔ ran theSequence = dom theP ositions ∧ theSequence = theP ositions (1) ∀ i : 0 . . theSequence − a , a : AGEN T • ( i, a ) ∈ theSequence ∧ ( i + 1 , a ) ∈ theSequence ⇒ ( ∃ x , x : N | ( x , a ) , ( x , a ) ∈ RAN DOM ORDER ∧ x < x (2)(1) Every agent in the population appears once and only once in the resultingsequence;(2) The ordering of agents in the sequence is based on the ordering defined in RAN DOM ORDERIN G .Random New sweep is simpler to specify. We return a random ordering of agentsafter each call. We only need to ensure that every agent appears in this sequenceexactly once. rndN ewSweep : AGEN T P OSIT ION ↔ seqAGEN T ∀ theP ositions : AGEN T P OSIT ION ; theSequence : seq AGEN T • rndN ewSweep ( theP ositions ) = theSequence ⇔ ran theSequence = dom theP ositions ∧ theSequence = theP ositions (1)(1) Every agent in the population appears once and only once in the resultingsequence;Uniform Choice allows for an agent to be picked multiple times. The onlyconstraints are that the sequence returned contains only agents in the populationand that the size of the sequence equals the number of agents. HE SPECIFICATION OF SUGARSCAPE 55 unif ormChoice : AGEN T P OSIT ION ↔ seq AGEN T ∀ theP ositions : AGEN T P OSIT ION ; n : N ; theSequence : seq AGEN T | ≤ n < theSequenceunif ormChoice ( theP ositions ) = theSequence ⇔ theSequence ( n ) ∈ dom theP ositions ∧ theSequence = theP ositions (1) Every agent in the sequence is an agent from the simulation population;(2) the size of the sequence equals the total number of individual agents in thepopulation.Each variation of asynchronous updating can now be covered by the simplematter of swapping in the appropriate ordering function within the specifications.4.2. Growback, Seasonal Growback and Replacement.
Replacement, Growback and
SeasonalGrowback belong to the category of rules we term independent . Thiscategory includes all rules where the agent involved in the update (or rule execu-tion) does not interact with any other agent - the update result is independent ofany outside factor. It follows then that the order in which these rules are executedwill have no bearing on their outcome. Given this we need make no changes toany of these rules.4.3.
Pollution Diffusion.
P ollutionDif f usion is defined specifically as a syn-chronous rule. There is no asynchronous alternative to this rule as imposing AUwould redefine the rule entirely. For this reason we do not produce a AU specifi-cation of this rule.4.4.
Movement.
The specification of rules under an AU regime follows a standardpattern. First we impose an ordering on all the agents subject to the rule and thenwe recursively apply the update to each agent in the defined order. Each individualagent update can affect the global state and these changes must be passed forwardto the next sequence of agent updates. This is in contrast to SU where all updatesoccur simultaneously.We always define the application of the rule to agents in a sequence recursively.While the rules themselves can be quite simple the Z notation forces us to pass toeach update all parts of the global state that can be changed. This can result inlarge function signatures. AsyncM ovement basic ∆ SugarScapestep ′ = steploc ′ = locmaxSugar ′ = maxSugarpollution ′ = pollutionsex ′ = sexvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentCulture ′ = agentCultureloanBook ′ = loanBookdiseases ′ = diseasesagentImmunity ′ = agentImmunitychildren ′ = childrenmetabolism ′ = metabolismpopulation ′ = populationinitialSugar ′ = initialSugar ( sugar ′ , agentSugar ′ , position ′ ) = applyM ove ( rndN ewSweep ( position ) , vision, sugar, agentSugar, position )Movement is a typical example of this structure. The main specification AsyncM ovement basic simply passes the relevant state information alongside the ordering of agents (ac-cording to whatever AU variant we are using) to the recursive function applyM ove .This recursive function applies the move rule to each agent in turn and returnsthe final updated agent position, agent sugar levels and lattice sugar levels.
HE SPECIFICATION OF SUGARSCAPE 57 applyM ove : seq
AGEN T × AGEN T N × ( P OSIT ION N ) × AGEN T N × AGEN T P OSIT ION ↔ (( P OSIT ION N ) × AGEN T N × AGEN T P OSIT ION ) ∀ head : AGEN T ; tail : seq AGEN T ; population : P AGEN T ; positions : AGEN T P OSIT ION ; sugar : P OSIT ION N ; agentSugar : AGEN T N ; vision : AGEN T N ; • applyM ove ( hi , vision, sugar, agentSugar, positions ) = (1)( sugar, agentSugar, positions ) applyM ove ( h head i a tail, vision, sugar, agentSugar, positions ) = (2) ∃ newLoc : P OSIT ION | newLoc ∈ neighbourhood ( position ( head ) , vision ( head )) (3) ∧ ∀ otherLoc : P OSIT ION | otherLoc ∈ neighbourhood ( position ( head ) , vision ( head )) ⇒ sugar ( otherLoc ) ≤ sugar ( newLoc ) • applyM ove ( tail, vision, sugar ⊕ { newLoc } ,agentSugar ⊕ { head agentSugar ( head ) + sugar ( newLoc ) } ,positions ⊕ { head newLoc } )(1) The base case. If there are no agents left to update then we simply returnthe current state;(2) The recursive case. If we have agents left to process then we move the firstagent in the list and apply the rule to the remaining agents;(3) Find the best location for the agent to move to based on sugar levels ateach location.4.5. Pollution Diffusion.
The movement rule for pollution is almost identicalto the simpler basic movement rule. It only differs in that it takes pollution intoaccount when selecting the best new position for an agent to move to.
AsyncM ovement pollution ∆ SugarScapestep ′ = steploc ′ = locmaxSugar ′ = maxSugarsex ′ = sexpollution ′ = pollutionvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentCulture ′ = agentCultureloanBook ′ = loanBookchildren ′ = childrenagentImmunity ′ = agentImmunitydiseases ′ = diseasesmetabolism ′ = metabolismpopulation ′ = population ( sugar ′ , agentSugar ′ , position ′ ) = (1) applyM ove pollution ( rndN ewSweep ( position ) , vision, sugar,agentSugar, position, pollution ) pollution ′ = pollution ⊕ {∀ l : P OSIT ION ; x : AGEN T | position ′ ( x ) = l • (2) l ( P RODU CT ION ∗ sugar ( l ) + CON SU M P T ION ∗ metabolism ( x )) } (1) Call the recursive applyM ove pollution to apply movement rule to each agentin turn;(2) Update location pollution levels based on agent movement. HE SPECIFICATION OF SUGARSCAPE 59 applyM ove pollution : seq
AGEN T × AGEN T N × ( P OSIT ION N ) × AGEN T N × AGEN T P OSIT ION × P OSIT ION N ↔ (( P OSIT ION N ) × AGEN T N × AGEN T P OSIT ION ) ∀ head : AGEN T ; tail : seq AGEN T ; population : P AGEN T ; positions : AGEN T P OSIT ION ; sugar : P OSIT ION N ; agentSugar : AGEN T N ; vision : AGEN T N ; pollution : P OSIT ION N • applyM ove pollution ( hi , vision, sugar, agentSugar, positions, pollution ) =( sugar, agentSugar, positions ) applyM ove pollution ( h head i a tail, vision, sugar, agentSugar, positions, pollution ) = ∃ newLoc : P OSIT ION | newLoc ∈ neighbourhood ( position ( head ) , vision ( head )) ∧ ∀ otherLoc : P OSIT ION | otherLoc ∈ neighbourhood ( position ( head ) , vision ( head )) ⇒ sugar ( otherLoc ) div (1 + pollution ( otherLoc )) ≤ sugar ( newLoc ) div (1 + pollution ( position ′ ( newLoc ))) • applyM ove pollution ( tail, vision, sugar ⊕ { newLoc } ,agentSugar ⊕ { head agentSugar ( head ) + sugar ( newLoc ) } ,positions ⊕ { head newLoc } , pollution )4.6. Combat.
Asynchronous Combat is undertaken with the applyAllCombat function which applies the combat rule to each agent in a random order usingthe singleF ight function. We note in passing that the synchronous specificationseems to us to be simpler than the asynchronous one (even if the implementationis not).
Combat async ∆ SugarScapestep ′ = stepmaxSugar ′ = maxSugarpollution ′ = pollutionloanBook ′ = population ′ ⊳ loanBook ⊲ ( population ′ ⊳ (ran loanBook )) ∀ ag : AGEN T ; l : P OSIT ION • ag ∈ population ′ ⇒ ( sex ′ ( ag ) = sex ( ag ) ∧ vision ′ ( ag ) = vision ( ag ) ∧ age ′ ( ag ) = age ( ag ) ∧ maxAge ′ ( ag ) = maxAge ( ag ) ∧ children ′ ( ag ) = children ( ag ) ∧ agentCulture ′ ( ag ) = agentCulture ( ag ) ∧ agentImmunity ′ ( ag ) = agentImmunity ( ag ) ∧ metabolism ′ ( ag ) = metabolism ( ag ) ∧ diseases ′ ( ag ) = diseases ( ag )) ∧ initialSugar ′ ( ag ) = initialSugar ( ag )( population ′ , position ′ , sugar ′ , agentSugar ′ ) = applyAllCombat ( rndN ewSweep ( position ) , population, position, sugar,agentSugar, vision, agentCulture ) HE SPECIFICATION OF SUGARSCAPE 61 applyAllCombat : seq
AGEN T × P AGEN T × ( AGEN T P OSIT ION ) × ( P OSIT ION N ) × ( AGEN T N ) × ( AGEN T N ) × ( AGEN T seq BIT ) → ( P AGEN T × ( AGEN T P OSIT ION ) × ( P OSIT ION N ) × ( AGEN T N )) ∀ head : AGEN T ; tail : seq AGEN T ; population : P AGEN T ; positions : AGEN T P OSIT ION ; sugar : P OSIT ION N ; agentSugar : AGEN T N ; vision : AGEN T N ; culture : AGEN T seq BIT • applyAllCombat ( hi , population, positions, sugar, agentSugar, vision, culture ) =( population, positions, sugar, agentSugar, vision, culture ) applyAllCombat ( h head i a tail, population, positions, sugar, agentSugar, vision, culture ) = if ( head ∈ population ) then applyAllCombat ( tail,singleF ight ( head, population, positions, sugar, agentSugar, vision, culture )) else applyAllCombat ( tail, population, positions, sugar, agentSugar, vision, culture ) singleF ight : AGEN T × P AGEN T × ( AGEN T P OSIT ION ) × ( P OSIT ION N ) × ( AGEN T N ) × ( AGEN T N ) × ( AGEN T seq BIT ) → ( P AGEN T × ( AGEN T P OSIT ION ) × ( P OSIT ION N ) × ( AGEN T N )) ∀ agent : AGEN T ; population : P AGEN T ; positions : AGEN T P OSIT ION ; sugar : P OSIT ION N agentSugar : AGEN T N ; vision : AGEN T N ; culture : AGEN T seq BIT • singleF ight ( agent, population, positions, sugar, agentSugar, vision, culture ) = if ( availM oves ( agent, positions, sugar, agentSugar, culture, vision ( agent )) = ∅ ) then ( population, positions, sugar, agentSugar ) else ∃ loc : P OSIT ION ; available : P P OSIT ION ; ∀ otherLoc : P OSIT ION | loc, otherLoc ∈ availM oves ( agent, positions, sugar, agentSugar, culture, vision ( agent )) ∧ otherLocation = location • reward ( loc, sugar, position, agentSugar, COM BAT LIM IT ) ≥ reward ( otherLoc, sugar, position, agentSugar, COM BAT LIM IT )( distance ( position ( agent ) , loc ) > distance ( position ( otherLoc ) , position ′ ( agent )) ⇒ reward ( loc, sugar, position, agentSugar, COM BAT LIM IT ) > reward ( otherLoc, sugar, position, agentSugar, COM BAT LIM IT )) • ( population \ { positions ∼ ( loc ) } , ( positions − ⊲ { loc } ) ⊕ { agent loc } ,sugar ⊕ { loc } , agentSugar ⊕ { agent agentSugar ( agent )+ reward ( position ′ ( agent ) , sugar, position, agentSugar, COM BAT LIM IT ) } )4.7. Disease.
Disease is a simple rule that follows the standard pattern for AUspecification. We place all agents into a sequence, ordered according to the vari-ation of AU we are using, and apply the rule to each agent in turn updating thestate as we go along.
HE SPECIFICATION OF SUGARSCAPE 63
T ransmission ∆ AgentsloanBook ′ = loanBookpopulation ′ = populationsex ′ = sexposition ′ = positionvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentCulture ′ = agentCultureagentImmunity ′ = agentImmunitychildren ′ = childrenagentSugar ′ = agentSugarmetabolism ′ = metabolisminitialSugar ′ = initialSugardiseases ′ = applyT ransmission ( rndN ewSweep ( position ) , diseases, position ) (1)(1) Call recursive applyT ransmission on each agent in population in deter-mined order. applyT ransmission : seq AGEN T × AGEN T P seq BIT × AGEN T P OSIT ION ↔ AGEN T P seq BIT ∀ head : AGEN T ; tail : seq AGEN T ; diseases : AGEN T P seq BIT ; position : AGEN T P OSIT ION ∃ newInf ections : P seq BIT | newInf ections (1)= newDiseases ( asSeq ( visibleAgents ( head, position, , diseases ) • applyT ransmission ( hi , diseases, position ) = (2) diseasesapplyT ransmission ( h head i a tail, diseases, position ) = (3) applyT ransmission ( tail, diseases ⊕ { head ( diseases ( head ) ∪ newInf ections ) } , position )(1) Construct a set of new infections for an agent using the previously defined newDiseases ;(2) Base case: Noting to do, return new disease mapping; (3) Recursive case: Add new diseases to the first agent in the list (accordingto the rule definition) and then recursively apply the rule to the rest of thelist.4.8. Culture.
Culture is specified in an identical manner to
Disease . AsyncCulture ∆ Agentspopulation ′ = populationsex ′ = sexposition ′ = positionvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentSugar ′ = agentSugarchildren ′ = childrenloanBook ′ = loanBookdiseases ′ = diseasesmetabolism ′ = metabolismagentImmunity ′ = agentImmunityinitialSugar ′ = initialSugaragentCulture ′ = applyCulture ( rndN ewSweep ( position ) , agentCulture, position )(1) Call recursive applyCulture on each agent in population in determinedorder. applyCulture : seq AGEN T × AGEN T seq BIT × AGEN T P OSIT ION ↔ AGEN T seq BIT ∀ head : AGEN T ; tail : seq AGEN T ; culture : AGEN T seq BIT ; position : AGEN T P OSIT ION ; ∃ n : P AGEN T | n = neighbours ( head, position ( head ) , • applyCulture ( hi , culture, position ) = (1) cultureapplyCulture ( h head i a tail, culture, position ) = (2) applyCulture ( tail,culture ⊕ { head f lipT ags ( culture ( head ) , asSeq ( n ) , culture ) } , position )(1) Base case: return new values for culture tags; HE SPECIFICATION OF SUGARSCAPE 65 (2) Recursive case: Flip the tags of the first agent in the list and repeat (re-cursively) for the remaining agents in the list (sequence).4.9.
Inheritance.
Inheritance also follows the same pattern as
Culture and
Disease . AsyncInheritance ∆ Agentspopulation ′ = populationsex ′ = sexposition ′ = positionvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentCulture ′ = agentCulturechildren ′ = childrenmetabolism ′ = metabolismdiseases ′ = diseasesagentImmunity ′ = agentImmunityinitialSugar ′ = initialSugar ( loanBook ′ , agentSugar ′ ) = (1) applyInheritance ( rndN ewSweep ( position ) , children, loanBook, agentSugar )(1) Use recursive applyInheritance function to calculate inheritance based oneach agent in turn. applyInheritance : seq AGEN T × AGEN T P AGEN T × ( AGEN T ↔ ( AGEN T × ( N × N ))) × AGEN T N × AGEN T N × AGEN T N ( AGEN T ↔ ( AGEN T × ( N × N ))) × AGEN T N ∀ head : AGEN T ; tail : seq AGEN T ; children : AGEN T P AGEN T ; loans : AGEN T ↔ ( AGEN T × ( N × N )); agentSugar : AGEN T N ; age, maxAge : AGEN T N ∃ newLoans : AGEN T ↔ ( AGEN T × ( N × N )); newAgentSugar : AGEN T N | newAgentSugar = agentSugar ⊕ ( { head } ∪ (1) { ( a, amt ) | a ∈ children ( head ) ∧ amt = agentSugar ( a )+ agentSugar ( head ) / children ( head ) } ) ∧ newLoans = ( { head } − ⊳ loans ) ∪ oneAgentLoans ( a, asSeq (ran( { a } ⊳ loans )) ,Children ( head )) • (2) applyInheritance ( hi , children, loans, agentSugar, age, maxAge ) = (3)( loans, agentSugar ) applyInheritance ( h head i a tail, children, loans, agentSugar, age, maxAge ) = if ( age ( head ) = maxAge ( head ) ∨ agentSugar ( head ) = 0) then (4) applyInheritance ( tail, children, newLoans, newAgentSugar, age, maxAge ) else applyInheritance ( tail, children, loans, agentSugar, age, maxAge )(1) Distribute the dying agents sugar equally amongst its children;(2) Distribute any loans where the dying agent is the lender equally amongstits children;(3) Base case of recursion. Nothing to do but return results;(4) Recursive case: If the first agent in the list is dying then handle that agentsinheritance and recurse through the rest of the agents otherwise just ignoreit and apply the rule to rest of agents.4.10. Mating.
The AU specification of
M ating is simpler than the SU version asit does not have to construct conflict free sets. It just puts all of the potential pairsin a sequence ordered according to the variant of AU we are using and applies therule to each in turn.
HE SPECIFICATION OF SUGARSCAPE 67
AsyncAgentM ating Ξ Lattice ∆ AgentsloanBook ′ = loanBook ∃ potentialM atingP airs : P ( AGEN T × AGEN T ) | potentialM atingP airs = { ( a : AGEN T, b : AGEN T ) | sex ( a ) = sex ( b ) ∧ isF ertile ( age ( a ) , sex ( a )) ∧ isF ertile ( age ( head ) , sex ( head )) ∧ adjacent ( position ( a ) , position ( head )) } ( population ′ , position ′ , vision ′ , agentSugar ′ , agentCulture ′ ,metabolism ′ , children ′ , diseases ′ , agentImmunity ′ , age ′ , sex ′ , initialSugar ′ ) = (1) applyM ating ( rndN ewSweep ( potentialM atingP airs ) , population, position, vision,agentSugar, agentCulture, metabolism, children,diseases, agentImmunity, age, maxAge, sex, initialSugar )(1) Call applyM ating function on the agents in sequence.4.11. Credit.
M akeLoans ∆ Agents Ξ Steppopulation ′ = populationsex ′ = sexposition ′ = positionvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentCulture ′ = agentCultureagentImmunity ′ = agentImmunitydiseases ′ = diseaseschildren ′ = childrenmetabolism ′ = metabolisminitialSugar ′ = initialSugar ( loanBook ′ , agentSugar ′ ) = (1) applyLoans ( rndN ewSweep ( position ) , population, position, agentSugar, age, sex, loanBook, step (1) Call applyLoans on each agent in turn. applyLoans : seq AGEN T × P AGEN T × AGEN T P OSIT ION × AGEN T N × AGEN T N × AGEN T SEX × ( AGEN T ↔ ( AGEN T × ( N × N ))) × N → ( AGEN T ↔ ( AGEN T × ( N × N ))) × AGEN T N ∀ population : P AGEN T ; position : AGEN T P OSIT ION ; sex : AGEN T SEX ; age : AGEN T N ; agentSugar : AGEN T N ; head, ag : AGEN T ; loanBook, loans : ( AGEN T ↔ ( AGEN T × ( N × N ))); tail : seq AGEN T ; step : N ; ∃ newAgentSugar : AGEN T N ; newLoans : ( AGEN T ↔ ( AGEN T × ( N × N ))); neighbours : P AGEN T | neighbours = { b : AGEN T | vonN eumanN eighbour ( lender, b, position ) } (1)( newLoans, newAgentSugar ) = singleLenderLoans ( lender, asSeq ( neighbours ) ,agentSugar, age, sex, loanBook, step ) applyLoans ( hi , population, position, agentSugar, age, sex, loanBook, step ) = (2)( loanBook, agentSugar ) applyLoans ( h lender i a tail, population, position,agentSugar, age, sex, loanBook, step ) = (3) applyLoans ( tail, population, position, newAgentSugar, age, sex, newLoans, step )(1) Construct the set of neighbours of an agent lender , the updated loan bookand the updated sugar levels gotten by the lender giving loans to its neigh-bours;(2) Base Case: Nothing to do just return existing values;(3) Recursive case: Recursively call applyLoans on the remainder of the agents(excluding the first agent lender ) and the new loan and sugar levels gottenby lender generating new loans. HE SPECIFICATION OF SUGARSCAPE 69 singleLenderLoans : AGEN T × seq AGEN T × P AGEN T × AGEN T N × AGEN T N × AGEN T SEX × ( AGEN T ↔ ( AGEN T × ( N × N ))) × N → ( AGEN T ↔ ( AGEN T × ( N × N ))) × AGEN T N ∀ sex : AGEN T SEX ; age : AGEN T N ; agentSugar : AGEN T N ; head, lender : AGEN T ; loanBook : ( AGEN T ↔ ( AGEN T × ( N × N ))); tail : seq AGEN T ; step : N ; singleLenderLoans ( lender, hi , agentSugar, age, sex, loanBook, step ) =( loanBook, agentSugar ) singleLenderLoans ( lender, h head i a tail, agentSugar, age, sex, loans, step ) = if canLend ( age ( lender ) , sex ( lender ) , agentSugar ( lender )) ∧ willBorrow ( age ( head ) , sex ( head ) , agentSugar ( head ) , { head } ⊳ ran( loanBook ))) then ∃ newAgentSugar : AGEN T N ; newLoans : ( AGEN T × ( AGEN T × ( N × N ))); amt : N | amt = min ( amtAvail ( age ( lender ) , sex ( lender ) , agentSugar ( lender )) ,amtReq ( agentSugar ( head ))) newAgentSugar = agentSugar ⊕ { lender agentSugar ( lender ) − amt,head agentSugar ( head ) + amt } newLoans = loanBook ∪ { ( lender, ( head, ( amt, step + DU RAT ION ) } singleLenderLoans ( lender, tail, newAgentSugar, age, sex, newLoans, step ) else singleLenderLoans ( lender, tail, agentSugar, age, sex, loanBook, step ) singleLenderLoans calculates all loans that a particular agent can give to itsneighbours.(1) If there are no loans in the sequence then just return the current loans andsugar levels as is;(2) If the loan sequence is not empty then apply the payment details to thefirst loan and make the payments on the rest: a) If the first loan is capable of being paid by the borrower we simply movethe correct amount of sugar from the borrower to the lender;b) If the borrower cannot pay off the loan then they pay back half theirsugar and the loan is renegotiated for the remainder.Using these functions we can now specify the P ayLoans part of the
Credit rule.
P ayLoans ∆ Agents Ξ Steppopulation ′ = populationsex ′ = sexposition ′ = positionvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentCulture ′ = agentCultureagentImmunity ′ = agentImmunitychildren ′ = childrendiseases ′ = diseasesmetabolism ′ = metabolisminitialSugar ′ = initialSugar ∃ dueLoans, newLoans : P ( AGEN T × ( AGEN T × ( N × N ))) • dueLoans = loanBook ⊲ (ran( loanBook ) ⊲ { a : ( N × N ) | second ( a ) = step } ) (1)( newLoans, agentSugar ′ ) = makeP ayments ( asSeq ( dueLoans ) , ∅ , agentSugar )(2) loanBook ′ = ( loanBook \ dueLoans ) ∪ newLoans (3)(1) We create the set of due loans;(2) We now create the set of renegotiated loans and update the agentSugarlevels using the makeP ayments function;(3) Finally we update the loan book by removing all loans that were due andadding any new renegotiated loans.5. Added Spice
Introduction.
We have defined all the rules so far under the assumptionthat there is only one resource (known as sugar ). The final rule,
T rade , is onlydefined for simulations with at least two resources. In fact the rules are meant tobe general enough that they will work with any number of resources although weknow of no sugarscape based simulation that used more than two resources. Thesecond resource is known as spice .We will show how to extend the rules to deal with two resources. In order toavoid unnecessary clutter and make the differences as clear as possible we will
HE SPECIFICATION OF SUGARSCAPE 71 show the differences between the one and two resource schemas with boldface .Any part of a schema that is not an exact copy of the previously defined versionwill be in boldface .5.2.
Basic Types.
The basic types are copies of those already defined for sugar . M AXSP ICEM ET ABOLISM : N (1) SP ICEGROW T H : N (2) M AXSP ICE : N (3) IN IT IALSP ICEM IN, IN IT IALSP ICEM AX : N (4) SP ICEP RODU CT ION, SP ICECON SU M P T ION : N (5) SP ICECOM BAT LIM IT : N (6) SP ICECHILDAM T : N (7)(1) Agents metabolise spice during each move at an individually set rate lessthan M AXSP ICEM ET ABOLISM ;(2) Spice grows back at a predefined rate;(3) Each location can hold a set maximum amount of spice;(4) Agents created after mating start with an initial spice endowment;(5) Pollution can be caused by production and consumption of spice;(6)
SP ICECOM BAT LIM IT is required to help determine the reward fromattacking an agent using the combat rule.(7) We posit that a minimum amount of spice is needed for agent mating tooccur.Note that these constants are replicas of their sugar counterparts.5.3.
The SpiceScape.
The spice grid contains everything in the
Lattice schemeand just adds information on the extra spice resource.
SpiceLatticeLattice spice : POSITION N maxSpice : POSITION N dom spice = dom maxSpice = POSITION (1) ∀ x : POSITION • spice ( x ) ≤ maxSpice ( x ) ≤ MAXSPICE (2)(1) Every location has an associated amount of spice and maximum carryingcapacity;(2) Every position’s spice levels are within the acceptable levels.5.4.
Agents.
SpiceAgentsAgents agentSpice : AGENT N initialSpice : AGENT N spiceMetabolism : AGENT N spiceLoanBook : AGENT ↔ ( AGENT × ( N × N ))dom spiceMetabolism = dom agentSpice == dom initialtSpicepopulation (1)dom spiceLoanBook ⊆ population (2)dom(ran spiceLoanBook ) ⊆ population ∀ x : AGENT • x ∈ population ⇒ spiceMetabolism ( x ) ≤ MAXSPICEMETABOLISM (3)(1) Every agent has a spice metabolism and a spice store;(2) The spiceLoanBook has the same invariants as the original loanBook;(3) Every agents metabolism is less than or equal to the defined maximum.Finally we combine them into an overall schema as before:
SpiceScapeSpiceAgentsSpiceLatticeStep
The initialisation scheme and tick schemas are also largely unchanged.
HE SPECIFICATION OF SUGARSCAPE 73
InitialSpiceScapeSpiceAgents ′ SpiceLattice ′ Step ′ step ′ = 0 population ′ = IN IT IALP OP U LAT ION SIZEloanBook ′ = ∅ spiceLoanBook ′ = ∅ ∀ a : AGEN T • a ∈ population ′ ⇒ age ′ ( a ) = 0 diseases ′ ( a ) = ∅ children ′ ( a ) = ∅ IN IT IALSU GARM IN ≤ agentSugar ′ ( a ) ≤ IN IT IALSU GARM AXinitialSugar ′ ( a ) = agentSugar ′ ( a ) INITIALSPICEMIN ≤ agentSpice ′ ( a ) ≤ INITIALSPICEMAXinitialSpice ′ ( a ) = agentSpice ′ ( a ) T ick spice ∆ SpiceAgents ∆ Steppopulation ′ = populationposition ′ = positionsex ′ = sexvision ′ = visionmaxAge ′ = maxAgemetabolism ′ = metabolisminitialSugar ′ = initialSugar initialSpice ′ = initialSpicespiceMetabolism ′ = spiceMetabolism agentCulture ′ = agentCulturechildren ′ = childrenloanBook ′ = loanBook spiceLoanBook ′ = spiceLoanBook agentImmunity ′ = agentImmunitydiseases ′ = diseasesstep ′ = step + 1 ∀ x : AGEN T • x ∈ population ⇒ ( age ′ ( x ) = age ( x ) + 1 ∧ agentSugar ′ ( x ) = agentSugar ( x ) − metabolism ( x ) ∧ agentSpice ′ ( x ) = agentSpice ( x ) − spiceMetabolism ( x ))5.5. Rules.
As well as defining the final rule,
T rade , we will also expand the otherrules to allow them to operate on a simulation with two resources. We define thenew rule (
T rade ) first.5.6.
Agent Trade T .Agent Trade T : • Agent and neighbour compute their MRSs; if these are equal then end,else continue; • The direction of exchange is as follows: spice flows from the agent withthe higher MRS to the agent with the lower MRS while sugar goes inthe opposite direction; • The geometric mean of the two MRSs is calculated-this will serve asthe bargaining price, p ; • The quantities to be exchanged are as follows: if p > < HE SPECIFICATION OF SUGARSCAPE 75 • If this trade will (a) make both agents better off (increases the welfareof both agents), and (b) not cause the agents’ MRSs to cross over oneanother, then the trade is made and return to start, else end.MRS is calculated simply for an agent as the fraction obtained by dividing itsspice level times its sugar metabolism by its spice metabolism times its sugar level,as set out below.
M RS : N × N × N × N A ∀ sugar, sugarM etabolism, spice, spiceM etabolism : N • M RS ( sugar, sugarM etabolism, spice, spiceM etabolism ) =( spice ∗ sugarM etabolism ) / ( spiceM etabolism ∗ sugar ) tradeP airs constructs a sequence of all possible trading partners based on theproximity of the agents to each other. tradeP airs : seq AGEN T × AGEN T P OSIT ION seq( AGEN T × AGEN T ) ∀ tail : seq AGEN T ; positions : AGEN T P OSIT ION ; a : AGEN T • tradeP airs ( hi , positions ) = hi tradeP airs ( h a i a tail, positions ) = trade ( tail, positions a asSeq ( { b : agent | adjacent ( position ( a ) , position ( b )) • ( a, b ) } ) T rade ∆ SpiceAgentsspiceLoanBook ′ = spiceLoanBookloanBook ′ = loanBookpopulation ′ = populationinitialSugar ′ = initialSugar initialSpice ′ = initialSpice sex ′ = sexmetabolism ′ = metabolismspiceM etabolism ′ = spiceM etabolismposition ′ = positionvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentCulture ′ = agentCultureagentImmunity ′ = agentImmunitychildren ′ = children ∃ allP airs : seq( AGEN T, AGEN T ) | allP airs = tradeP airs ( asSeq ( population ) , position )( agentSugar ′ , agentSpice ′ ) = (1) executeT rades ( allT rades ( chooseExclusiveT rades ( allP airs ) , ( agentSugar, agentSpice ) , metabolism, spiceM etabolism )) T rade is similar to
M ating in that trading must be done in exclusive pairs. Anagent cannot carry out two simultaneous trades and the rule forces each agentto trade with all its neighbours in some sequence. As with
M ating we constructconflict free sets of trading pairs that can proceed simultaneously and then orderthese sets. chooseExclusiveT rades : AGEN T × AGEN T ↔ seq P ( AGEN T, AGEN T ) ∀ a, b : AGEN T ; tradingP airs : AGEN T ↔ AGEN T • chooseExclusiveT rades ( ∅ ) = hi chooseExclusiveT rades ( tradingP airs ) = ∃ maxSet : AGEN T ↔ AGEN T | maxSet ⊆ tradingP airs ∧ (( a, b ) ∈ tradingP airs ∧ ( a, b ) maxSet ) ⇔∃ c : AGEN T | { ( a, c ) , ( c, a ) , ( b, c ) , ( c, b ) } ∩ maxSet = ∅ ) h maxSet i a chooseExclusiveT rades ( tradingP airs \ maxSet ) HE SPECIFICATION OF SUGARSCAPE 77 executeT rades : seq(
AGEN T × AGEN T ) × AGEN T N × AGEN T N ↔ ( AGEN T N , AGEN T N ) ∀ tail : seq( AGEN T × AGEN T ); head : ( AGEN T × AGEN T ); agentSugar, agentSpice, metabolism, spiceM etabolism : AGEN T N • executeT rades ( hi , agentSugar, agentSpice, metabolism, spiceM etabolism ) =( agentSugar, agentSpice ) executeT rades ( h head i a tail, agentSugar, sugar ) = ∃ newAgentSugar, newAgentSpice : AGEN T N | ( newAgentSugar, newAgentSpice ) = allT rades ( head, ( agentSugar, agentSpice, metabolism, spiceM etabolism ) • executeT rades ( tail, newAgentSugar, newAgentSpice, metabolism, spiceM etabolism ) allT rades recursively goes through the sequence of trading partners and getseach trading pair to update the sugar and spice levels based on their trades. allT rades : seq( AGEN T × AGEN T ) × (( AGEN T N ) × ( AGEN T N )) × ( AGEN T N ) × ( AGEN T N ) ↔ (( AGEN T N ) × ( AGEN T N )) ∀ head : AGEN T × AGEN T ; tail : seq( AGEN T × AGEN T ) sugar, spice, sugarM etabolism, spiceM etabolism : AGEN T N • allT rades ( hi , ( sugar, spice ) , sugarM etabolism, spiceM etabolism ) = ( sugar, spice ) allT rades ( h head i a tail, ( sugar, spice ) , sugarM etabolism, spiceM etabolism ) = allT rades ( tail, pairT rade ( head, ( sugar, spice ) , sugarM etabolism, spiceM etabolism ) , sugarM etabolism, spiceM etabolism )Each trading partnership will execute a series of trades until their MRS scorescross over. pairT rade is complicated by the fact that there are multiple options:(1) If their MRS scores are equal then they perform no trades;(2) If their MRS scores are not equal then the direction of trade will dependon which MRS score is higher;a) Within a trade a value of p (based on MRS scores) determines the priceof the resources.(3) Trades between the pair continue until their new and old MRS scores crossover. pairT rade : ( AGEN T × AGEN T ) × (( AGEN T N ) × ( AGEN T N )) × ( AGEN T N ) × ( AGEN T N ) ↔ (( AGEN T N ) × ( AGEN T N )) ∀ a, b : AGEN T ; sugar, spice : AGEN T N ; metabolism, spiceM etabolism : AGEN T N |∃ p, mrsA, mrsB, newM rsA, newM rsB : A ; newSugar, newSpice : AGEN T N mrsA = M RS ( sugar ( a ) , metabolism ( a ) , spice ( a ) , spiceM etabolism ( a )) mrsB = M RS ( sugar ( b ) , metabolism ( b ) , spice ( b ) , spiceM etabolism ( b )) p = √ mrsA ∗ mrsB ( mrsA > mrsB ∧ p > ⇒ ( newSugar = sugar ⊕ { ( a, sugar ( a ) + 1) , ( b, sugar ( b ) − }∧ newSpice = spice ⊕ { a spice ( a ) − p, b spice ( b ) + p } )( mrsA > mrsB ∧ p ≤ ⇒ ( newSugar = sugar ⊕ { a sugar ( a ) + (1 div p ) , b sugar ( b ) − (1 div p ) } newSpice = spice ⊕ { a spice ( a ) − , b spice ( b ) + 1 } )( mrsA ≤ mrsB ∧ p > ⇒ ( newSugar = sugar ⊕ { b sugar ( b ) + 1 , a sugar ( a ) − }∧ newSpice = spice ⊕ { b spice ( b ) − p, a spice ( a ) + p } )( mrsA ≤ mrsB ∧ p ≤ ⇒ ( newSugar = sugar ⊕ { b sugar ( b ) + (1 div p ) , a sugar ( a ) − (1 div p ) }∧ newSpice = spice ⊕ { b spice ( b ) − , a spice ( a ) + 1 } ) newM rsA = M RS ( newSugar ( a ) , metabolism ( a ) , newSpice ( a ) , spiceM etabolism ( a )) newM rsB = M RS ( newSugar ( b ) , metabolism ( b ) , newSpice ( b ) , spiceM etabolism ( b )) • pairT rade (( a, b ) , ( sugar, spice ) , metabolism, spiceM etabolism ) = ( sugar, spice ) ⇔ mrsA = mrsBpairT rade (( a, b ) , ( sugar, spice ) , metabolism, spiceM etabolism ) = ( newSugar, newSpice ) ⇔ (( mrsA > mrsB ∧ newM rsA ≤ newM rsB ) ∨ ( mrsA < mrsB ∧ newM rsA ≥ newM rsB )) pairT rade (( a, b ) , ( sugar, spice ) , metabolism, spiceM etabolism ) = pairT rade (( a, b ) , ( newSugar, newSpice ) , metabolism, spiceM etabolism ) ⇔ (( mrsA > mrsB ∧ newM rsA > newM rsB ) ∨ ( mrsA < mrsB ∧ newM rsA < newM rsB ))5.7. Asynchronous Trade.
HE SPECIFICATION OF SUGARSCAPE 79
T rade ∆ SpiceAgentsspiceLoanBook ′ = spiceLoanBookloanBook ′ = loanBookpopulation ′ = populationsex ′ = sexmetabolism ′ = metabolismspiceM etabolism ′ = spiceM etabolisminitialSugar ′ = initialSugar initialSpice ′ = initialSpice position ′ = positionvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentCulture ′ = agentCultureagentImmunity ′ = agentImmunitychildren ′ = children ∃ traders : P ( AGEN T × AGEN T ) • ( agentSugar ′ , agentSpice ′ ) = (1) allT rades ( tradeP airs ( rndN ewSweep ( position ) , positions ) , ( agentSugar, agentSpice ) ,metabolism, spiceM etabolism )(1) The new sugar and spice allocations are derived by conducting all possibletrades using the recursive helper function allT rades .5.7.1. Growback.
Growback spice ∆ SpiceLattice (1) pollution ′ = pollutionmaxSugar ′ = maxSugar maxSpice ′ = maxSpice (2) sugar ′ = sugar ⊕ { x : P OSIT ION • x min ( { sugar ( x ) + SU GARGROW T H, maxSugar ( x ) } ) } spice ′ = spice ⊕ { x : POSITION • x min ( { spice ( x ) + SPICEGROWTH , maxSpice ( x ) } ) } (3)(1) Lattice is replaced with
SpiceLattice . In all subsequent schemas
SpiceLattice replaces
Lattice and
SpiceAgent replaces
Agent ;(2) maxSpice remains unchanged;(3) The new spice levels are calculated using the same simple formula used forsugar growback.
Seasonal Growback.
SeasonalGrowback spice ∆ SpiceLattice Ξ Steppollution ′ = pollutionmaxSugar ′ = maxSugar maxSpice ′ = maxSpice ∀ x : P OSIT ION • ( step div SEASON LEN GT H ) mod 2 = 0 ⇒ sugar ′ = { x : P OSIT ION | f irst ( x ) < M div 2 • x min ( { sugar ( x ) + SU GARGROW T H, maxSugar ( x ) } ) }∪{ x : P OSIT ION | f irst ( x ) ≥ M div 2 • x min ( { sugar ( x ) + SU GARGROW T H div
W IN T ERRAT E, maxSugar ( x ) } ) }∀ x : P OSIT ION • ( step div SEASON LEN GT H ) mod 2 = 0 ⇒ sugar ′ = { x : P OSIT ION | f irst ( x ) < M div 2 • x min ( { sugar ( x ) + SU GARGROW T H div
W IN T ERRAT E, maxSugar ( x ) } ) }∪{ x : P OSIT ION ; y : N | f irst ( x ) ≥ M div 2 • x min ( { sugar ( x ) + SU GARGROW T H, maxSugar ( x ) } ) }∀ x : POSITION • (1)( step div SEASONLENGTH ) mod = ⇒ spice ′ = { x : POSITION | first ( x ) < M div • x min ( { spice ( x ) + SPICEGROWTH , maxSpice ( x ) } ) }∪{ x : POSITION | first ( x ) ≥ M div • x min ( { spice ( x ) + SPICEGROWTH div
WINTERRATE , maxSpice ( x ) } ) }∀ x : POSITION • ( step div SEASONLENGTH ) mod = ⇒ spice ′ = { x : POSITION | first ( x ) < M div • x min ( { spice ( x ) + SPICEGROWTH div
WINTERRATE , maxSpice ( x ) } ) }∪{ x : POSITION | first ( x ) ≥ M div • x min ( { spice ( x ) + SPICEGROWTH , maxSpice ( x ) } ) } (1) Seasonal growback adds a rule for spice grow back that is an exact replicaof the sugar rule. We note that we only use the one W IN T ERRAT E instead of a separate rate for sugar and spice. In the absence of any explicitdirection on this point this solution seems to be the most obvious.
HE SPECIFICATION OF SUGARSCAPE 81
Movement.
In order to update Movement we will need to implement a wel-fare function that can be used to measure the desirability of a location. With tworesources the desirability of any location becomes a subjective measure, what oneagent may rate highly another may not. Welfare is dependent on the agents currentlevels of spice and sugar, so an agent with low spice levels may consider a locationcontaining spice more desirable than one containing sugar. Overall the desirabilityof a location is determined by the agents current resource levels (wealth) and therelative metabolism rates for each resource.This is in contrast to the previous approach where welfare just equaled theamount of sugar in a location. This welfare measure is precisely defined in thebook and we follow this definition. welf are : N × N × N × N × N × N A ∀ agentSugar, sugarM etabolism,agentSpice, spiceM etabolism,locationSugar, locationSpice : N • welf are ( agentSugar, sugarM etabolism, agentSpice, spiceM etabolism,locationSugar, locationSpice ) =( locationSugar + agentSugar ) ∗ ( sugarM etabolism div( sugarM etabolism + spiceM etabolism )) ∗ ( locationSpice + agentSpice ) ∗ ( spiceM etabolism div( sugarM etabolism + spiceM etabolism ))Movement can now be restated by replacing the previous measure of a locationsdesirability (sugar level) with this new measure and the updating of spice levels.In all other respects the schema remains unchanged. M ovement basicSpice ∆ SpiceScapestep ′ = steppopulation ′ = populationmaxSugar ′ = maxSugarpollution ′ = pollutionsex ′ = sexvision ′ = visionage ′ = ageinitialSugar ′ = initialSugar initialSpice ′ = initialSpice metabolism ′ = metabolismmaxAge ′ = maxAgeagentCulture ′ = agentCultureloanBook ′ = loanBookdiseases ′ = diseasesagentImmunity ′ = agentImmunitychildren ′ = children maxSpice ′ = maxSpicespiceLoanBook ′ = spiceLoanBookspiceMetabolism ′ = spiceMetabolism ∀ a : AGEN T ; l : P OSIT ION • a ∈ population ⇒ distance ( position ′ ( a ) , position ( a )) ≤ vision ( a ) distance ( position ( a ) , l ) ≤ vision ( a ) ∧ ( l ran position ′ )) ⇒ welfare ( agentSugar ( a ) , metabolism ( a ) , (1) agentSpice ( a ) , spiceMetabolism ( a ) , sugar ( l ) , spice ( l )) < welfare ( agentSugar ( a ) , metabolism ( a ) , agentSpice ( a ) , spiceMetabolism ( a ) , sugar ( position ′ ( a )) , spice ( position ′ ( a ))) agentSugar ′ = { a : AGEN T | a ∈ population • a agentSugar ( a ) + sugar ( position ′ ( a )) } sugar ′ = sugar ⊕ { loc : P OSIT ION | loc ∈ ran position ′ • loc } agentSpice ′ = { a : AGENT | a ∈ population • (2) a agentSpice ( a )+ spice ( position ′ ( a )) } spice ′ = spice ⊕ { loc : POSITION | loc ∈ ran position ′ • loc } (3)(1) This is a copy of the original proposition with the welf are function nowreplacing the previous sugar level check;(2) Agents consume spice at their new locations;(3) Locations with agents present now have no remaining spice. HE SPECIFICATION OF SUGARSCAPE 83
Pollution Formation P Π ,χ . The
M ovement spiceP ollution schema has the samealterations as the
M ovement basicSpice
M ovement pollutionSpice ∆ SpiceScapestep ′ = steppopulation ′ = populationmaxSugar ′ = maxSugarsex ′ = sexpollution ′ = pollutionvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentCulture ′ = agentCultureloanBook ′ = loanBookchildren ′ = childrenagentImmunity ′ = agentImmunityinitialSugar ′ = initialSugar initialSpice ′ = initialSpice diseases ′ = diseasesmetabolism ′ = metabolism spiceMetabolism ′ = spiceMetabolismspiceLoanBook ′ = spiceLoanBookmaxSpice ′ = maxSpice ∀ a : AGEN T ; l : P OSIT ION | a ∈ dom( position ′ ) • a ∈ population ⇒ distance ( position ′ ( a ) , position ( a )) ≤ vision ( a )( distance ( position ( a ) , l ) ≤ vision ( a ) ∧ ( l ran position ′ )) ⇒ welfare ( agentSugar ( a ) , metabolism ( a ) , agentSpice ( a ) , spiceMetabolism ( a ) , sugar ( l ) , spice ( l ))div( + pollution ( l )) < welfare ( agentSugar ( a ) , metabolism ( a ) , agentSpice ( a ) , spiceMetabolism ( a ) , sugar ( position ′ ( a )) , spice ( position ′ ( a ))) div ( + pollution ( position ′ ( a ))) agentSugar ′ = { a : AGEN T | a ∈ population • a agentSugar ( a ) + sugar ( position ′ ( a )) } sugar ′ = sugar ⊕ { l : P OSIT ION | l ∈ ran position ′ • l } agentSpice ′ = { a : AGENT | a ∈ population • a agentSpice ( a ) + spice ( position ′ ( a )) } spice ′ = spice ⊕ { l : POSITION | l ∈ ran position ′ • l } pollution ′ = pollution ⊕{ l : P OSIT ION ; x : AGEN T | position ′ ( x ) = l • l ( P RODU CT ION ∗ sugar ( l ) + CON SU M P T ION ∗ metabolism ( x )) } HE SPECIFICATION OF SUGARSCAPE 85
Pollution Diffusion.
P ollutionDif f usion spice ∆ SpiceLattice Ξ StepmaxSugar ′ = maxSugarsugar ′ = sugar maxSpice ′ = maxSpicespice ′ = spice ( step mod P OLLU T ION RAT E = 0) ⇒ pollution ′ = pollution ( step mod P OLLU T ION RAT E = 0) ⇒ pollution ′ = { l : P OSIT ION • l ( pollution ( north ( l )) + pollution ( south ( l ))+ pollution ( east ( l )) + pollution ( west ( l ))) div 4 } Replacement.
Death spice ∆ SpiceAgentspopulation ′ = population \ { a : AGEN T | age ( a ) = maxAge ( a ) ∨ agentSugar ( a ) = 0 ∨ agentSpice ( a ) = • a } loanBook ′ = population ′ ⊳ loanBook ⊲ { x : AGEN T × ( N × N ) | f irst ( x ) ∈ population ′ } spiceLoanBook ′ = population ′ ⊳ spiceLoanBook ⊲ { x : AGENT × ( N × N ) | first ( x ) ∈ population ′ }∀ a : AGEN T • a ∈ population ′ ⇒ ( sex ( a ) = sex ′ ( a ) ∧ vision ( a ) = vision ′ ( a ) ∧ maxAge ( a ) = maxAge ′ ( a ) ∧ agentCulture ( a ) = agentCulture ′ ( a ) ∧ position ( a ) = position ′ ( a ) ∧ age ( a ) = age ′ ( a ) ∧ agentSugar ( a ) = agentSugar ′ ( a ) ∧ metabolism ′ ( a ) = metabolism ( a ) ∧ diseases ′ ( a ) = diseases ( a ) ∧ agentImmunity ′ ( a ) = agentImmunity ( a ) ∧ children ′ ( a ) = children ( a ) ∧ initialSugar ′ ( a ) = initialSugar ( a ) ∧ agentSpice ′ ( a ) = agentSpice ( a ) ∧ initialSpice ′ ( a ) = initialSpice ( a ) ∧ spiceMetabolism ′ ( a ) = spiceMetabolism ( a )) Replacement spice ∆ SpiceAgents population ′ = IN IT IALP OP U LAT ION SIZEloanBook ′ = loanBookspiceLoanBook ′ = spiceLoanBook ∀ a : AGEN T • a ∈ ( population ) ⇒ ( a ∈ population ′ ∧ sex ( a ) = sex ′ ( a ) ∧ vision ( a ) = vision ′ ( a ) ∧ maxAge ( a ) = maxAge ′ ( a ) ∧ agentCulture ( a ) = agentCulture ′ ( a ) ∧ position ( a ) = position ′ ( a ) ∧ age ( a ) = age ′ ( a ) ∧ agentSugar ′ ( a ) = agentSugar ( a ) ∧ metabolism ′ ( a ) = metabolism ( a ) ∧ initialSugar ′ ( a ) = initialSugar ( a ) ∧ initialSpice ′ ( a ) = initialSpice ( a ) ∧ agentSpice ′ ( a ) = agentSpice ( a ) ∧ spiceMetabolism ′ ( a ) = spiceMetabolism ( a ) ∧ diseases ′ ( a ) = diseases ( a ) ∧ agentImmunity ′ ( a ) = agentImmunity ( a ) ∧ children ′ ( a ) = children ( a )) ∀ a : AGEN T • a ∈ population ′ \ population ⇒ ( age ′ ( a ) = 0 ∧ IN IT IALSU GARM IN ≤ agentSugar ′ ( a ) ≤ IN IT IALSU GARM AX ∧ initialSugar ′ ( a ) = agentSugar ′ ( a ) ∧ INITIALSPICEMIN ≤ agentSpice ′ ( a ) ≤ INITIALSPICEMAX ∧ initialSpice ′ ( a ) = agentSpice ′ ( a ) ∧ diseases ′ ( a ) = ∅ ∧ children ′ ( a ) = ∅ )5.12. Agent Mating.
HE SPECIFICATION OF SUGARSCAPE 87
AgentM ating Ξ Lattice ∆ AgentsloanBook ′ = loanBook ∧ spiceLoanBook ′ = spiceLoanBook ∃ potentialM atingP airs : P ( AGEN T × AGEN T ) | (1) potentialM atingP airs = { ( a : AGEN T, b : AGEN T ) | sex ( a ) = sex ( b ) ∧ isF ertile ( age ( a ) , sex ( a )) ∧ isF ertile ( age ( head ) , sex ( head )) ∧ adjacent ( position ( a ) , position ( head )) } ( population ′ , position ′ , vision ′ , agentSugar ′ , agentCulture ′ , metabolism ′ , children ′ , diseases ′ , agentImmunity ′ , age ′ , sex ′ , initialSugar ′ , spiceMetabolism ′ , agentSpice ′ , initialSpice ′ ) = (2) concurrentM ating ( getConf ictF reeP airs ( potentialM atingP airs ) , population, position, vision,agentSugar, agentCulture, metabolism, children,diseases, agentImmunity, age, maxAge, sex, initialSugar, spiceMetabolism , agentSpice , initialSpice )(1) Generate the set of all possible mating pairs;(2) Recursively proceed with concurrent mating within the conflict free subsets. concurrentM ating : seq P ( AGEN T × AGEN T ) × P AGEN T × AGEN T P OSIT ION × AGEN T N × AGEN T N × AGEN T seq BIT × AGEN T N × AGEN T P AGEN T × AGEN T P seq BIT × AGEN T seq BIT × AGEN T N × AGEN T N × AGEN T SEX × AGEN T N × AGENT N × AGENT N × AGENT N ↔ P AGEN T × AGEN T P OSIT ION × AGEN T N × AGEN T N × AGEN T seq BIT × AGEN T N × AGEN T P AGEN T × AGEN T P seq BIT × AGEN T seq BIT × AGEN T N × AGEN T N × AGEN T SEX × AGEN T N × AGENT N × AGENT N × AGENT N ∀ tail : seq P ( AGEN T × AGEN T ); head : P ( AGEN T × AGEN T ); population : P AGEN T ; position : AGEN T P OSIT ION ; vision : AGEN T N ; agentSugar, agentSpice : AGEN T N ; agentCulture : AGEN T seq BIT ; metabolism, spiceMetabolism : AGEN T N ; children : AGEN T P AGEN T ; diseases : AGEN T P seq BIT ; agentImmunity : AGEN T seq BIT ; age : AGEN T N ; maxAge : AGEN T N ; sex : AGEN T SEX ; initialSugar, initialSpice : AGEN T N ; HE SPECIFICATION OF SUGARSCAPE 89 ∃ newpopulation : P AGEN T ; newposition : AGEN T P OSIT ION ; newvision : AGEN T N ; newagentSugar, newagentSpice : AGEN T N ; newagentCulture : AGEN T seq BIT ; newmetabolism, newspiceMetabolism : AGEN T N ; newchildren : AGEN T P AGEN T ; newdiseases : AGEN T P seq BIT ; newagentImmunity : AGEN T seq BIT ; newage : AGEN T N ; newmaxAge : AGEN T N ; newsex : AGEN T SEX ; newinitialSugar, newinitialSpice : AGEN T N ; | ( newpopulation, newposition, newvision, newagentSugar, newagentCulture,newmetabolism, newchildren, newdiseases, newagentImmunity, newage, newmaxAge,newsex, newinitialSugar, newspiceMetabolism , newagentSpice , newinitialspice ) = applyM ating ( asSeq ( head ) , population, position, vision,agentSugar, agentCulture, metabolism, children,diseases, agentImmunity, age, maxAge, sex, initialSugar, spiceMetabolism , agentSpice , initialspice ) • concurrentM ating ( hi , population, position, vision,agentSugar, agentCulture, metabolism, children,diseases, agentImmunity, age, maxAge, sex, initialSugar ) =( population, position, vision, agentSugar, agentCulture, metabolism,children, diseases, agentImmunity, age, maxAge, sex, initialSugar, spiceMetabolism , agentSpice , initialspice ) concurrentM ating ( h head i a tail, population, position, vision,agentSugar, agentCulture, metabolism, children,diseases, agentImmunity, age, maxAge, sex, initialSugar ) = concurrentM ating ( tail, newpopulation, newposition, newvision,newagentSugar, newagentCulture, newmetabolism, newchildren,newdiseases, newagentImmunity, newage, newmaxAge, newsex, newinitialSugar, newspiceMetabolism , newagentSpice , newinitialspice ) applyM ating : seq( AGEN T × AGEN T ) × P AGEN T × AGEN T P OSIT ION × AGEN T N × AGEN T N × AGEN T seq BIT × AGEN T N × AGEN T P AGEN T × AGEN T P seq BIT × AGEN T seq BIT × AGEN T N × AGEN T N × AGEN T SEX × AGEN T N × AGENT N × AGENT N × AGENT N ↔ P AGEN T × AGEN T P OSIT ION × AGEN T N × AGEN T N × AGEN T seq BIT × AGEN T N × AGEN T P AGEN T × AGEN T P seq BIT × AGEN T seq BIT × AGEN T N × AGEN T N × AGEN T SEX × AGEN T N × AGENT N × AGENT N × AGENT N ∀ population : P AGEN T ; position : AGEN T P OSIT ION ; sex : AGEN T SEX ; vision : AGEN T N ; age : AGEN T N ; initialSugar, initialSpice : AGEN T N ; maxAge : AGEN T N ; metabolism, spiceMetabolism : AGEN T N ; agentSugar, agentSpice : AGEN T N ; agentCulture : AGEN T seq BIT ; children : AGEN T P AGEN T ; agentImmunity : AGEN T seq BIT ; diseases : AGEN T P seq BIT ; head : AGEN T × AGEN T ; tail : seq( AGEN T × AGEN T ); • HE SPECIFICATION OF SUGARSCAPE 91 ∃ of f spring, a, b : AGEN T ; newsex : AGEN T SEX ; newvision : AGEN T N ; newmetabolism, newagentSugar, newinitialSugar : AGEN T N ; newspiceMetabolism , newagentSpice , newinitialSpice : AGENT N ; newmaxAge : AGEN T N ; newagentCulture : AGEN T seq BIT ; newchildren : AGEN T P AGEN T ; newagentImmunity : AGEN T seq BIT ; inheritedImmunity : seq BIT ; inheritedCulture : seq BIT ; | of f spring populationa = f irst ( head ) ∧ b = second ( head ) newchildren : children ∪ { of f spring ∅ a children ( a ) ∪ { of f spring } ,b children ( b ) ∪ { of f spring }} newsex = sex ∪ { of f spring male }∨ newsex = sex ∪ { of f spring f emale } newvision = vision ∪ { of f spring vision ( a ) }∨ newvision = vision ∪ { of f spring vision ( b ) } newmaxAge = maxAge ∪ { of f spring maxAge ( a ) }∨ newmaxAge = maxAge ∪ { of f spring maxAge ( b ) } newmetabolism = metabolism ∪ { of f spring metabolism ( a ) }∨ newmetabolism = metabolism ∪ { of f spring metabolism ( b ) } newspiceMetabolism = spiceMetabolism ∪ { offspring spiceMetabolism ( a ) }∨ newspiceMetabolism = spiceMetabolism ∪ { offspring spiceMetabolism ( b ) } newinitialSugar = initialSugar ⊕{ of f spring initialSugar ( a ) / initialSugar ( b ) / } newagentSugar = agentSugar ⊕ { of f spring initialSugar ( of f spring ) , a initialSugar ( a ) / , b newinitialSpice = initialSpice ⊕{ offspring initialSpice ( a ) / + initialSpice ( b ) / } newagentSpice = agentSpice ∪ { offspring initialSpice ( offspring ) , a initialSpice ( a ) / , b ∧ ∀ n : 1 . . IM M U N IT Y LEN GT H • ( inheritedImmunity ( n ) = agentImmunity ( a )( n ) ∨ inheritedImmunity ( n ) = agentImmunity ( b )( n )) newagentImmunity : agentImmunity ∪ { of f spring inheritedImmunity }∧ ∀ n : 1 . . CU LT U RECOU N T • ( inheritedCulture ( n ) = agentCulture ( a )( n ) ∨ inheritedCulture ( n ) = agentCulture ( b )( n )) newagentCulture : agentCulture ∪ { of f spring inheritedCulture } applyM ating ( hi , population, position, vision, agentSugar, agentCulture,metabolism, children, diseases, agentImmunity, age, maxAge, sex, initialSugar, spiceMetabolism , agentSpice , initialSpice ) =( population, position, vision, agentSugar, agentCulture, metabolism,children, diseases, agentImmunity, age, maxAge, sex, initialSugar, spiceMetabolism , agentSpice , initialSpice ) applyM ating ( h head i a tail, population, position, vision, agentSugar, agentCulture,metabolism, children, diseases, agentImmunity, age, maxAge, sex, initialSugar, spiceMetabolism , agentSpice , initialSpice ) = if (( ∃ loc : P OSIT ION | ( adjacent ( loc, position ( ag ))) ∨ adjacent ( loc, position ( head )) ∧ loc dom position ) ∧ ( agentSpice ( head ) > initialSpice ( head )) ∧ ( agentSpice ( ag ) > initialSpice ( applyM ating ( tail, population ∪ { of f spring } , position ∪ { of f spring loc } ,newvision, newagentSugar, newagentCulture, newmetabolism,newchildren, diseases ∪ { of f spring ∅ } , newagentImmunity,age ∪ { of f spring } , newmaxAge, newsex, initialSugar, newspiceMetabolismelse applyM ating ( tail, population, position, vision, agentSugar, agentCulture,metabolism, children, diseases, agentImmunity, age, maxAge, sex, initialSugar, spiceMetabolism , agentSpice , initialSpice )5.13. Culture.
HE SPECIFICATION OF SUGARSCAPE 93
Culture spice ∆ SpiceAgentspopulation ′ = populationsex ′ = sexposition ′ = positionvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentSugar ′ = agentSugarchildren ′ = childrenloanBook ′ = loanBookdiseases ′ = diseasesinitialSugar ′ = initialSugarmetabolism ′ = metabolismagentImmunity ′ = agentImmunity agentSpice ′ = agentSpicespiceMetabolism ′ = spiceMetabolismspiceLoanBook ′ = spiceLoanBookinitialSpice ′ = initialSpice ∀ a : AGEN T • a ∈ population ⇒ agentCulture ′ ( a ) = f lipT ags ( agentCulture ( a ) ,asSeq ( { b : AGEN T | adjacent ( position ( a ) , position ( b )) } ) , agentCulture )5.14. Disease.
ImmuneResponse spice Ξ SpiceLattice ∆ SpiceAgents Ξ SteploanBook ′ = loanBook spiceLoanBook ′ = spiceLoanBook population ′ = populationsex ′ = sexposition ′ = positionvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentCulture ′ = agentCulturediseases ′ = diseaseschildren ′ = childrenagentSugar ′ = agentSugarinitialSugar ′ = initialSugar initialSpice ′ = initialSpice metabolism ′ = metabolism agentSpice ′ = agentSpicespiceMetabolism ′ = spiceMetabolism agentImmunity ′ = { a : AGEN T | a ∈ population • a applyDiseases ( agentImmunity ( a ) , asSeq ( diseases ( a ))) }∀ x : AGEN T • x ∈ population ⇒ agentSugar ′ ( x ) = agentSugar ( x ) − { d : seq BIT | d ∈ diseases ( a ) ∧ ¬ subseq ( d, agentImmunity ( a ) }∀ x : AGEN T • x ∈ population ⇒ agentSpice ′ ( x ) = agentSpice ( x ) − { d : seq BIT | d ∈ diseases ( a ) ∧ ¬ subseq ( d, agentImmunity ( a ) } HE SPECIFICATION OF SUGARSCAPE 95
T ransmission spice ∆ SpiceAgentsloanBook ′ = loanBookinitialSugar ′ = initialSugar spiceLoanBook ′ = spiceLoanBook population ′ = populationsex ′ = sexposition ′ = positionvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentCulture ′ = agentCultureagentImmunity ′ = agentImmunitychildren ′ = childrenagentSugar ′ = agentSugar agentSpice ′ = agentSpicespiceMetabolism ′ = spiceMetabolisminitialSpice ′ = initialSpice metabolism ′ = metabolism ∀ a : AGEN T • a ∈ population ⇒ diseases ′ ( a ) = diseases ( a ) ∪ newDiseases ( asSeq ( visibleAgents ( a, position, , diseases )5.15. Inheritance.
Inheritance spice ∆ SpiceAgentspopulation ′ = population ∧ sex ′ = sexposition ′ = position ∧ vision ′ = visionage ′ = age ∧ maxAge ′ = maxAgeagentCulture ′ = agentCulture ∧ children ′ = childrenmetabolism ′ = metabolism ∧ spiceMetabolism ′ = spiceMetabolism diseases ′ = diseases ∧ agentImmunity ′ = agentImmunityinitialSugar ′ = initialSugar initialSpice ′ = initialSpice ∃ dying : P AGEN T ; inheritF romF emale, inheritF romM ale : AGEN T ( N × N ) • (1)dom inheritF romF emale = dom inheritF romM ale = population \ dyingdying = { x : AGEN T | x ∈ population ∧ ( age ( x ) = maxAge ( x ) ∨ agentSugar ( x ) = 0 ∨ agentSpice ( x ) = ) } (2) ∀ x : AGEN T ; n, m : N | x ∈ population \ dying • getM other ( x, children, sex ) dying ⇒ inheritF romF emale ( x ) = (0 , getF ather ( x, children, sex ) dying ⇒ inheritF romM ale ( x ) = (0 , ∃ m : AGEN T | m = getM other ( x, children, sex ) ∧ m ∈ dying ⇒ inheritF romF emale ( x ) =( agentSugar ( m ) div population ∩ children ( m ) \ dying ))( agentSpice ( m ) div population ∩ children ( m ) \ dying )) (3) ∃ d : AGEN T | d = getF ather ( x, children, sex ) ∧ d ∈ dying ⇒ inheritF romM ale ( x ) = agentSugar ( d ) div population ∩ children ( d ) \ dying ))( agentSpice ( m ) div population ∩ children ( m ) \ dying )) x ∈ dying ⇒ ( agentSugar ′ ( x ) = 0 ∧ agentSpice ′ ( x ) = ) x dying ⇒ ( agentSugar ′ ( x ) = agentSugar ( x )+ f irst ( inheritF romM ale ( x )) + f irst ( inheritF romF emale ( x )) ∧ agentSpice ′ ( x ) = agentSpice ( x )+ second ( inheritFromFemale ( x )) + second ( inheritFromMale ( x ))) loanBook ′ = disperseLoans ( loanBook, asSeq ( dying ) , children ) spiceLoanBook ′ = disperseLoans ( spiceLoanBook , asSeq ( dying ) , children ) (4)(1) Agents can now inherit two amounts, a sugar inheritance and a spice inheritance; HE SPECIFICATION OF SUGARSCAPE 97 (2) Death now occurs if either resource reaches zero;(3) The individual spice inheritance is calculated in the same way as the sugar inheritance;(4) Spice loans are dispersed amongst children.5.16.
Combat.
Combat is defined only in terms of sugar. We can either acceptthis and assume combat is based only on sugar levels or we can extend combatby defining new versions of wealth and reward. We note that no simulationscombining combat with more than one resource are presented in the book.We can extend the combat rule with a few simple assumptions. First the wealthof an agent is used to determine if we can attack that agent or if an agent canretaliate against us. In the single resource scenario we simply used the sugar thatan agent carried. With two resources we need to combine both sugar and spice.The simplest approach is to add these two amounts together and in the absenceof any guidelines this seems the sensible option. availM oves requires only minor changes to return the set of all safe moves thatan agent can make. availM oves spice : AGEN T × ( AGEN T P OSIT ION ) × ( P OSIT ION N ) × ( AGEN T N ) × ( P OSIT ION N ) × ( AGEN T N ) × ( AGEN T seq BIT ) × N P P OSIT ION ∀ x, agent : AGEN T ; positions : AGEN T P OSIT ION ; vision : N ; sugar, spice : P OSIT ION N ; agentSpice, agentSugar : AGEN T N ; culture : AGEN T seq BIT • availM oves spice ( agent, positions, sugar, agentSugar, spice, agentSpice, culture, vision ) = { l : P OSIT ION ; x : AGEN T | l ∈ distance ( l, positions ( agent )) ≤ vision ∧ positions ( x ) = l ⇒ ( agentSugar ( x )+ agentSpice ( x ) AGEN T × P AGEN T × ( AGEN T P OSIT ION ) × ( P OSIT ION N ) × ( AGEN T N ) × ( AGEN T N ) × ( AGEN T N ) × ( AGEN T seq BIT ) → ( P AGEN T × ( AGEN T P OSIT ION ) × ( P OSIT ION N ) × ( AGEN T N ) × ( AGEN T N )) ∀ head : AGEN T ; tail : seq AGEN T ; pop : P AGEN T ; positions : AGEN T P OSIT ION ; sugar : P OSIT ION N ; agSugar, agSpice : AGEN T N ; vision : AGEN T N ; culture : AGEN T seq BIT • applyAllCombat ( hi , pop, positions, sugar, agSugar, agSpice, vision, culture ) =( pop, positions, sugar, agSugar, agSpice ) applyAllCombat ( h head i a tail, pop, positions, sugar, agSugar, agSpice, vision, culture ) = if ( head ∈ pop ) then applyAllCombat spice ( tail,singleF ight spice ( head, pop, positions, sugar, agSugar, agSpice, vision, culture )) else applyAllCombat spice ( tail, pop, positions, sugar, agSugar, agSpice, vision, culture ) 00 JOSEPH KEHOE singleF ight spice : AGEN T × P AGEN T × ( AGEN T P OSIT ION ) × ( P OSIT ION N × ( AGEN T N ) × ( AGEN T N ) × ( AGEN T N ) × ( AGEN T seq BIT ) → ( P AGEN T × ( AGEN T P OSIT ION ) × ( P OSIT ION N ) × ( AGEN T N ) × ( AGEN T N )) ∀ ag : AGEN T ; population : P AGEN T ; positions : AGEN T P OSIT ION ; sugar : P OSIT ION N ; agSugar, agSpice : AGEN T N ; vision : AGEN T N ; culture : AGEN T seq BIT • singleF ight spice ( ag, population, positions, sugar, agSugar, agSpice, vision, culture ) = if ( availM oves ( ag, positions, sugar, agSugar, agSpice, culture, vision ( ag )) = ∅ ) then ( population, positions, sugar, agSugar, agSpice ) else ∃ loc : P OSIT ION ; available : P P OSIT ION ; ∀ otherLoc : P OSIT ION | loc, otherLoc ∈ availM oves spice ( ag, positions, sugar, agSugar, agSpice, culture, vision ( ag )) ∧ otherLocation = locationreward ( loc, sugar, position, agSugar, COM BAT LIM IT )+ reward ( loc , spice , position , agSpice , SPICECOMBATLIMIT ) ≥ reward ( otherLoc, sugar, position, agSugar, COM BAT LIM IT )+ reward ( otherLoc , spice , position , agSpice , SPICECOMBATLIMIT )( distance ( position ( ag ) , loc ) > distance ( position ( otherLoc ) , position ′ ( ag )) ⇒ reward ( loc, sugar, position, agSugar, COM BAT LIM IT )+ reward ( loc , sugar , position , agSpice , SPICECOMBATLIMIT ) > reward ( otherLoc, sugar, position, agSugar, COM BAT LIM IT )+ reward ( otherLoc , spice , position , agSpice , SPICECOMBATLIMIT )) • ( population \ { positions ∼ ( loc ) } , ( positions − ⊲ { loc } ) ⊕ { ag loc } , sugar ⊕ { loc } ,agSugar ⊕ { ag agSugar ( ag )+ reward ( position ′ ( ag ) , sugar, position, agSugar, COM BAT LIM IT ) } , agSpice ⊕ { ag agSpice ( ag )+ reward ( position ′ ( ag ) , spice , position , agSpice , SPICECOMBATLIMIT ) } ) HE SPECIFICATION OF SUGARSCAPE 101 SynchronousCombat spice ∆ SugarScapestep ′ = stepmaxSugar ′ = maxSugar maxSpice ′ = maxSpice pollution ′ = pollutionloanBook ′ = population ′ ⊳ loanBook ⊲ ( population ′ ⊳ (ran loanBook )) spiceLoanBook ′ = population ′ ⊳ spiceLoanBook ⊲ ( population ′ ⊳ (ran spiceLoanBook )) population ′ ⊆ populationsugar ′ = sugar ⊕ { p : P OSIT ION | p ∈ ran position ′ • p }∀ ag : AGEN T ; l : P OSIT ION • ag ∈ population ′ ⇒ ( sex ′ ( ag ) = sex ( ag ) ∧ vision ′ ( ag ) = vision ( ag ) ∧ age ′ ( ag ) = age ( ag ) ∧ maxAge ′ ( ag ) = maxAge ( ag ) ∧ children ′ ( ag ) = children ( ag ) ∧ agentCulture ′ ( ag ) = agentCulture ( ag ) ∧ agentImmunity ′ ( ag ) = agentImmunity ( ag ) ∧ metabolism ′ ( ag ) = metabolism ( ag ) ∧ initialSugar ′ ( ag ) = initialSugar ( ag ) ∧ initialSpice ′ ( ag ) = initialSpice ( ag ) ∧ spiceMetabolism ( ag ) = spiceMetabolism ( ag ) ∧ diseases ′ ( ag ) = diseases ( ag ) ∧ agentSugar ′ ( ag ) = agentSugar ( ag )+ reward ( position ′ ( ag ) , sugar, position, agentSugar, COM BAT LIM IT ) ∧ agentSpice ′ ( ag ) = agentSpice ( ag )+ reward ( position ′ ( ag ) , spice , position , agentSpice , SPICECOMBATLIMIT ) ∧ position ′ ( ag ) ∈ availM oves spice ( ag, position, sugar, agentSugar,agentSpice, agentCulture, vision ( ag )))) ag ∈ population \ population ′ ⇒∃ x : AGEN T • position ′ ( x ) = position ( ag ) ∧ tribe ( culture ( x )) = tribe ( culture ( ag ))( l ∈ availM oves spice ( ag, position, sugar, agentSugar, agentSpice, agentCulture, vision ( ag )) ∧ reward ( l, sugar, position, agentSugar, COM BAT LIM IT )+ reward ( l , spice , position , agentSpice , SPICECOMBATLIMIT ) ≥ reward ( position ′ ( ag ) , sugar, position, agentSugar, COM BAT LIM IT )+ reward ( position ′ ( ag ) , spice , position , agentSpice , SPICECOMBATLIMIT ) ∧ distance ( position ( ag ) , l ) < distance ( position ( ag ) , position ′ ( ag ))) ⇒ ∃ x : AGEN T • position ′ ∼ ( l ) = x ∧ position ( x ) = l 02 JOSEPH KEHOE Credit. Credit is defined with one resource. It is incorporated into a dualresource simulation but no extra information is given as to what changes weremade, if any. The most logical approach is to assume that spice loans are admin-istered the the exact same way as sugar . We create a separate system of loans for spice that is dealt with in the exact same manner as sugar loans. Our specificationis now split into two parts, the parts dealing with sugar , already specified, and theparts dealing with spice , which are copies of their counterparts. The amount of aresource available to be borrowed now depends on which resource we are talkingabout. amtAvail new : N × SEX × N × N → N ∀ age, resource, baseAmt : N • amtAvail new ( age, male, resource, baseAmt ) = resource div 2 ⇔ age > M ALEF ERT ILIT Y EN DamtAvail new ( age, male, resource, baseAmt ) = resource − baseAmt ⇔ ( age ≤ M ALEF ERT ILIT Y EN D ∧ isF ertile ( age, male ) ∧ resource > baseAmt ) amtAvail new ( age, male, resource, baseAmt ) = 0 ⇔ ( age ≤ M ALEF ERT ILIT Y EN D ∧¬ ( isF ertile ( age, male ) ∨ resource > baseAmt )) amtAvail new ( age, f emale, resource, baseAmt ) = resource div 2 ⇔ age > F EM ALEF ERT ILIT Y EN DamtAvail new ( age, f emale, resource, baseAmt ) = resource − baseAmt ⇔ ( age ≤ F EM ALEF ERT ILIT Y EN D ∧ isF ertile ( age, f emale ) ∧ resource > baseAmt ) amtAvail new ( age, f emale, resource, baseAmt ) = 0 ⇔ ( age ≤ F EM ALEF ERT ILIT Y EN D ∧ ¬ ( isF ertile ( age, f emale ) ∨ resource > baseAmt )) HE SPECIFICATION OF SUGARSCAPE 103 P aySugarLoans ∆ Agents Ξ Steppopulation ′ = populationsex ′ = sexposition ′ = positionvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentCulture ′ = agentCultureagentImmunity ′ = agentImmunitychildren ′ = childrendiseases ′ = diseasesmetabolism ′ = metabolisminitialSugar ′ = initialSugar initialSpice ′ = initialSpicespiceMetabolism ′ = spiceMetabolismspiceLoanBook ′ = spiceLoanBookagentSpice ′ = agentSpice ∃ dueLoans, newLoans : ( AGEN T ↔ ( AGEN T × ( N × N ))) • dueLoans = loanBook ⊲ (ran( loanBook ) ⊲ { a : ( N × N ) | second ( a ) = step } )( loanBook ′ , agentSugar ′ ) = payExclusiveLoans ( chooseConf lictF reeSets ( dueLoans ) , agentSugar, loanBook ) 04 JOSEPH KEHOE P aySpiceLoans ∆ Agents Ξ Steppopulation ′ = populationsex ′ = sexposition ′ = positionvision ′ = visionage ′ = agemaxAge ′ = maxAgeagentCulture ′ = agentCultureagentImmunity ′ = agentImmunitychildren ′ = childrendiseases ′ = diseasesmetabolism ′ = metabolisminitialSugar ′ = initialSugar initialSpice ′ = initialSpicespiceMetabolism ′ = spiceMetabolism loanBook ′ = loanBookagentSugar ′ = agentSugar ∃ dueLoans, newLoans : ( AGEN T ↔ ( AGEN T × ( N × N ))) • dueLoans = loanBook ⊲ (ran( spiceLoanBook ) ⊲ { a : ( N × N ) | second ( a ) = step } )( spiceLoanBook ′ , agentSpice ′ ) = payExclusiveLoans ( chooseConf lictF reeSets ( dueLoans ) , agentSpice, spiceLoanBook ) HE SPECIFICATION OF SUGARSCAPE 105 M akeLoans Sugar ∆ Agents Ξ Steppopulation ′ = population ∧ sex ′ = sexposition ′ = position ∧ vision ′ = visionage ′ = age ∧ maxAge ′ = maxAgeagentCulture ′ = agentCulture ∧ agentImmunity ′ = agentImmunitydiseases ′ = diseases ∧ children ′ = childrenmetabolism ′ = metabolisminitialSugar ′ = initialSugar initialSpice ′ = initialSpicespiceMetabolism ′ = spiceMetabolismagentSpice ′ = agentSpicespiceLoanBook ′ = spiceLoanBook ∃ newLoans : P ( AGEN T × ( AGEN T × ( N × N ))); ∀ ag, lender, borrower : AGEN T ; amt, due : N • loanBook ′ = loanBook ∪ newLoansag ∈ dom newLoans ⇒ agentSugar ′ ( ag ) = agentSugar ( ag ) − totalLoaned ( ag, newLoans ) ag ∈ dom(ran newLoans ) ⇒ agentSugar ′ ( ag ) = agentSugar ( ag ) + totalOwed ( ag, newLoans ) ag dom( newLoans ) ∪ dom(ran newLoans ) ⇒ agentSugar ′ ( ag ) = agentSugar ( ag ) willBorrow ( age ( ag ) , sex ( ag ) , agentSugar ′ ( ag ) , ran( loanBook ′ ∩ { a : AGEN T × ( AGEN T × ( N × N )) | borrower ( a ) = borrower ( loan ) } )) ⇒¬ ∃ ag AGEN T • canLend ( age ( ag , sex ( ag , agentSugar ′ ( ag ∧ adjacent ( position ( ag , position ( ag )) totalLoaned ( ag, newLoans ) ≤ amtAvail new ( age ( ag ) , sex ( ag ) , agentSugar ( ag ) , CHILDAM T ) totalOwed ( ag, newLoans ) ≤ CHILDAM T − agentSugar ( ag )( lender, ( borrower, ( amt, due ))) ∈ newLoans ⇒ ( canLend ( age ( lender ) , sex ( lender ) , agentSugar ( lender )) ∧ willBorrow ( age ( borrower ) , sex ( borrower ) , agentSugar ( borrower ) , { borrower } ⊳ (ran loanBook )) ∧ amt ≤ min ( { amtAvail new ( age ( lender ) , sex ( lender ) , agentSugar ( lender ) ,CHILDAM T ) , CHILDAM T − agentSugar ( borrower )) } ) ∧ due = step + DU RAT ION ∧ adjacent ( position ( lender ) , position ( borrower ))) 06 JOSEPH KEHOEHE SPECIFICATION OF SUGARSCAPE 107 M akeSpiceLoans Ξ SpiceLattice ∆ SpiceAgents Ξ Steppopulation ′ = population ∧ sex ′ = sexposition ′ = position ∧ vision ′ = visionage ′ = age ∧ maxAge ′ = maxAgeagentCulture ′ = agentCulture ∧ agentImmunity ′ = agentImmunitydiseases ′ = diseases ∧ children ′ = childrenmetabolism ′ = metabolismspiceM etabolism ′ = spiceM etabolismagentSugar ′ = agentSugarloanBook ′ = loanBookinitialSugar ′ = initialSugar initialSpice ′ = initialSpice ∃ newLoans : P ( AGEN T × ( AGEN T × ( N × N ))); ∀ ag, lender, borrower : AGEN T ; amt, due : N • spiceLoanBook ′ = spiceLoanBook ∪ newLoansag ∈ dom newLoans ⇒ agentSpice ′ ( ag ) = agentSpice ( ag ) − totalLoaned ( ag, newLoans ) ag ∈ dom(ran newLoans ) ⇒ agentSpice ′ ( ag ) = agentSpice ( ag ) + totalOwed ( ag, newLoans ) ag dom( newLoans ) ∪ dom(ran newLoans ) ⇒ agentSpice ′ ( ag ) = agentSpice ( ag ) willBorrow ( age ( ag ) , sex ( ag ) , agentSpice ′ ( ag ) , ran( loanBook ′ ∩ { a : AGEN T × ( AGEN T × ( N × N )) | borrower ( a ) = borrower ( loan ) } )) ⇒¬ ∃ ag AGEN T • canLend ( age ( ag , sex ( ag , agentSpice ′ ( ag ∧ adjacent ( position ( ag , position ( ag )) totalLoaned ( ag, newLoans ) ≤ amtAvail new ( age ( ag ) , sex ( ag ) , agentSpice ( ag ) , SP ICECHILDAM T ) totalOwed ( ag, newLoans ) ≤ SP ICECHILDAM T − agentSpice ( ag )( lender, ( borrower, ( amt, due ))) ∈ newLoans ⇒ ( canLend ( age ( lender ) , sex ( lender ) , agentSpice ( lender )) ∧ willBorrow ( age ( borrower ) , sex ( borrower ) , agentSpice ( borrower ) , { borrower } ⊳ (ran spiceLoanBook )) ∧ amt ≤ min ( { amtAvail new ( age ( lender ) , sex ( lender ) ,agentSpice ( lender ) , SP ICECHILDAM T ) SP ICECHILDAM T − agentSpice ( borrower )) } ) ∧ due = step + DU RAT ION ∧ adjacent ( position ( lender ) , position ( borrower ))) 08 JOSEPH KEHOE Rule Application Sequence. T ick spice [ Growback spice | SeasonalGrowback spice ][ M ovement basicSpice | ( M ovement pollutionSpice P ollutionDif f usion spice ) | Combat spice ] { Inheritance spice }{ Death spice [ Replacement spice | AgentM ating spice ] }{ Culture }{ P aySugarLoans P aySpiceLoans M akeSugarLoans M akeSpiceLoans }{ T ransmission spice ImmuneResponse spice }{ T rade } Conclusions We have shown that it is possible to apply formal methods fruitfully in thearea of ABSS and produced a full formal specification of the Sugarscape family ofsimulations. It is, to the best of our knowledge, the first formal specification of theentire Sugarscape simulation family. The purpose of the specification is to providea clear, unambiguous and precise definition of Sugarscape. The specification hasidentified many ambiguities and/or missing bits of information in the original ruledefinitions. Where there is an obvious way of removing these ambiguities we havedone so. If there is more than one possible solution we have identified them andchosen the most likely one.The issues with the model definition that we have encountered can broadly begrouped into three main types: Lack of Clarity, Missing Information and Sequentialbiases. Lack of Clarity: The rules, although simply stated in the appendix, lackclarity in their definition. Only one version of each rule is presented evenwhen many variations are referred to in the text. The variations presentedcannot always be used together, for example the Movement rule defined inthe appendix is not the variant required if the pollution rule is also used.Our specification brings them all together in one place for ease of reference. Missing Information: Missing or incomplete information is the biggestcause for concern. In many cases we can work out the most likely answerbased on context but in some cases there is not one definitive correct an-swer. If there was more than one arguably correct solution we chose thesimplest. How we fill in these blanks can have a big effect on how thesimulation proceeds. These effects may be important if we are trying tocompare different implementations of Sugarscape. If we take the diseasetransmission rule, for example, questions that are unanswered include:(1) Once an agent gains immunity from a particular disease, do we re-move that particular disease from the set of diseases that the agent iscarrying, or is the agent still a carrier?(2) When we transmit a disease do we only transmit diseases that we carryand have no immunity for, or, can any disease we carry be transmitted? HE SPECIFICATION OF SUGARSCAPE 109 (3) The Mating rule omits important information about parents contribut-ing half of their resources to their offspring. This has a huge effect onhow mating works in a simulation.By replacing each ambiguous interpretation with one simple and preciseinterpretation we allow different developers to replicate their results andbenchmark them against each other. All hidden assumptions that couldserve to advantage one implementation over another are excised. Sequential Biases: Sugarscape is based on the assumption that it will beimplemented sequentially. While this may have been a good assumption atthe time it was written it is not now necessarily the case. Improvements inprocessing speed have recently been attained mainly through the introduc-tion of concurrency. Simulations are now almost always run on multicoreor even multiprocessor machines.The Z specification is free from assumptions about implementation. Itachieves this without having to specify or constrain in any way what conflictresolution or avoidance strategies are employed. This leaves developersthe freedom to try out different approaches as suits their implementationplatform.Because the specification is high level and only defines the before and afterstate of each rule it makes few assumptions as to how any rule will be imple-mented. All inherent biases towards a sequential implementation are removed.Implementers have complete freedom as to what programming model they em-ploy (Object-oriented, imperative, functional, or any concurrent approach). Anysimulations that adhere to the standard can be properly compared in terms ofperformance or patterns of behaviour. This will put on a firmer foundation anyclaims made by researchers about their implementations.6.1. Further Work. Further work remains to be done in getting agreement fromthe ABM community on the decisions made in producing this interpretation ofSugarscape. Any incorrect assumptions made in removing ambiguities need tobe identified and agreed upon. This provides a route to address the issues ofreplication of experimental results in ABSS.Sugarscape can now be used as a benchmark (or rather set of benchmarks) forABM implementers. This is particularly useful for those proposing new approachesto concurrency that promise performance improvements. Current trends, for exam-ple, include the use of Graphics Processor Units (GPUs)[Deissenberg et al., 2008,Lysenko and D’Souza, 2008, Richmond et al., 2009], containing hundreds to thou-sands of individual processors. These approaches tend not to be tested on themore complex rules in Sugarscape (such as Combat, Inheritance and Trade) asthey are not easily parallelized. By providing a precise and full set of these rulesit is now possible for researchers to properly compare how different models copewith more complex and more realistic ABMs. 10 JOSEPH KEHOE Z itself is rather verbose and can be hard to parse when reading. The lackof modularity made function definition signatures overly long. The available toolssuch as CZT [Malik and Utting, 2005] make the process of writing the specificationeasier but I have altered the specifications to remove bracketing where I thoughtit made the specification easier to read even if this was flagged as an error in thetype checker. These issues could be overcome through the use of a variant of Zsuch as Object-Z or Alloy. The issue of whether ABM modellers would be willingto use formal specifications remains unknown.There are differences between the outcomes of the synchronous and asynchro-nous approaches. Sugarscape assumes an asynchronous approach and this affectsthe style of specification that we use. We have shown in the case of combat thedifferences in a synchronous and asynchronous specification. While we regard thesynchronous specification as somewhat simpler to produce but others may disagree.We tackle the question as to which approach is the more correct elsewhere. References [Axtell and Axtell, 2000] Axtell, R. and Axtell, R. L. (2000). Why agents? on the varied moti-vations for agent computing in the social sciences. In Working Paper 17, Center on Social andEconomic Dynamics, Brookings Institution , page 17.[Berryman, 2008] Berryman, M. (2008). Review of software platforms for agent based models.Technical report, DTIC Document.[Campillo et al., 2012] Campillo, X. R., Cela, J. M., and Cardona, F. X. H. (2012). Simulat-ing archaeologists? using agent-based modelling to improve battlefield excavations. Journal ofArchaeological Science , 39(2):347 – 356.[Deissenberg et al., 2008] Deissenberg, C., van der Hoog, S., and Dawid, H. (2008). Eurace: Amassively parallel agent-based model of the european economy. Applied Mathematics and Com-putation , 204(2):541 – 552. ¡ce:title¿Special Issue on New Approaches in Dynamic Optimizationto Assessment of Economic and Environmental Systems¡/ce:title¿.[Epstein and Axtell, 1996] Epstein, J. M. and Axtell, R. (1996). Growing Artificial Societies:Social Science from the Bottom Up . The Brookings Institution, Washington, DC, USA.[Gilbert, 2004] Gilbert, N. (2004). Agent-based social simulation: dealing with complexity. TheComplex Systems Network of Excellence , 9(25):1–14.[Inchiosa and Parker, 2002] Inchiosa, M. E. and Parker, M. T. (2002). Overcoming design anddevelopment challenges in agent-based modeling using ascape. Proceedings of the National Acad-emy of Sciences , 99(suppl 3):7304–7308.[Lysenko and D’Souza, 2008] Lysenko, M. and D’Souza, R. M. (2008). A framework for megas-cale agent based model simulations on graphics processing units. Journal of Artificial Societiesand Social Simulation , 11(4):10.[Macal and North, 2009] Macal, C. and North, M. (2009). Agent-based modeling and simulation.In Simulation Conference (WSC), Proceedings of the 2009 Winter , pages 86–98.[Malik and Utting, 2005] Malik, P. and Utting, M. (2005). Czt: A framework for z tools. In ZB.Lecture , pages 65–84. Springer.[Perumalla, 2006] Perumalla, K. S. (2006). Discrete-event execution alternatives on general pur-pose graphical processing units (gpgpus). In Proceedings of the 20th Workshop on Principles ofAdvanced and Distributed Simulation , PADS ’06, pages 74–81, Washington, DC, USA. IEEEComputer Society. HE SPECIFICATION OF SUGARSCAPE 111 [Railsback et al., 2006] Railsback, S. F., Lytinen, S. L., and Jackson, S. K. (2006). Agent-basedsimulation platforms: Review and development recommendations. Simulation , 82(9):609–623.[Richmond et al., 2009] Richmond, P., Coakley, S., and Romano, D. M. (2009). A high perfor-mance agent based modelling framework on graphics card hardware with cuda. In Proceedings ofThe 8th International Conference on Autonomous Agents and Multiagent Systems - Volume 2 ,AAMAS ’09, pages 1125–1126, Richland, SC. International Foundation for Autonomous Agentsand Multiagent Systems.[Richmond et al., 2010] Richmond, P., Walker, D., Coakley, S., and Romano, D. (2010). Highperformance cellular level agent-based simulation with flame for the gpu. Briefings in Bioinfor-matics , 11(3):334–347.[Spivey, 1989] Spivey, J. M. (1989). The Z Notation: A Reference Manual . Prentice-Hall, Inc.,Upper Saddle River, NJ, USA.[Troitzsch, 2009] Troitzsch, K. G. (2009). Perspectives and challenges of agent-based simulationas a tool for economics and other social sciences. In