by jeofken · 6y ago · 0 comments
For the delivery company example mentioned on the site, I’d imagine a database, perhaps just ‘library(persistency)’, storing the fleet of cars the company has, the delivery orders, the drivers employed, etc. The constraints would be expressed as prolog relations.
I may be implementing a system like this soon, and would like to hear war stories of doing it with a library like OptaPlanner or Prolog.
1) You need to know how to encode the constraints so they can be evaluated efficiently, not just write them.
2) A common way to achieve 1) is to encode a problem as a SAT problem and use a modern SAT solver. They are pretty sick. You can write great SAT solvers in Prolog, but there are already many good ones in many languages, so it's quite poinless unless you do it for fun or learning.
3) Compared to most statistical methods / heuristics, searches in Prolog will be slow. And in most cases statistical methods will do fine anyway, because there will be at least decent solutions to be easily found.
My conclusion is that we often confuse the problems of "proving that a plan is optimal" with "finding a good plan", which are indeed related, but use very different techniques to reach solutions.
The bigger the search space, the more we like it.
I also recommend checking out Picat, a Prolog-derived language with excellent support for constraints programming and many built-in global constraints (a very important tool for larger-scale constraint programming) [2]. As of the recently released version 3 (featured on HN [3]), Picat also supports traditional Prolog syntax. IMO Picat is still rough around the edges when it comes to error messages, modularization etc, but if nothing else it's excellent for learning and for prototyping constraint models.
[1] https://www.swi-prolog.org/man/clpfd.html [2] http://picat-lang.org/ [3] https://news.ycombinator.com/item?id=24608997
I think the biggest challenge in optimization problems is converting the constraints from object/concept space to integer/constraint space and back. Once you're done with that, it doesn't really matter which tools you use as long as they provide the mathematical operations necessary.
Then you may want to also dig into https://en.wikipedia.org/wiki/Answer_set_programming papers / solvers / systems over the past ~1.5 decades or so.
> In a more general sense, ASP includes all applications of answer sets to knowledge representation and the use of Prolog-style query evaluation for solving problems arising in these applications.
Once he had to convert a Prolog algo in 50 `if then` in C. He told me it wasn't clean but the perfs they got out of it was an order of magnitude.