trade_utils
index
/home/gcallah/TandonDevOps/IndraABM/capital/trade_utils.py

This file contains general functions useful in trading goods.

 
Modules
       
lib.actions
copy
math
random

 
Classes
       
builtins.object
TradeState

 
class TradeState(builtins.object)
    TradeState(trader1, trader2, good1=None, amt1=0, good2=None, amt2=0, status=3)
 
A class to track the state of a trade.
 
  Methods defined here:
__init__(self, trader1, trader2, good1=None, amt1=0, good2=None, amt2=0, status=3)
Args:
    good1: the name of the good offered first
    amt1: the amount of that good offered at this point
        in negotiations
    good2: the name of the good offered in return for good1
    amt2: the amount of that good offered at this point
        in negotiations
    status: current state of this trade
__repr__(self)
Return repr(self).
__str__(self)
Return str(self).
get_good(self, which_side)
get_other(self, which_side)
get_side(self, which_side)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Functions
       
adj_add_good(agent, good, amt, comp=None)
adj_add_good_w_comp(agent, good, amt, old_amt)
adjust_dura(trader, good, val)
This function will check if durability is an attribute of
the goods. If so, utility will be adjusted by durability.
bear_util_func(qty, divisibility=None)
cat_util_func(qty, divisibility=None)
check_age(trader, good)
Adjust the amt_avaliable if the good is too decayed
check_complement(trader)
see if COMPLEMENT is an attribute in trader
check_div(trader, good)
This function will check if divisibility is an attribute of
the goods. If so, the function will return divisibility;
else, the function will return 1.
check_transportability(good, distance)
compl_lst(agent, good)
return the complimentary list of this good
endow(trader, avail_goods, equal=False, rand=False, comp=False)
This function is going to pick a good at random, and give the
trader all of it, by default. We will write partial distributions
later.
equal_dist(num_trader, to_goods, from_goods, comp=False)
each trader get equal amount of goods
to_goods = trader[GOODS], from_goods = avail_goods
exec_trade(trade_state)
gen_util_func(qty, divisibility)
get_lowest(agent, my_good, their_good, bidder=True)
This function will get the max a bidder want to give up or
the min a reciever want to accept.
get_rand_good(goods_dict, nonzero=False)
What should this do with empty dict?
get_util_func(fname)
good_all_gone(agent, g)
Check if this agent no longer has this good
goods_to_str(goods)
take a goods dict to string
incr_util(good_dict, good, amt=None, agent=None, graph=False, comp=None)
if graph=True, increase the utility according to
the weight of edge in the graph
is_compl_good(agent, good)
check if this good is a comp of other goods that the agent have
is_complement(trader, good, comp)
see if 'comp' is complement of 'good'
is_depleted(goods_dict)
See if `goods_dict` has any non-zero amount of goods in it.
negotiate(trade)
See if these two traders (held in `trade` can strike a deal.
new_good(old_amt, amt)
penguin_util_func(qty, divisibility=None)
rand_dist(to_goods, from_goods, comp=False)
Pick a random good and transfer a random amount of it to trader.
rand_goods_list(goods)
seek_a_trade(agent, comp=False, size=None)
Find closest agent and see if we can trade with them.
seek_a_trade_w_comp(agent, **kwargs)
steep_util_func(qty, divisibility=None)
test_util_func(f, max, d)
trade(agent, my_good, my_amt, counterparty, their_good, their_amt, comp=None)
trade_acceptable(trade_state, which_side)
Is the trade acceptable to `which_side`?
trade_debug(agent1, agent2, good1, good2, amt1, amt2, gain, loss)
trade_state_to_str(state)
convert integer value of ans to string
transfer(to_goods, from_goods, good_nm, amt=None, comp=False)
Transfer goods between two goods dicts.
Use `amt` if it is not None.
utility_delta(agent, good, change)
We are going to determine the utility of goods gained
(amt is positive) or lost (amt is negative).
`change` will be fractional if good divisibility < 1

 
Data
        ACCEPT = 1
AMT_AVAIL = 'amt_available'
COMPLEMENTS = 'complementaries'
DEBUG = <lib.utils.Debug object>
DEF_MAX_UTIL = 20
DIGITS_TO_RIGHT = 2
DIM_UTIL_BASE = 1.1
ESSENTIALLY_ZERO = 0.0001
GEN_UTIL_FUNC = 'gen_util_func'
GOODS = 'goods'
INADEQ = 0
INIT1 = 3
INIT2 = 2
NO_TRADER = -2
OFFER_FROM_1 = 5
OFFER_FROM_2 = 4
PENDING = 6
REJECT = -1
STEEP_GRADIENT = 20
TEST_GOODS_DICT = {'honey': {'amt_available': 20}, 'molasses': {'amt_available': 30}, 'stevia': {'amt_available': 0}, 'sugar': {'amt_available': 10}}
TRADER1 = 0
TRADER2 = 1
TRADE_STATUS = 0
TRANSPORTABILITY = 'transportability'
UTIL_FUNC = 'util_func'
max_util = 20
trade_state_dict = {-2: 'No Trader', -1: 'Reject', 0: 'Inadequate', 1: 'Accept', 2: 'Init 2', 3: 'Init 1', 4: 'Offer 2', 5: 'Offer 1'}
util_funcs = {'bear_util_func': <function bear_util_func>, 'cat_util_func': <function cat_util_func>, 'gen_util_func': <function gen_util_func>, 'penguin_util_func': <function penguin_util_func>, 'steep_util_func': <function steep_util_func>}