Formation of networks and coalitions