  Evolution occurs in populations of reproducing individuals. The structure of
a biological population affects which traits evolve. Understanding evolutionary
game dynamics in structured populations is difficult. Precise results have been
absent for a long time, but have recently emerged for special structures where
all individuals have the same number of neighbors. But the problem of
determining which trait is favored by selection in the natural case where the
number of neighbors can vary, has remained open. For arbitrary selection
intensity, the problem is in a computational complexity class which suggests
there is no efficient algorithm. Whether there exists a simple solution for
weak selection was unanswered. Here we provide, surprisingly, a general formula
for weak selection that applies to any graph or social network. Our method uses
coalescent theory and relies on calculating the meeting times of random walks.
We can now evaluate large numbers of diverse and heterogeneous population
structures for their propensity to favor cooperation. We can also study how
small changes in population structure---graph surgery---affect evolutionary
outcomes. We find that cooperation flourishes most in societies that are based
on strong pairwise ties.
