Optimizing incentives for systems with heterogeneous agents