ConstraintSolver.jl v0.1.0
I confess that while I’m writing this it isn’t actually a package yet and I plan to publish this post to my Patrons today. One day before it will be a release (if nobody has any problem with it :D).
Edit: (7th of April) It now is an official package 🙂
You can install it with:
] add ConstraintSolver
You’re new? Welcome to OpenSourc.ES and a long journey about: How to build a constraint solver?
- Start here and in a few weeks you can read this one 😀
Haven’t posted here for quite a while as I worked on the Covid19 visualization and did some other stuff during quarantine time. Had a look back into what I promised to write about and feel more and more the urge to use a new blog to have a better structure and a search function. Hopefully there will be a first working version in the next months. I already have one version with a very limited number of posts for my Patrons and writing new posts there first and transfer them over to the old one.
Anyway I found that I wanted to talk a bit about the general structure again using Multiple Dispatch. It is a talk about multiple dispatch in Julia. I more and more enjoy that feature. Well this post is not about multiple dispatch though but you should definitely watch the talk. I think post 20 (so the next one) will be about the general structure again which includes some dispatch things.
What the hell is this post about then?
Oh okay sorry I drifted away…
There were some issues/missing features I had before I wanted to release this basic version 0.1.0.
I’ll go through them one by one here and we’ll see how long this post will be.
- All solutions
- Branch splitting strategies
- Logging
- Registering v0.1.0
All solutions
I think I haven’t written about getting all solutions yet. I mentioned it at least three times before that this will be interesting for sudoku. Checking whether every sudoku has exactly one solution is also a nice feature if you want to create a sudoku puzzle yourself.
There are several options to implement this in the backend but the frontend side is what might be more interesting to you. In the backend I simply have a vector of vectors which saves every solution and I deactivate the early breaks in the backtrack functions to actually fully search the tree.
I have two options: all_solutions
and all_optimal_solutions
which are the same for feasibility problems and for optimization problems you might be only interested in optimal solutions but for small problems it might be nice to get all feasible solutions.
For the frontend you need to implement:
function MOI.get(model::Optimizer, ::MOI.ResultCount)
return length(model.inner.solutions)
end
such that the user can query the number of solutions with: MOI.get(m, MOI.ResultCount())
when m
is the model.
Additionally to get the actual solutions one needs to change the backend of…