-
Notifications
You must be signed in to change notification settings - Fork 16
EconAgent breakdown by externally accessible data and functions
Si Li edited this page Feb 27, 2025
·
1 revision
Here's a breakdown of the externally called functions (public or protected internal) within EconAgent.cs, along with brief descriptions:
- uid (int): A unique identifier for the agent. (read-only)
- Cash (float): The amount of cash the agent currently possesses. (read-only, use AddToCash to modify)
- CashString (string): A formatted string representation of the agent's cash (e.g., "00.00"). (read-only)
- Alive (bool): Indicates whether the agent is still active in the simulation. (read-only)
- DaysStarving (int): How many consecutive rounds the agent has been starving. (read-only)
- Profit (float): The agent's profit for the current round. (read-only)
- TaxableProfit (float): The agent's profit subject to taxes. (read-only)
- inventory (Dictionary<string, InventoryItem>): The agent's inventory of goods. (read/write access to items inside dictionary)
- Profession (string): The agent's current profession (read-only).
- outputName(string): The good produced by this agent.
- ResetCash(): Sets the agent's cash to 0.
- Stats(String header) (String): Gathers and returns a string of the agent's current stats for logging purposes.
- PayWealthTax(float amountExempt, float taxRate) (float): Calculates and deducts a wealth tax from the agent's cash. Returns the amount of tax paid.
- Pay(float amount): Deducts a specified amount from the agent's cash.
- Init(SimulationConfig cfg, AuctionStats at, string b, float _initStock, float maxstock, float cash=-1f): Initializes the agent with configuration, auction information, its profession, initial stock, max stock, and initial cash (if given).
- Respawn(bool bankrupted, string buildable, Government gov = null): Respawns the agent after bankrupcy, or role change.
- PrintInventory(string label): prints out inventory to console.
- TaxProfit(float taxRate) (float): Calculates and deducts a profit tax.
- IsBankrupt() (bool): Checks if the agent is currently bankrupt.
- ConsumeGoods(): (Virtual) Allows for custom logic for the agent consuming goods.
- Tick(Government gov, ref bool changedProfession, ref bool bankrupted, ref bool starving) (float): Advances the agent's state for a single round. Includes things like consuming food, checking bankruptcy, and triggering profession changes. Returns the amount of taxes consumed.
- Food() (float): returns how much food is currently in the agents inventory.
- EvaluateHappiness() (float): Returns a happiness score for the agent.
- ChangeProfession(Government gov, bool bankrupted = true): Allows the agent to switch professions.
- AddToCash(float quant): Adds a specified amount to the agent's cash.
- ClearRoundStats(): Clears any statistics accumulated during that round.
- Buy(string commodity, float quantity, float price) (float): Handles the agent purchasing a commodity. Returns the amount of commodity bought.
- Sell(string commodity, float quantity, float price): Handles the agent selling a commodity.
- UpdateSellerPriceBelief(in Offer trade, in ResourceController rsc): updates the agents price belief after a sale.
- UpdateBuyerPriceBelief(in Offer trade, in ResourceController rsc): updates the agents price belief after a purchase.
- Decide(): Triggers the agent's decision-making process, including production and consumption.
- CreateBids(AuctionBook book) (Offers): Creates offers (bids) to buy commodities.
- Produce() (float): Triggers the agent to produce goods. Returns amount produced.
- CalcMinProduction() (float): Calculates the agents min production.
- CreateAsks() (Offers): Creates offers (asks) to sell commodities.
- Simulation Control: Methods like Init, Tick, Decide, Produce, ChangeProfession, and IsBankrupt are essential for controlling the agent's lifecycle and behavior within the simulation.
- Market Interaction: CreateBids, CreateAsks, Buy, Sell, UpdateSellerPriceBelief, UpdateBuyerPriceBelief are the core functions that allow agents to interact with the simulated market.
- Data Reporting: Stats and the various properties (Cash, Profit, inventory, etc.) are used to query the agent's internal state and monitor their performance.
- Financial Operations: PayWealthTax, Pay, and AddToCash are used to manage the agent's finances.
- Happiness: EvaluateHappiness returns the agent's happiness score.
- Inventory: Inventory contains externally accessable methods to add or remove goods.
- Respawns Respawn will reinit the agent if they bankrupt.
**How these are used externally. ** These functions are designed to be called by the AuctionHouse class, and by the Government to simulate the economy, monitor agents, and make policy decisions. The AuctionHouse is the central controller that orchestrates the entire simulation.
The EconAgent class presents a well-defined public interface that allows external systems (primarily the AuctionHouse and Government) to:
- Manage the agent's lifecycle.
- Interact with the market on the agent's behalf.
- Monitor and report on the agent's state.
- Tax or pay the agent.
- Control when an agent changes profession.