Seeding CP-SAT solver

835 views
Skip to first unread message

Alberto Manzini

unread,
Oct 24, 2023, 12:45:03 PM10/24/23
to or-tools-discuss
Hi everyone, I was wondering if it is possible to set random search in CP-SAT solver more deterministic, like setting a random seed in the solver.
Thanks for help,
Alberto Manzini

Laurent Perron

unread,
Oct 24, 2023, 1:14:07 PM10/24/23
to or-tools-discuss
Ok

 interleave_search:true,share_binary_clause:false, num_workers:16

Will start a deterministic search with 16 workers. 
It is usually way slower than the non deterministic version. 

--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/ae29896b-be79-4693-bb70-cbf4075cb0dfn%40googlegroups.com.

Alberto Manzini

unread,
Oct 25, 2023, 8:54:11 AM10/25/23
to or-tools-discuss
Thanks for your reply, just another query: why set 16 as search workers? It's just to handle the fact solver will get slower to find solutions or it's somehow mandatory?

Laurent Perron

unread,
Oct 25, 2023, 9:04:27 AM10/25/23
to or-tools...@googlegroups.com
Single thread solve is already deterministic. 
I run my models with at least 16 workers. But you can set to whatever you want.
Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



Frederic Didier

unread,
Oct 25, 2023, 9:17:51 AM10/25/23
to or-tools...@googlegroups.com
When interleave_search is true, it does not matter as much.
You should just set it to your number of cores, what is important is the parameter "intearleave_batch_size".

Basically, to be deterministic, we split the solve into batch size independent chunks, wait for all of them to be solved by (num_workers), synchronize and generate the next batch.
So you usually want the batch size to be around twice the number of workers, so that you have a good utilization of your core if some chunks are fast to be completed.

For a fixed batch size, the result should be deterministic, independently of the number of workers.


Alberto Manzini

unread,
Oct 25, 2023, 9:58:17 AM10/25/23
to or-tools-discuss
Understood, thank you very much.
Message has been deleted
Message has been deleted

Alberto Manzini

unread,
Oct 25, 2023, 10:23:26 AM10/25/23
to or-tools-discuss
I've set these parameters, but I'm not getting deterministic solutions yet. Am I missing something?

solver = cp_model.CpSolver()
solver. parameters.num_search_workers = self. num_search_workers

# set parameters to have deterministic saver search
solver.parameters.interleave_search = True
solver.parameters.interleave_batch_size = self. num_search_workers * 2
solver. parameters. share_binary_clauses = False

solver.parameters.max_time_in_seconds = self.num_minutes_to_solve * 60 + 1
Il giorno mercoledì 25 ottobre 2023 alle 16:20:35 UTC+2 or-tools-discuss ha scritto:
I've set these parameters, but I'm not getting deterministic solutions yet. Am I missing something?

immagine

Frederic Didier

unread,
Oct 25, 2023, 10:45:04 AM10/25/23
to or-tools...@googlegroups.com
Make sure you have the latest version, and also that you build your model in a deterministic way (the fingerprint in the log should be the same).
Also, if you hit the time limit, then of course you might hit it sooner or later, so this part will not be deterministic.

If nothing works, can you send us the proto of your model so we can check on our side?



Reply all
Reply to author
Forward
0 new messages