[docs]defcalculate(self,world,agent):# The energy taken from the grid by each agentsum_taken=0.0forainworld.agents:sum_taken+=a.enacted_action.grid_consumptionsum_taken+=a.enacted_action.store_energy# Energy taken by the current agent onlytake_by_agent=agent.enacted_action.grid_consumption+agent.enacted_action.store_energy# Proportion of energy taken by current agent compared to the sumlocal_oc=1-take_by_agent/(sum_taken+10E-300)returnlocal_oc