Hi all,
The attached implementation of the magic square problem was tested on multiple machines and the performance differences are huge. We are speaking of differences of 100x or more on machines that would have a comparable performance on other algorithms or with other solvers. We tried different seeds to make sure we aren't comparing edge cases, but on each machine, the performance is somewhat stable across different seeds. Some examples:
MacBook Pro, M1 CPU: 3 seconds
MacBook Pro, i7 CPU: 13 seconds
26 Core Xeon CPU @ 2.6 GHZ, Windows: 100 seconds
i5 CPU, 4 Cores with Hyperthreading, Linux: 1600 seconds
Different versions of OR-Tools were compared, which didn't seem to explain the difference. In fact, an older version (7.7) performed considerably better on the Windows environment than the newest version (9.5.2234).
Is CpSolver performing differently on different operating systems? Is it possibly invoking other solvers that are installed on the machine (Cplex, Gurobi), without me noticing and could this explain the performance difference?
I also noticed that on the Mac M1 machine "lb_tree_search" was used, but it wasn't used on any of the other installations. When I tried enforcing it on the other systems (solver.parameters.subsolvers.append("lb_tree_search")), it wouldn't change anything.
Another very strange thing happened when for the following equation the variables are added in a different order:
Before:
model.AddAllDifferent([x[i][j] for j in range(n) for i in range(n)])
After:
model.AddAllDifferent([x[i][j] for
i in range(n) for
j in range(n)])
All of a sudden the problem solves within seconds on the two "slow" machines.
I have seen with some commercial MIP solvers that the order in which variables and constraints are added can have a significant impact, but I have never seen such a minor change cause a speedup of 100x. Is there anything that can be done to improve the robustness of CpSolver and make it depend less on the order in which constraints/ variables are added?