Skip to content

Three common programming paradigms or styles are the imperative (OO & procedural), functional, and logic (or constraint) styles. This repo shows examples of the latter using the Apache Groovy programming language and other (mostly JVM) languages which support this style of programming (often using libraries).

License

paulk-asert/groovy-constraint-programming

Repository files navigation

Groovy Constraint Programming

This repo contains examples from an Introduction to Constraint Programming talk:

https://speakerdeck.com/paulk/groovy-constraint-programming

You have 4 options to run the examples:


The Pythagorean subproject is an introductory example comparing an imperative style solution (using a brute-force approach), and a constraint-programming solution (using Choco[1]).

Pythagorean

Run Choco solution via Jupyter/BeakerX: Binder

Command-line arguments for Gradle to run the script: :Pythagorean:run


The McNuggets subproject illustrates solving a fairly simple Frobenius numbers puzzle using Choco[1] and Ojalgo[2].

McNuggets

Command-line arguments for Gradle to see the task names for the available solutions:

:McNuggets:tasks --group="Application"

Then pick one of those tasks to run, e.g. to run the Ojalgo solution:

:McNuggets:runOjalgo

Cryptarithmetic puzzles

This example solves a classic cryptarithmetic puzzle using constraint programming. The Groovy solution is contrasted with brute-force approaches and solutions in other JVM languages.

Constraint programming

See the SendMoreMoney subproject for all the details.

Constraint-programming libraries covered: Choco

Programming languages covered: Clojure, Groovy, Frege, Java, Nashorn, JRuby, Jython, Kotlin, Luaj, Scala, tuprolog.


Diet optimization

This example solves an optimization/linear programming problem. Numerous technologies and approaches are used to solve the problem.

Linear programming

See the Diet subproject for all the details.

Technologies illustrated: Apache Commons Math, Hipparchus, Choco (with and without ibex integration), JaCoP (using scalar-product/weighted-sum and knapsack algorithms), Ojalgo, OptaPlanner, OrTools, SAS/OR.


Genetic algorithms

This example uses genetic algorithms to explore the infinite monkey theorem.

Chimpanzee at keyboard

See the Monkeys subproject for all the details.

Technologies illustrated: Apache Commons Math, Jenetics.


Technology summary

Libraries used:

Choco, Hipparchus, Apache Commons Math, JaCoP, OptaPlanner, OrTools, Jenetics, SAS/OR (commercial product).


About

Three common programming paradigms or styles are the imperative (OO & procedural), functional, and logic (or constraint) styles. This repo shows examples of the latter using the Apache Groovy programming language and other (mostly JVM) languages which support this style of programming (often using libraries).

Topics

Resources

License

Stars

Watchers

Forks