How to evaluate spin exchange parameters of a magnetic material using DFT?

I think we have to calculate total energies using different FM, AFM configurations and solve a set of linear equations. How to arrive at the set of equations for any given structure?

An example from the literature: Solid State Communications 2009, 149 (15–16), 602–604.