Agent
Extends:
Direct Subclass:
Indirect Subclass:
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 Summary
Public Constructor | ||
public |
constructor(options: Object) creates an Agent with clone of specified options and initializes with .init(). |
Member Summary
Public Members | ||
public |
period: * |
|
public |
time, in JS ms since epoch, of agent wake |
Method Summary
Public Methods | ||
public |
ends current period, causing agent to undertake end-of-period tasks such as production and redemption of units |
|
public |
initialize an agent to new settings |
|
public |
initPeriod(period: number | Object) re-initialize agent to the beginning of a new simulation period |
|
public |
percent of period used |
|
public |
guess at number of random Poisson wakes remaining in period |
|
public |
produce() produces units in negative inventory with configured costs, usually called automatically at end-of-period. |
|
public |
redeem() redeems units in positive inventory with configured values, usually called automatically at end-of-period. |
|
public |
increases or decreases agent's inventories of one or more goods and/or money |
|
public |
unitCostFunction(good: String, hypotheticalInventory: Object): number agent's marginal cost of producing next unit |
|
public |
unitValueFunction(good: String, hypotheticalInventory: Object): number agent's marginal value for redeeming next unit |
|
public |
wakes agent so it can act, emitting wake, and sets next wakeTime from this.nextWake() unless period.endTime exceeded |
Public Constructors
public constructor(options: Object) source
creates an Agent with clone of specified options and initializes with .init(). Option properties are stored directly on the created agent's this.
Params:
Name | Type | Attribute | Description |
options | Object | Agent creation options |
|
options.description | string |
|
text description of agent, optional |
options.inventory | Object |
|
initial inventory, as object with good names as keys and levels as values |
options.money | string |
|
Good used as money by this agent |
options.values | Object |
|
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 |
options.costs | Object |
|
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 |
options.wakeTime | number |
|
initial wake-up time for agent, adjusted by this.init() to first poisson-based wake with .nextWake() |
options.rate | number |
|
Poisson-arrival rate of agent wake events |
options.nextWake | function(): number |
|
calculates next Agent wake-up time |
Public Members
public period: * source
Public Methods
public endPeriod() source
ends current period, causing agent to undertake end-of-period tasks such as production and redemption of units
Emit:
post-period |
when period ends, always, but after first completing any production/redemption |
public init(newSettings: Object) source
initialize an agent to new settings
Params:
Name | Type | Attribute | Description |
newSettings | Object |
|
see constructor |
public initPeriod(period: number | Object) source
re-initialize agent to the beginning of a new simulation period
Params:
Name | Type | Attribute | Description |
period | number | Object | A period initialization object, or a number indicating a new period using the previous period's initialization object |
|
period.number | number | A number, usually sequential, identifying the next period, e.g. 1,2,3,4,5,... |
|
period.equalDuration | boolean |
|
with positive period.duration, autogenerates startTime and endTime as n or n+1 times period.duration |
period.duration | number |
|
the length of the period, used with period.equalDuration |
period.startTime | number |
|
period begins, manual setting for initial time value for agent wakeTime |
period.endTime | number |
|
period ends, no agent wake events will be emitted for this period after this time |
period.init | Object |
|
initializer for other agent properties, passed to .init() |
Emit:
pre-period |
when initialization to new period is complete |
Example:
myAgent.initPeriod({number:1, duration:1000, equalDuration: true});
myAgent.initPeriod(2);
public pctPeriod(): number source
percent of period used
Return:
number | proportion of period time used as a number from 0.0, at beginning of period, to 1.0 at end of period. |
public poissonWakesRemainingInPeriod(): number source
guess at number of random Poisson wakes remaining in period
Return:
number | "expected" number of remaining random Poisson wakes, calculated as (this.period.endTime-this.wakeTime)*rate |
public produce() source
produces units in negative inventory with configured costs, usually called automatically at end-of-period. transfer uses memo object {isProduce:1}
Emit:
pre-redeem(transferAmounts) |
before calling .transfer, can modify transferAmounts |
post-redeem(transferAmounts) |
after calling .transfer |
public redeem() source
redeems units in positive inventory with configured values, usually called automatically at end-of-period. transfer uses memo object {isRedeem:1}
Emit:
pre-redeem(transferAmounts) |
before calling .transfer, can modify transferAmounts |
post-redeem(transferAmounts) |
after calling .transfer |
public transfer(myTransfers: Object, memo: Object) source
increases or decreases agent's inventories of one or more goods and/or money
Emit:
pre-transfer(myTransfers, memo) |
before transfer takes place, modifications to myTransfers will change transfer |
post-transfer(myTransfers, memo) |
after transfer takes place |
public unitCostFunction(good: String, hypotheticalInventory: Object): number source
agent's marginal cost of producing next unit
Return:
number | marginal unit cost of next unit, at given (negative) hypothetical inventory, using agent's configured costs |