Class: Agent

Agent(options)

Agent with Poisson-distributed opportunities to act, with period managment, optional inventory, unit values and costs, and end-of-period production and consumption to satisfy trades

Constructor

new Agent(options)

creates an Agent with clone of specified options and initializes with .init(). Option properties are stored directly on the created agent's this.
Parameters:
Name Type Description
options Object Agent creation options
Properties
Name Type Attributes Default Description
description string <optional>
text description of agent, optional
inventory Object <optional>
{} initial inventory, as object with good names as keys and levels as values
money string <optional>
'money' Good used as money by this agent
values Object <optional>
{} marginal value table of agent for goods that are redeemed at end-of-period, as object with goods as keys and numeric arrays as values
costs Object <optional>
{} marginal cost table of agent for goods that are produced at end-of-period, as object with goods as keys and numeric arrays as values
wakeTime number <optional>
0 initial wake-up time for agent, adjusted by this.init() to first poisson-based wake with .nextWake()
rate number <optional>
1 Poisson-arrival rate of agent wake events
nextWake function <optional>
poissonWake calculates next Agent wake-up time
Source:

Classes

Agent

Members

wakeTime :number

time, in JS ms since epoch, of agent wake
Type:
  • number
Source:

Methods

decay(initialValue, finalValue) → {number}

decay an initial value into a final value over the time provided in the current period
Parameters:
Name Type Description
initialValue number initial value, greater than 0
finalValue number final value, greater than 0
Source:
Returns:
result current value
Type
number

endPeriod()

ends current period, causing agent to undertake end-of-period tasks such as production and redemption of units
Source:
Fires:
  • {post-period} when period ends, always,event: but after first completing any production/redemption

init(newSettingsopt)

initialize an agent to new settings
Parameters:
Name Type Attributes Description
newSettings Object <optional>
see constructor
Source:

initPeriod(period)

re-initialize agent to the beginning of a new simulation period
Parameters:
Name Type Description
period number | Object A period initialization object, or a number indicating a new period using the previous period's initialization object
Properties
Name Type Attributes Default Description
number number A number, usually sequential, identifying the next period, e.g. 1,2,3,4,5,...
equalDuration boolean <optional>
false with positive period.duration, autogenerates startTime and endTime as n or n+1 times period.duration
duration number <optional>
the length of the period, used with period.equalDuration
startTime number <optional>
period begins, manual setting for initial time value for agent wakeTime
endTime number <optional>
period ends, no agent wake events will be emitted for this period after this time
init Object <optional>
initializer for other agent properties, passed to .init()
Source:
Fires:
  • event:{pre-period} when initialization to new period is complete
Example
myAgent.initPeriod({number:1, duration:1000, equalDuration: true});
myAgent.initPeriod(2);

pctPeriod() → {number}

percent of period used
Source:
Returns:
proportion of period time used as a number from 0.0, at beginning of period, to 1.0 at end of period.
Type
number

poissonWakesRemainingInPeriod() → {number}

guess at number of random Poisson wakes remaining in period
Source:
Returns:
"expected" number of remaining random Poisson wakes, calculated as (this.period.endTime-this.wakeTime)*rate
Type
number

produce()

produces units in negative inventory with configured costs, usually called automatically at end-of-period. transfer uses memo object {isProduce:1}
Source:
Fires:
  • {pre-redeem(transferAmounts)} before calling .transfer,event: can modify transferAmounts
  • {post-redeem(transferAmounts)} after calling .event:transfer

redeem()

redeems units in positive inventory with configured values, usually called automatically at end-of-period. transfer uses memo object {isRedeem:1}
Source:
Fires:
  • {pre-redeem(transferAmounts)} before calling .transfer,event: can modify transferAmounts
  • {post-redeem(transferAmounts)} after calling .event:transfer

transfer(myTransfers, memoopt)

increases or decreases agent's inventories of one or more goods and/or money
Parameters:
Name Type Attributes Description
myTransfers Object object with goods as keys and changes in inventory as number values
memo Object <optional>
optional memo passed to event listeners
Source:
Fires:
  • {pre-transfer(myTransfers, memo)} before transfer takes place,event: modifications to myTransfers will change transfer
  • {post-transfer(myTransfers,event: memo)} after transfer takes place

unitCostFunction(good, hypotheticalInventory) → {number}

agent's marginal cost of producing next unit
Parameters:
Name Type Description
good String (e.g. "X", "Y")
hypotheticalInventory Object object with goods as keys and values as numeric levels of inventory
Source:
Returns:
marginal unit cost of next unit, at given (negative) hypothetical inventory, using agent's configured costs
Type
number

unitValueFunction(good, hypotheticalInventory) → {number}

agent's marginal value for redeeming next unit
Parameters:
Name Type Description
good String (e.g. "X", "Y")
hypotheticalInventory Object object with goods as keys and values as numeric levels of inventory
Source:
Returns:
marginal unit value of next unit, at given (positive) hypothetical inventory, using agent's configured values
Type
number

wake(infoopt)

wakes agent so it can act, emitting wake, and sets next wakeTime from this.nextWake() unless period.endTime exceeded
Parameters:
Name Type Attributes Description
info Object <optional>
optional info passed to this.emit('wake', info)
Source:
Fires:
  • event:{wake(info)} immediately