One example for Google or-tools is the n-queens problem solver. It says below that the implementation can be improved by adding constraints on the violation of symmetry to the constraint resolver.
Looking around the internet, I found symmetry constraint limitations for the n-queens problem , but I can't figure out how to convert them into restrictions on the python code that implements them for life.
EDIT: it was a bad question, let it be updated ...
What have i tried?
Here is the installation from the first link above:
from ortools.constraint_solver import pywrapcp N = 8 solver = pywrapcp.Solver("n-queens")
I know that I can successfully implement simple restrictions. If I wanted the solution to always have a queen in the first column in the first row, I could implement this as follows:
solver.Add(queens[0] == 0)
The variable queens[0] represents the location of the queen in the first column, and this restriction is only satisfied when the first column has a queen in the first row. This, of course, is not what I want to do, because it is possible that the solution does not contain any corner cells.
Limitations on symmetry breaking for the n-queens problem are given below. They are pulled directly from the link in the second paragraph.

I understand how these limitations work. The idea is that you can apply this function to every cell on the n-queens board to convert the state to an equivalent state. One of these states will be the canonical representation of this state. This is used as a method to reduce future processing by eliminating duplicate ratings.
If I just realized this after I did this, I would do exactly what I described above, transform the state with every possible symmetry breaking function, by computing some kind of status hash (for example, a row of the selected row in each column) and select the one that is the lowest for each proposed solution. Skip future processing on the ones we saw before.
My problem is that I donβt know how to convert these conversions to constraints for a constraint programming solution for google or-tools.
Let's look at the simplest, d1(r[i] = j) => r[j] = i , the reflection of the main diagonal. I know that the transformation needs to be applied to all cells, and then compared with the current state in order to prevent its expansion. I donβt understand enough about python to understand which expression works here for the conversion, and I just cannot understand how to create a constraint that compares the transformation with the current state for this particular solver.
state = [queens[i].Value() for i in range(N)] symX = [state[N - (i + 1)] for i in range(N)] symY = [N - (state[i] + 1) for i in range(N)] symD1 = [state.index(i) for i in range(N)] symD2 = [N - (state.index(N-(i+1)) + 1) for i in range(N)] symR90 = [N - (state.index(i) + 1) for i in range(N)] symR180 = [N - (state[N-(i+1)] + 1) for i in range(N)] symR270 = [state.index(N-(i+1)) for i in range(N)]