Simulation of large deviation functions using population dynamics