4 ms·
I'm guessing the library python-constraint is basically just brute-forcing all possible combinations, at least when a regular python function is used as a const
by default-kramer 3y ago
I'm guessing the library python-constraint is basically just brute-forcing all possible combinations, at least when a regular python function is used as a constraint? Barring some crazy introspection, it would have to, right? And if I'm right, I don't understand why you would use a library rather than just loop over x, y, and z the old-fashioned way.
- cjalmeida 3y agoIt’s bit smarter than that. There are a couple of tricks to make the search more informed. There are a couple introductory articles to CSP that are more in depth than TFA.
- ben-schaaf 3y agoFrom the docs it's using proper backtracking solvers. It doesn't need introspection to do this, just a python object that "records" its operations, eg: def __mul__(self, other): return Multiplication(self, other)
- default-kramer 3y agoCool trick! I don't know enough Python to have thought of this myself.
- Avshalom 3y agoAside from the solver being a little smarter. Just syntactically, it might be fine with x,y,z but brute force looping over a,b,c,d...w,x,y,z is gonna take a really really wide monitor.