Pool
Pool for managing a collection of agents.
Agents may belong to multiple pools.
Constructor Summary
Public Constructor | ||
public |
|
Member Summary
Public Members | ||
public |
agents: *[] |
|
public |
agentsById: {} |
|
public |
nextCache: * |
Method Summary
Public Methods | ||
public |
distribute(field: string, good: good, aggregateArray: number[] | string) distribute an aggregate setting of buyer Values or seller Costs to a pool of sellers, by giving each agent a successive value from the array without replacement |
|
public |
calls .endPeriod for all agents in the Pool |
|
public |
finds latest period.endTime of all agent in Pool |
|
public |
initPeriod(param: Object | number) calls .initPeriod for all agents in the Pool |
|
public |
finds agent from Pool with lowest wakeTime |
|
public |
Add an agent to the Pool |
|
public |
Repeatedly wake agents in Pool, until simulation time "untilTime" is reached. |
|
public |
Repeatedly wake agents in Pool, until simulation time "untilTime" or "limitCalls" agent wake calls are reached. |
|
public |
adjusts Pool agents inventories, via agent.transfer(), in response to one or more trades |
|
public |
wake() wakes agent in Pool with lowest wakeTime |
Public Constructors
public constructor() source
Public Methods
public distribute(field: string, good: good, aggregateArray: number[] | string) source
distribute an aggregate setting of buyer Values or seller Costs to a pool of sellers, by giving each agent a successive value from the array without replacement
Throw:
when field is invalid or aggregateArray is wrong type |
public push(agent: Object) source
Add an agent to the Pool
Params:
Name | Type | Attribute | Description |
agent | Object | to add to pool. Should be instanceof Agent, including subclasses. |
public runAsPromise(untilTime: number, batch: number): Promise<Object, Error> source
Repeatedly wake agents in Pool, until simulation time "untilTime" is reached. For a synchronous equivalent, see syncRun(untilTime, limitCalls)
public syncRun(untilTime: number, limitCalls: number) source
Repeatedly wake agents in Pool, until simulation time "untilTime" or "limitCalls" agent wake calls are reached. This method runs synchronously. It returns only when finished.
public trade(tradeSpec: Object) source
adjusts Pool agents inventories, via agent.transfer(), in response to one or more trades
Params:
Name | Type | Attribute | Description |
tradeSpec | Object | Object providing specifics of trades. |
|
tradeSpec.bs | string | 'b' for buy trade, 's' for sell trade. In a buy trade, buyQ, buyId are single element arrays. In a sell trade, sellQ, sellId are single element arrays, |
|
tradeSpec.goods | string | the name of the goods, as stored in agent inventory object |
|
tradeSpec.money | string | the name of money used for payment, as stored in agent inventory object |
|
tradeSpec.prices | number[] | the price of each trade |
|
tradeSpec.buyId | number[] | the agent id of a buyer in a trade |
|
tradeSpec.buyQ | number[] | the number bought by the corresponding agent in .buyId |
|
tradeSpec.sellId | number[] | the agent id of a seller in a trade |
|
tradeSPec.sellQ | number[] | the number bought by he corresponding agent in .sellId |
Throw:
when accounting identities do not balance or trade invalid |