Necessary optimality conditions for geodesics in weighted Wasserstein spaces