def fitness(solution, customers,
budget):
# solution = [offer_id per pelanggan], misal [2, 0, 1, 3, ...]
total_cost = sum(OFFER_COST[solution[i]] for i in range(len(customers)))
if total_cost > budget:
return -999_999 # constraint
violation
retained = sum(
customers[i]['arpu'] * ACCEPT_RATE[solution[i]][customers[i]['risk']]
for i in range(len(customers))
)
return retained # maximise retained ARPU
# OFFERS: 0=tanpa offer, 1=diskon 10%, 2=gratis 1 bulan, 3=priority support
# GA akan mencari kombinasi terbaik yang memaksimalkan retained revenue