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
|
Classes
Members
wakeTime :number
time, in JS ms since epoch, of agent wake
Type:
- number
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 |
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
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 |
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
|
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
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
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}
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}
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 |
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 |
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 |
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) |
Fires:
- event:{wake(info)} immediately