for i1 = 1:M for i2 = 1:M if i1 == i2 for g = 1:N iS(i1,i2) = iS(i1,i2) + eq(i1,G(g,1))+eq(i2,G(g,2)); end else