-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
18 lines (11 loc) · 897 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import numpy as np
def calc_util_and_cost(pt, shopping_utils, shopping_costs):
return np.sum(pt * shopping_utils), np.sum(pt * shopping_costs)
def calc_util_plus_penalty(total_util, total_cost, overbudget_penalty, saving_coefficient, budget):
return total_util - overbudget_penalty * (max(total_cost - budget, 0) ** 2) + ((saving_coefficient * (budget - total_cost)))
def calc_util_obj_fn(total_util, total_cost, overbudget_penalty, saving_coefficient, budget):
return total_util - overbudget_penalty * (max(total_cost - budget, 0) ** 2)
def print_results(student, best_pt, pt_cost, max_util):
print('Items bought:', [student.shopping_list[i] for i, item in enumerate(best_pt) if item > 0])
print('Quantities of each item', [item[0] for item in best_pt if item > 0])
print(f'Money spent: {pt_cost} \n"Money saved: {student.budget - pt_cost}\nUtility: {max_util}')