A variational approach to optimal design