A variational principle and its application