1

I am given a completely blank sudoku and I want that it should produce fairly different answers when executed. Currently I am choosing a random integer say( x ) and iterate over solutions till I reach x:-

i=0
for lists in pycosat.itersolve(clauses):
 i=i+1
 if(i==x):
   sol = lists

Now take sol to get the required sudoku solution. This is very inefficient. Is there a efficient(faster) way to do it?

  • In principle you can use `picosat_set_global_default_phase` to specify that newly assigned literals get a random assignment, and `picosat_set_seed` to set a unique seed each run. But I don't see either of these exposed in pycosat's interface. – GManNickG Jan 27 '22 at 15:18
  • A solver-agnostic approach might be to instead shuffle the formula, perhaps by randomly flipping the polarity of variables (so that 1 becomes -1 and -1 becomes 1 everywhere, obviously flipping your interpretation of it as well), shuffling the order of literals within clauses (effectively changing which unit clauses are seen first in conflicts), and perhaps shuffling the variables themselves (swapping 1 with -2 and -1 with 2, again swapping your interpretations). This would make even an "always assign false first" strategy appear random, I think. – GManNickG Jan 27 '22 at 15:19
  • Please provide enough code so others can better understand or reproduce the problem. – Community Feb 05 '22 at 03:57

0 Answers0