xcsp3team / pycsp3

A Python Library for modeling combinatorial constrained problems
https://www.pycsp.org
MIT License
60 stars 9 forks source link

Improve efficiency of parse_tuples (e.g. for huge Table constraints) #46

Closed tias closed 3 months ago

tias commented 3 months ago

Hi,

We're seeing some parser inefficiencies while preparing for the xcsp3 competitition with a CPMpy bridge.

E.g. there are some instances with odd use of Table constraints that have very few table constraints but with huge (constant) tables, e.g. the very first MiniCOP file: MiniCOP/AircraftLanding-table-airland01_mc22.xml

The parser takes 25 seconds, ortools' type checker takes another 12 and the solver only 9 seconds, so more time in the parser then anything else...

Looking at the parser code, I see a number of generic optimisations that can probably bedone to the parser throughout:

with those changes (e.g. everything above 'else') parsing now takes 19 seconds

to get it more faster, we have to use some external optimized implementation; e.g. if we convert the string to a csv formatted string, we can use numpy's loadtxt as well as its efficient tolist(). This parses that file in 10 seconds on my computer.

Since we intend to use the parser in the competition, I hope you can agree it is worth optimising some of its bottlenecks?