Live data from Hacker News

Constraint Solving with MiniZinc

hillelwayne.com

31–39 of 39 posts

Re: Constraint Solving with MiniZinc

#31
I highly recommend clicking through to the second post in the series. It discusses optimizing the models -- an area where I've had some success and a lot of failure. There are some really complicated tradeoffs to be managed, and it can be incredibly hard to measure whether you've made a genuine optimization or whether you've accidentally tipped the solver into a happy path for one particular instance of the problem you're trying to solve. Some solvers use PRNGs, and you have to be careful to try enough seeds to get a clear picture of the solver's performance. This can be challenging when the time to solution is exponentially distributed with a mean of several hours. The most important thing OP does, in my opinion, is to solve a smaller (but not otherwise simpler) version of the problem. This is crucial if you're going to find a tractable representation -- or rather, if you're going to eliminate completely bogus representations of the problem.

Re: Constraint Solving with MiniZinc

#32

In similar vein to others asking "how does this compare with ..."; I'm reading a book on Prolog at the moment and would be interested if anyone has experience in both MiniZinc and Prolog and can compare them for constraint solving ?

I'm not familiar with MiniZinc and I've studied but not used Prolog; however I have worked on a library which combined a linear constraint solver with a Prolog-like DFS (depth first search) logic implementation.

The most succinct difference is (usually) a constraint solver is going to find a solution (or the best solution) while a DFS logic will attempt to enumerate all solutions.

For example, consider a geometric problem of placing a point on the plane according to constraints (such as left of line AB, above line CD, etc.) Assuming a solution exists, there might be a whole region of solutions (for example three lines might describe a triangle where any point inside the triangle is a solution).

A linear constraint solver is going to give you an answer of an arbitrary point in the triangle. It is not going to give you a stream of results "1.00,5.00; 1.01,5.02; 1.02,5.04; etc." If you want that you need to perturb some of the inputs to the solver to change the output. In other words there is no built-in combinatoric enumeration order.

In contrast, a depth first solver would output exactly that, because that's how it also views the problem internally - by enumerating options. It may be sophisticated in ruling out scanning parts of the space which can't be in the solution, but it can't avoid enumerating partial solutions which are part of a full solution because that's how the algorithm works. It would be the same as an implementation leaving arbitrary rows out of a table join in SQL - the algorithm depends, for correctness and completeness, on that not being done.

(Note again the distinction between leaving out partial solutions that are part of a full solution versus leaving out searching entire regions which can be ruled out of ever being a solution. So I'm not arguing that it has to brute force solutions I'm making the more nuanced argument that the "row count" is significant in data flow within a DFS logic engine in a way that is not even a concept within a linear constraint solver's data flow. Or to put it another way, within a linear constraint solver there's only ever "one row" but it is kind of fuzzy what the values of the columns are.)

However unlike a strictly linear constraint solver minizinc also supports either-or constraints so I don't know how much that changes the above. I would be interested to find out if MiniZinc tracks the combinatorics of multiple either-or constraints in the way that a Datalog or SQL would - I suspect it instead treats them all as interchangeable and indistinguishable rather than enumerable.

Another difference between constraint solvers and DFS logic is generally you can pick an arbitrary variable in a constraint solver and change it's value an recalculate the model. In a DFS logic you generally cannot do that; at most you could (at the implementation level not the user level) unbind and rebind the most recently bound variable, or unwind the stack and recalculate from an earlier point.

Re: Constraint Solving with MiniZinc

#33

Earlier quoted context omitted.

If you don't mind sharing, how do you use these tools?

I’ve used it for smaller problems ranging from toys and puzzles to small scale optimization and scheduling problems. In the latter, my biggest use was to prototype how I’d solve a problem for my sister in her job (scheduling facilities maintenance in a way that didn’t interfere with planned experiments and tests, what maintenance work could be done and when to minimize conflicts with customer schedules). It worked as…

Thanks for your reply! I asked because a couple years ago I started, but quickly quit, a Coursera optimization course.

Re: Constraint Solving with MiniZinc

#35

Earlier quoted context omitted.

If you don't mind sharing, how do you use these tools?

I’ve used it for smaller problems ranging from toys and puzzles to small scale optimization and scheduling problems. In the latter, my biggest use was to prototype how I’d solve a problem for my sister in her job (scheduling facilities maintenance in a way that didn’t interfere with planned experiments and tests, what maintenance work could be done and when to minimize conflicts with customer schedules). It worked as…

MiniZinc should've let you farm out your problem to CBC if it could be made into an LP or MIP problem. CBC isn't as good as CPLEX or GUROBI, but is great free software that can run massive scale models.

Re: Constraint Solving with MiniZinc

#36

Earlier quoted context omitted.

I’ve used it for smaller problems ranging from toys and puzzles to small scale optimization and scheduling problems. In the latter, my biggest use was to prototype how I’d solve a problem for my sister in her job (scheduling facilities maintenance in a way that didn’t interfere with planned experiments and tests, what maintenance work could be done and when to minimize conflicts with customer schedules). It worked as…

MiniZinc should've let you farm out your problem to CBC if it could be made into an LP or MIP problem. CBC isn't as good as CPLEX or GUROBI, but is great free software that can run massive scale models.

I just never explored it past the point of trying out the ideas on my laptop. I knew it could be done (and should've mentioned that in my prior post), but had no immediate need to. Their scheduling solutions were effective, though suboptimal (at my sister's job). Additionally, as I spoke with her more I found out there were a lot of factors I didn't know about (and some I couldn't be told about for various reasons). I love my sister, and it was a good learning experience, but I can only work pro bono for so long. She had no support from her leadership to explore this approach further so that was that.

Re: Constraint Solving with MiniZinc

#37
post #22

Earlier quoted context omitted.

I believe you're trying to make a point about something, but all I can see are (rethorical?) questions.

Maybe saying some of that can't be formulated as LP/MIP?

All of these can be formulated by MIPS, so I didn't understand the point either.

Re: Constraint Solving with MiniZinc

#38

In similar vein to others asking "how does this compare with ..."; I'm reading a book on Prolog at the moment and would be interested if anyone has experience in both MiniZinc and Prolog and can compare them for constraint solving ?

For depth and breadth, I don't think Håkan Kjellerstrand can be beat. (hakank.org) The downside is, you have to do a lot of reading to figure out what's going on. The upshot is, it's all in one place. I don't know that there's any great introductory material that will give you a brief comparison between systems -- it may be that solving constraint satisfaction problems is just really hard, and there's no summary that…

(Thanks for your kind words.)

http://hakank.org/common_cp_models/ is a page which collects models that solve the same problem in different CP systems (and mostly with the same approach). It can be used to compare similarities and differences between systems, though one have to do the comparison oneself.

A long time ago (in 2012) I did a talk on comparing features in different CP systems mostly focused how "easy" - subjectively and IMHO - it was to learn the systems: http://hakank.org/constraint_programming/sweconsnet_talk_201...

Re: Constraint Solving with MiniZinc

#39
post #26

Is this in same category as OptaPlanner? How do these two compare?

OptaPlanner (Apache license, 100% Java) is a constraint solver. MiniZinc (MPL, C++) is a modeling language for other constraint solvers. Both are used for similar use cases - Vehicle Routing Problem, employee rostering, task assignment, ....

OptaPlanner uses metaheuristics and construction heuristics, java objects as input & output (not just arrays of integers and floating point numbers), constraints that can call any java code, supports multithreaded incremental solving, etc. It currently has no Minizinc adaptor or JSR-331 (a similar initiative) adaptor. If there's more demand for that, it would be considered.

Post reply on HN