Optimal harvesting of structured populations