  We study the complexity of classical constraint satisfaction problems on a 2D
grid. Specifically, we consider the complexity of function versions of such
problems, with the additional restriction that the constraints are
translationally invariant, namely, the variables are located at the vertices of
a 2D grid and the constraint between every pair of adjacent variables is the
same in each dimension. The only input to the problem is thus the size of the
grid. This problem is equivalent to one of the most interesting problems in
classical physics, namely, computing the lowest energy of a classical system of
particles on the grid. We provide a tight characterization of the complexity of
this problem, and show that it is complete for the class $FP^{NEXP}$. Gottesman
and Irani (FOCS 2009) also studied classical translationally-invariant
constraint satisfaction problems; they show that the problem of deciding
whether the cost of the optimal solution is below a given threshold is
NEXP-complete. Our result is thus a strengthening of their result from the
decision version to the function version of the problem. Our result can also be
viewed as a generalization to the translationally invariant setting, of
Krentel's famous result from 1988, showing that the function version of SAT is
complete for the class $FP^{NP}$. An essential ingredient in the proof is a
study of the complexity of a gapped variant of the problem. We show that it is
NEXP-hard to approximate the cost of the optimal assignment to within an
additive error of $\Omega(N^{1/4})$, for an $N \times N$ grid. To the best of
our knowledge, no gapped result is known for CSPs on the grid, even in the
non-translationally invariant case. As a byproduct of our results, we also show
that a decision version of the optimization problem which asks whether the cost
of the optimal assignment is odd or even is also complete for $P^{NEXP}$.
