Randomness in CP-SAT search

653 views
Skip to first unread message

Thomas B

unread,
Oct 5, 2022, 6:01:28 AM10/5/22
to or-tools-discuss
Hello,

I have a CP model that solves to optimality. Then I rerun the model with a new constraint that the former objective function can only be == the optimum. This is how I create multiple solutions with the optimal objective value.

I noticed that I get different solutions for a CP model if I run the same model on the same PC. 
If I set the number of workers = 1 the results are always the same. But I get fewer solutions than in default mode. Is there another way to create deterministic behavior to get more solutions?

Also, I get a different solution if I run the same model on another machine. Is there a way to force the solver to search for the same solutions on different machines?

Thank you very much!

Sincerely
Thomas



Laurent Perron

unread,
Oct 5, 2022, 6:39:21 AM10/5/22
to or-tools-discuss
I need some clarifications:
  - you create a model. Solve to optimality. add a constraint obj == optimal value, then rerun ?
  - do you remove the objective, and use enumerate_all_solutions:true ?

Default parallel search is not deterministic. Single thread search should be deterministic.
Is it exactly the same model ? meaning the same underlying protobuf? Or could the order of constraints or variables depend on the architecture ? It can happen if you use hash_maps.
Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00



--
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/2bcfe0bb-c652-4c9d-9377-6a32de4c03bcn%40googlegroups.com.

Thomas B

unread,
Oct 5, 2022, 7:10:59 AM10/5/22
to or-tools-discuss
- yes, I solve to optimality, add a constraint obj == optimal value, then rerun
- I remove the objective
-  enumerate_all_solutions is = true now

Single thread search is deterministic for the same machine. So my problem with one machine is solved, tanks!

BUT
I only want to find 10 solutions, but they should always be the same no matter which machine.
The model is exactly the same, the ortools version also, but the python version is different (3.10 and 3.7), could that be an issue?

Laurent Perron

unread,
Oct 5, 2022, 7:39:59 AM10/5/22
to or-tools-discuss
The best way to make sure is to save the model in proto format on both arch, and compare the output.

saving: model.ExportToFile('model.pb.txt')

Laurent Perron | Operations Research | lpe...@google.com | (33) 1 42 68 53 00


Thomas B

unread,
Oct 5, 2022, 8:08:04 AM10/5/22
to or-tools-discuss
The models are identical on both machines.

Thomas B

unread,
Oct 5, 2022, 10:27:00 AM10/5/22
to or-tools-discuss
I checked it with model.ExportToFile('model.pb.txt')

Frederic Didier

unread,
Oct 5, 2022, 11:00:09 AM10/5/22
to or-tools...@googlegroups.com
It is probably a bug on our side then, can you send us the model.pb.txt so we can have a look?

Thomas B

unread,
Oct 6, 2022, 2:46:59 AM10/6/22
to or-tools-discuss
Yes, I attached both outputs.
model_laptop.pb.txt
model_server.pb.txt

Frederic Didier

unread,
Oct 6, 2022, 8:45:56 AM10/6/22
to or-tools...@googlegroups.com
Actually, after a bit of testing, I am not sure there is something we can do.

If you compile with different compilers on the different platforms, there is no guarantee the floating point computations will be done in the same order...
You can try to run your model with the parameters "linearization_level:0", since this disables the LP, we have almost no floating-point computation involved, and you should hopefully get the same solution.
It is not 100% guaranteed as we still use floating points for variable activities and other things.
Otherwise if your platforms are compatible, maybe you can use the same binary on both which should give the same result.

Thomas B

unread,
Oct 12, 2022, 10:12:30 AM10/12/22
to or-tools-discuss
Thank you very much for that tip.
Setting the parameter "linearization_level:0" helps.

A problem that occurred now is that some instances take very long to solve. With the parameter "linearization_level:1" they get solved really fast.

Could you tell me what the parameter does? So I may figure out how to solve this issue.

Greetings 
Thomas


Laurent Perron

unread,
Oct 12, 2022, 10:20:47 AM10/12/22
to or-tools-discuss
It uses a linear relaxation and a simplex to help. 

Reply all
Reply to author
Forward
0 new messages