Optimization, Algorithms, Python, Linear Programming, Operations Research.
Decrease each odd cell in the loop by θ and increase each even cell in the loop by θ. We already knew the position of the entering variable and can find the only possible loop. At the start, we move up from the entering variable(here we choose direction randomly) then we go right to the last basic