Markets
The data structures provided here are a basis for agent-based market simulations. For example, they could be used in financial market models or labor market models.
Market Registry
- class sfctools.datastructs.market_registry.MarketRegistry(owner)
Bases:
object
Data structure to store remaining and fulfilled demand of an agent at a market
DEMAND:
total
fulfilled
remaining
good1
=total-fulfilled
good2
good3
SUPPLY:
total
fulfilled
remaining
good1
=total-fulfilled
good2
good3
- Parameters
owner – agent instance who owns this data structure
- reset(kind, good)
reset all entries to zero
- Parameters
kind – ‘demand’ or ‘supply’
good – name of good
- set_current_update(kind, good, q)
” update fulfillment of demand or supply
- Parameters
kind – ‘demand’ or ‘supply’
good – name of good
q – new entry value
- set_target_update(kind, good, new_value)
set up the toftal demand/supply for a certain good
- Parameters
kind – ‘demand’ or ‘supply’
good – name of good
q – new entry value
- to_string()
converts data structure to human-readable string format
- class sfctools.datastructs.market_registry.RegistryEntry
Bases:
object
A helper data structure for MarketRegistry
Market Matching
- class sfctools.bottomup.matching.MarketMatching(demand_list=None, supply_list=None)
Bases:
object
Meta class for market matching. This is a basic framework for a list of demanders and suppliers who are matched decentrally and registered centrally. This can be thought of as a graph (nodes and edges) of agents.
constructor for market matching
- Parameters
demand_list – list of demand agents or None (default, creates empty list)
supply_list – list of supply agents or None (default)
- add_demander(agent)
Add demand agent as node in the graph
- Parameters
agent – instance to add on demand side
- add_supplier(agent)
Add supply agent as node in the graph
- Parameters
agent – instance to add on demand side
- clear()
Removes all edges from the current graph.
- clear_all()
Do a complete reset (remove edges and nodes, reset to blank greenfield market.
- property demand_list
Get list of demand agents. Filters demanders who are not bankrupt
- Returns
list of agents
- get_demand_data(agent)
get all demanders + info for agent
- Parameters
agent – reference agent
- Returns
dict containing data
- get_demanders_from(agent) list
get list of agents demanding from agent
- Parameters
agent – reference agent
- Returns
list of agents
- get_suppliers_of(agent) list
get list of agents supplying to agent
- Parameters
agent – reference agent
- Returns
list of agents
- get_supply_data(agent)
get all suppliers + info for agent
- Parameters
agent – reference agent
- Returns
dict containing data
- get_value(agent_from, agent_to)
- link_agents(supply_agent, demand_agent, val)
link a connection between demand and supply with weight val
- Parameters
supply_agent – agent instance, supply
demand_agent – agent instance, demand
val – a value that is stored in the data dict for this link
- plot(fname=None, show_figure=True)
plot the current matching situation as a network graph :param fname: filename (optional) if filename is given, no plot will be shown and a png will be saved to a file. :param show_figure: default True, show the figure in a plot window
- plot_weighted(my_layout=None, arrows=False, fname=None)
plot the current matching situation as a network graph, with edge thickness matching the weights Suppliers re plotted in red, demanders in blue.
- Parameters
my_layout – networkx graph layout
arrows – show the arrows
fname – if None, plot is shown in window. Else, file is stored to fname
- abstract rematch()
rematch the supply and demand agents, i.e. update the matching map. Has to be overridden as it is abstract.
- remove_demander(agent)
remove a demander
- remove_supplier(agent)
remove a supplier
- property supply_list
Get list of supply agents. Filters suppliers who are not bankrupt
- Returns
list of agents
- unlink_agents(supply_agent, demand_agent)
unlink a connection
- Parameters
supply_agent – agent instance, supply
demand_agent – agent instance, demand