Household and consumption

The Household class extends the agent by giving him utility functions and the ability to consume goods.

class abce.agents.Household[source]

Bases: object

consume(utility_function, input_goods)[source]

consumes input_goods returns utility according to the agent’s utility function.

A utility_function, has to be set before see py:meth:~abceagent.Household.create_cobb_douglas_utility_function or manually; see example.


A function that takes goods as parameters and returns a utility or returns (utility, left_over_dict). Where left_over_dict is a dictionary of all goods that are not completely consumed
input goods dictionary or list:
dictionary containing the amount of input good used consumed or a list of all goods that get completely consumed.
NotEnoughGoods: This is raised when the goods are insufficient.
The utility as a number. To log it see example.


def utility_function(car, cookies, bike):
    utility = car ** 0.5 * cookies ** 0.2 * bike ** 0.3
    cookies = 0  # cookies are consumed, while the other goods are not consumed
    return utility, locals()

def utility_function(cake, cookies, bonbons):  # all goods get completely consumed
    utility = cake ** 0.5 * cookies ** 0.2 * bonbons ** 0.3
    return utility

self.consumption_set = {'car': 1, 'cookies': 2000, 'bike':  2}
self.consume_everything = ['car', 'cookies', 'bike']
    utility = self.consume(utility_function, self.consumption_set)
except NotEnoughGoods:
    utility = self.consume(utility_function, self.consume_everything)
self.log('utility': {'u': utility})

creates a Cobb-Douglas utility function

Utility_functions are than used as an argument in consume_with_utility, predict_utility and predict_utility_and_consumption.

{‘input1’: exponent1, ‘input2’: exponent2 …}: dictionary containing good names ‘input’ and correstponding exponents
A utility_function that can be used in consume_with_utility etc.

Example: self._utility_function = self.create_cobb_douglas({‘bread’ : 10, ‘milk’ : 1}) self.produce(self.plastic_utility_function, {‘bread’ : 20, ‘milk’ : 1})