Re:Constraint Programming (2020)
by default-kramer on Sunday April 16, 2023 @11:33PM
(#35596593)
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.
[ Parent
| on HN ]
It’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.
Re:Constraint Programming (2020)
by ben-schaaf on Sunday April 16, 2023 @11:56PM
(#35596700)
From 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)
Re:Constraint Programming (2020)
by default-kramer on Monday April 17, 2023 @05:45PM
(#35607047)
Cool trick! I don't know enough Python to have thought of this myself.