예제 #1
0
    def linear_utility(self, amount_by_currency: CurrencyHoldings) -> float:
        """
        Compute agent's utility given her utility function params and a currency bundle.

        :param amount_by_currency: the currency holdings (dictionary) with the identifier (key) and quantity (value) for each currency
        :return: utility value
        """
        result = linear_utility(self.exchange_params_by_currency,
                                amount_by_currency)
        return result
예제 #2
0
    def linear_utility(self, amount_by_currency_id: CurrencyHoldings) -> float:
        """
        Compute agent's utility given her utility function params and a currency bundle.

        :param amount_by_currency_id: the currency holdings (dictionary) with the identifier (key) and quantity (value) for each currency
        :return: utility value
        """
        assert self.is_initialized, "Preferences params not set!"
        result = linear_utility(self.exchange_params_by_currency_id,
                                amount_by_currency_id)
        return result
예제 #3
0
def test_linear_utility():
    """Test logarithmic utlity."""
    assert (linear_utility(
        exchange_params_by_currency_id={
            "cur_1": 0.2,
            "cur_2": 0.8
        },
        balance_by_currency_id={
            "cur_1": 20,
            "cur_2": 100
        },
    ) > 0), "Utility should be positive."
예제 #4
0
    def get_score(self) -> float:
        """
        Compute the score of the current state.

        The score is computed as the sum of all the utilities for the good holdings
        with positive quantity plus the money left.
        :return: the score.
        """
        goods_score = logarithmic_utility(self.utility_params_by_good_id,
                                          self.quantities_by_good_id)
        money_score = linear_utility(self.exchange_params_by_currency_id,
                                     self.amount_by_currency_id)
        score = goods_score + money_score
        return score