Better HN
topnewbestaskshowjobs
Log inSign up

hakank

60 karma · joined Jan 20, 2018 (8y ago) · 24 submissions

http://hakank.org/ GitHub: https://github.com/hakank/hakank

Swedish software developer (retired) / Independent researcher. Interested in programming, mathematics (mostly recreational), constraint programming/modeling, logic programming, machine learning/data mining, inductive (logic) programming, probabilistic programming, genetic programming (especially symbolic regression)and AI (both GOFAI and newer stuff).

Favourite programming languages/systems: Picat, MiniZinc, Prolog, Perl, K, Java, Mathematica, Python.

Submissions

comment 2y ago · link · parent

Yes, the underlying engine of Picat is - a slightly altered- B-Prolog, which is available as the "bp" module, from which one can use many of traditional Prolog constructs, for example `bp.length/2` instead of Picat's `length/1` function. This can help when porting Prolog programs to Picat. In fact, quite a few Prolog programs can be run directly in Picat, perhaps with just some few adjustment.

For some example of the available predicates in the bp module, see my http://hakank.org/picat/v3_utils.pi . Also, see http://hakank.org/picat/#v3 for some examples of ported Prolog programs.

comment 3y ago · link · parent

I really like MiniZinc, especially that one can test a lot of different type of solvers for a problem.

But one of its drawbacks is its limitation of handling input and output (including preprocessing and postprocessing). In some cases - for example when the output is rather simple - I use for example Picat/Python to transform input to MiniZinc format (.dzn format or JSON) and then run MiniZinc.

But for more fancy output I tend to use Picat or Python + (OR-tools CP/SAT or CPMpy or minizinc-python).

That being said, one can do fancier output in MiniZinc, though it requires some work. Here is a model for certain scheduling problems which exemplifies this: http://hakank.org/minizinc/scheduling_with_assignments.mzn . But the output was a little easier to do in Picat: http://hakank.org/picat/scheduling_with_assignments.pi

comment 3y ago · link · parent

Thanks for your kind words.

comment 3y ago · link · parent

> You around, Hakan? :-)

Of course! :-)

comment 3y ago · link · parent

Here are some implementations in different constraint languages on this puzzle (which I call the "Einav puzzle"): http://www.hakank.org/common_cp_models/#einavpuzzle

comment 4y ago · link · parent

I would (also) say that this is a classic planning problem. It's deterministic, observable, static, and discrete.

comment 4y ago · link · parent

The solution is 26 steps and that should be the optimal solution.

comment 4y ago · link · parent

Constraint programming solvers tends to focus on finite domain (integers) but there are some solvers that has some supports for floats as decision variables. You can try some of these solvers.

For non linear models:

* Gecode (included in the MiniZincIDE distribtion)

* JaCoP (https://github.com/radsz/jacop)

* OptiMathSAT (https://optimathsat.disi.unitn.it/pages/fznreference.html)

For linear models:

* CBC (included in the MiniZincIDE distribution)

comment 4y ago · link · parent

I haven't seen a comparison on LP-focused benchmarks with OR-tools CP-SAT. In the 2022 MiniZinc Challenge (https://www.minizinc.org/challenge2022/results2022.html ) both Gurobi, CPLEX (as well and SCIP and HiGHS) participated: CP-SAT was the best in all the categories it participated in.

comment 4y ago · link · parent

Here's a link to Picat's main site: http://picat-lang.org/ . My Picat page have quite a few examples of CP/SAT models (also non-CP programs): http://www.hakank.org/picat/ .

comment 4y ago · link · parent

Well, most Prolog support clp(fd) (Constraint Logic Programming, Finite Domain) which mostly include support for minimizing/maximizing objectives.

comment 4y ago · link · parent

Yes, OR-tools has a lot of solvers. The solver I talked about is the CP-SAT solver. It's described (https://www.minizinc.org/challenge2022/description_or-tools_... ) as:

""" CP-SAT is a discrete optimization solver built on top of a SAT engine. It is available within the OR-Tools open-source repository (website: https://developers.google.com/optimization, github repository: https://github.com/google/or-tools). It has won multiple gold medals at the MiniZinc challenge (https://www.minizinc.org/challenge.html) since its debut in 2017.

The CP-SAT solver is architectured around five components: The base layer is a clause learning SAT solver. Above the SAT layer sits a Constraint Programming (CP) module with Boolean, integer and interval variables, and standard integer, scheduling and routing constraints. Alongside the CP solver, a simplex provides a global linear relaxation. Its integration with the CP and SAT layers enable the CP-SAT solver to solve MIP problems with the same techniques as (commercial) MIP solvers: relaxation, cuts, heuristics and duality based techniques. Both the CP and MIP modules rely on a unified protobuf representation of the model that can serve as a file format, as well as an intermediate representation of the model during all phases of the solve (input format, presolved model, LNS fragment). On top, the search layer implements a robust information-sharing portfolio of specialized workers that offers both good and fast solutions, and superior optimality proving capabilities.

This work was presented at the CPAIOR 2020 masterclass. The recording is available on youtube (https://www.youtube.com/watch?v=lmy1ddn4cyw). """

comment 4y ago · link · parent

One interesting development in the latter years is the mix of Constraint programming and SAT solvers. For example Google OR-tools (https://developers.google.com/optimization/ ) which mixes CP, SAT and MIP. It has won most of the MiniZinc Challenge categories (https://www.minizinc.org/challenge.html ) several years now. The Chuffed solver is another solver mixing CP and SAT.

comment 4y ago · link · parent

Hi again Geoff.

Here are some other constraint modelling implementations of this problem: http://hakank.org/common_cp_models/#einavpuzzle .

comment 6y ago · link · parent

Yes, but the solutions are different if the order (permutation) of the rows with the pattern rotations are different. There is a huge number of ways the rows can be ordered (9!).

comment 6y ago · link · parent

Which are the "9 ways to transpose"? In general there are 8 symmetries of a matrix, but you might also count reordering of rows/columns or blocks?

I agree that 1,5,9,4,8,3,7,2,6 pattern rotations is there somewhere, either in the columns or the rows of a solution, but that don't make all solutions the same.

comment 6y ago · link · parent

What I can see, of these 72 solutions, there are at most 9 distinct solutions when symmetries are removed (rotation, transpose, flipping). I might have missed some solution.

Though, of these 9 solutions there are more similarities, i.e. some of them are the same rows except that the positions are switched.

Some other thing. if the lines are sorted, there are only 4 distinct variants.

Also, the solution of the original Miracle Sudoku instance has some invariants, for example the rows are rotations of these numbers 1,5,9,4,8,3,7,2,6 and the columns are (when rows are sorted) rotations of the numbers 1..9.

I've added comments about this in my Picat model: http://hakank.org/picat/miracle_sudoku.pi

comment 6y ago · link · parent

Actually, the Peaceable Army (or Armies) of Queens problem is a separate problem and much harder than the n-queens problem. Here is a MiniZinc model: http://hakank.org/minizinc/peaceableArmyOfQueens.mzn , and a Picat model: http://hakank.org/picat/peaceableArmyOfQueens.pi

(Also: Thanks for your links to my site.)

comment 7y ago · link · parent

Thanks for the report. The typo is now fixed.

comment 7y ago · link · parent

Not sure if they are that meningful, but I have a collection of SETL programs here: http://www.hakank.org/setl/ (My SETL page).

The page also includes some SetlX programs.

comment 8y ago · link · parent

(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...

comment 8y ago · link · parent

:-) Yes.

comment 8y ago · link · parent

Some of the FlatZinc solvers can handle (nonlinear) finite-domain problems, and some just linear MIP problems with floats.

Some solvers, e.g. Gecode and JaCoP, can handle nonlinear problems with floats as well as finite-domain problems.

comment 8y ago · link · parent

There is a lot off different type of solvers that can be used to solve a MiniZinc model: MIP, Constraint Programming, SAT, Hybrid SAT+CP, Local search etc.