CP-SAT: performance tips for the enumeration of all solutions #4223
Unanswered
tanlin2013
asked this question in
CP-SAT questions
Replies: 1 comment
-
Look for embarrassingly parallel search. Basically select k variables, create all possible assignments, enumerate all solutions from one possible assignment in parallel. Bonus point if you only generate valid assignments. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What version of OR-Tools and what language are you using?
Version: 9.0.9048
Language: Python
Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi)
CP-SAT
What operating system (Linux, Windows, ...) and version?
macOS Sonoma 14.4.1
What did you do?
Hi there, I'm working on a sudoku-like constraint problem that requires the enumeration of all possible solutions. I wonder are there any general performance tips for this task? It might be problem-specific indeed. At least parallelism doesn't seem to be an option, then what are the other things I could have tried from the broader aspect?
The problem I consider is a 2d grid of size (Lx, Ly), the variables are defined on the edges, being either 0 or 1 (boolean), drawn as the arrows in dark gray. Additionally, periodic boundaries are assumed.
There are 2 constraints,
The overall fluxes at each vertex node (in orange), must sum up to some given integer (called charge) ranging from -2 to 2. In the example here, it is always 2-in-2-out on every node, corresponding to the charge 0. So
charge = up_edge + right_edge - down_edge - left_edge
.The sum of edges in every row or column, must equal to a given tuple of integers (W_row, W_col). In this example, it will be (0, 0) for both rows and columns. Remember the periodic boundaries.
What did you expect to see
Of course, the number of solutions grows really fast in an exponential manner. So is the time required...
(This table assumes all charges are 0, and (W_row, W_col) = (0, 0).)
Code
Below is the essential part of the implementation, or the full implementation here.
(i, j, k) is the coordinate system I use to label each edge. We can basically assign every up_edge and right_edge to the vertex on position (i, j), and k for these 2 edges.
Beta Was this translation helpful? Give feedback.
All reactions