implemented energy_assignment function: