def modify_utilities(time, reward, rulenames, rules, model_parameters):
    """
    Update rules with newly calculated utilites for rules whose firing led to reward.
    """
    for rulename in rulenames:
        for t in rulenames[rulename]:
            utility_time = time - t
            rules[rulename]['utility'] = round(rules[rulename]['utility'] +
                model_parameters['utility_alpha'] * (reward - utility_time -
                rules[rulename]['utility']), 4)
