Endogenous Formation of Links Between Players and of Coalitions: An Application of the Shapley Value