Variational approach to the diffusion on inhomogeneous lattices