Live data from Hacker News

MiniZinc

minizinc.org

31–40 of 76 posts

Re: MiniZinc

#31

I once tried to use MiniZinc as a back-end for a school timetabling app I was working on, and came away with the impression that the OptaPlanner Java API would be a lot easier to use. (Although unlike solvers, OptaPlanner uses heuristic algorithms -- simulated annealing, etc.) Maybe it's just that formally expressing a set of constraints doesn't come naturally to me. I'm sure with a lot of practice, writing MiniZinc…

I've used OptaPlanner in production, it was pretty straightforward and coped perfectly well with the few-hundred-variable problems we needed it for (we ran it with a timeout, and its solutions were good). If you're comfortable programming Java, it should be easy enough (note that it relies on mutating objects in-place; which took some getting used to since I was using it from Scala!)

I've used MiniZinc too (in a different project), where I wanted some optimal results to compare against some heuristic algorithms I was developing. MiniZinc requires more careful thought when it comes to encoding/representing the problem (i.e. sets of integers, rather than familiar Java objects), but it's not too difficult. Since it's optimal it can take an age to run; I could only scale my problem up to N=11 before it was taking more than 24 hours (that was enough for my comparisons though)

Re: MiniZinc

#32

I wrote a thesis on using constraint satisfaction with minizinc to solve the genome edit distance problem: https://github.com/jpnelson/genome-edit/blob/master/thesis.p... My takeaway: modeling problems in minizinc correctly is exceptionally difficult for non-trivial problems. You can model it correctly, but you'll likely still need to add additional "constraints" that improve the performance of the solver to the degr…

I used minizinc to try and generate levels for my puzzle game by encoding the rules.

It worked quite well for the more trivial rules, but as I added more complex rules, it wouldn't solve within reasonable time.

Unfortunately I didn't really figure out how to direct the solver in way that would speed up things.

Re: MiniZinc

#33
post #4

What exactly is "constraint modeling" and what is it used for?

Dependency management is a common example; e.g. we want A; A depends on B and C; B depends on D or E; C conflicts with D; etc. These are all constraints, and we can ask a system like MiniZinc to find a set of packages which don't conflict (in that example {A, B, C, E} satisfy the constraints).

I don't think MiniZinc itself is used by any package-management tools, although some use competing tools/libraries. Personally I've used MiniZinc for a related problem: finding a subset of dependencies (of a given size, say 10), which satisfy the most outputs.

Edit: Another constraint modelling problem I've tackled (although I didn't use MiniZinc to solve it) is seating allocation on public transport: if the scheduled vehicle is unavailable, and the replacement has a different seating layout, how can we best assign the reserved seats (taking into account ticket class, seat direction, window/aisle, amenities, etc.)?

Re: MiniZinc

#34
post #4

What exactly is "constraint modeling" and what is it used for?

Examples from the software domain: Dependency resolution in package managers (packages with version requirements) may use constraint solving. Or type checking may be implemented using constraint solving. Though often if the application is well understood enough, it may jump over generic modelling language like MiniZinc and generate instructions for a boolean satisfaction solver directly.

Re: MiniZinc

#35

Forgive my ignorance, but what kinds of problems are constraint solving good for? Can I specify a list of statements, constraints, prioritisations and the have it solve it for the best possible solution? Is that it? If so, I need it to figure out my optimal workout schedule given a handful of constraints (a problem I’ve been thinking about since I started university twenty years ago :) )

At work, a large consulting company, we use constraint programming (actually, mostly mixed integer prog and meta heuristics) to solve problems in logistics scheduling, route optimization, staff assignment, production planning, marketing (pricing, store assortment) finance (portfolio, capital budgeting) and others.

Large companies (think any of the Global 2000) benefit from a couple % improvement on their operations that lead to many $M in savings.

Re: MiniZinc

#37
post #22

You forgot to tell us what it is.

The first two paragraphs of the home page say what it is: MiniZinc is a free and open-source constraint modeling language. You can use MiniZinc to model constraint satisfaction and optimization problems in a high-level, solver-independent way, taking advantage of a large library of pre-defined constraints. Your model is then compiled into FlatZinc, a solver input language that is understood by a wide range of solvers…

[flagged]

Re: MiniZinc

#38
post #7

As a not professional programmer, but mathematically inclined I can say I found modelling in MiniZinc crazily hard. I tried the Coursera class, put in the hours and failed. It took me back to some classes where everything I tried failed and the proper result felt so near what I was trying that it was hard to digest a better strategy the next time. It did give me a new feeling for complexity and model space reduction.…

Can LLM help in this task?

Re: MiniZinc

#40
My goodness, a HN topic I can speak on with some level of expertise!

I developed and deployed a rail yard scheduling application based on MiniZinc which is being used daily in production at several sites by one of the largest rail network operators in Australia.

Like others here I had started out with the free coursera courses a couple of years prior and was really taken by the declarative nature of the language. When approached about the yard scheduling problem I thought it seemed like a good fit and was able to quickly generate a proof of concept. I spent the next 2 years iterating on it until it was able to handle all of the real world (and real-time) constraints.

The topology: - A yard has many tracks (~40 in our largest case) - A track has many track circuits (this reflects the underyling control system) - ~ 250 track circuits - A circuit can only be occupied by 1 train at a time - A train occupies many track circuits - This yard was a staging point for 2 unloading locations - Each unloading location had many loaders

The dynamics: - Trains entered the yard primarily for the purpose of proceeding to the unload and unloading - Most trains required 'provisioning' on certain tracks before or after unloading - Some trains required' shunting', making or breaking a consist into separate peices for repair or reconfiguration - Some trains required manual examination, meaning adjacent tracks must be vacant while the inspection took place - There are many routes trains can take (we pre-calculated these) - There were multiple train operators using the yard - Each operator had soft or hard constraints on where and how they would like their trains to operate - The primary objective function was meeting the agreed unloading time at the port and completing all maintenance and inspections - Secondary objectives were queuing times, route preferences

The implementation: - ~50k python codebase - Data read from 4 internal systems for maintenance requirements, schedules, etc - Telemetry from the train control system used to determine train location within the yard - Data was stored in python using attrs, cattrs and roundtripped to JSON - MiniZinc models were compiled on demand, this was a massive help in performance and flexibility - Frontend was a Streamlit app which displayed schedules using Altair/Vega-lite - The core 'solve' method was used in a variety of ways, you could reschedule a single trains, or many trains at once (the ideal), or a heuristic where trains were scheduled in dynamic batches (required for longer +24hr runs) - The frontend exposed a '1 click schedulers' which would bring in all the data and produce a feasible schedule very quickly (Reflection: This was an extremely challenging project for a lot of reasons, mainly because I was a 1 man team and trying to learn on a deadline, also this was during covid and I had nothing else to do so it became quite all consuming. I have since thought that if I could do it all again would the approach be different?

Of all the parts of the tech stack I enjoyed MiniZinc the most and would happily use it again. Modelling with constraints is not easy but there is a rock solid gaurantee that comes with it that pleases me greatly. As other people have said there is a lack of intermediate or advanced level "real world" tutorials which I completely agree with and am working on in my spare time.

I would say that things got a lot easier once I stopped trying to represent the entire model ahead of time in one minizinc file, and instead compiled models as required from the python side based on the data I was dealing with.

Python was great for the POC stage and horrendous once it got to a certain size. Alas a rewrite was never in the cards. We dealt with it by using type hints everywhere

Streamlit is absolutely not fit for purpose for anything beyond hello-world, at least at the time I was using it. Unfortunately I had no experience in frontends at all and just needed a way to expose the model to end users and display results so we made it work.

Altair/Vega-lite is a fantastic charting library which I would readily use again. Being able to produce standalone gantt-style train schedules complete with interaction was a major win for both end users and myself for debugging.

I have to duck off but love talking about this stuff, you can reach me at "justin dot rawlings at protonmail dot com" or jmjrawlings on github.

Post reply on HN