| Andrew Cooke | Contents | Latest | RSS | Twitter | Previous | Next


Welcome to my blog, which was once a mailing list of the same name and is still generated by mail. Please reply via the "comment" links.

Always interested in offers/projects/new ideas. Eclectic experience in fields like: numerical computing; Python web; Java enterprise; functional languages; GPGPU; SQL databases; etc. Based in Santiago, Chile; telecommute worldwide. CV; email.

Personal Projects

Lepl parser for Python.

Colorless Green.

Photography around Santiago.

SVG experiment.

Professional Portfolio

Calibration of seismometers.

Data access via web services.

Cache rewrite.

Extending OpenSSH.

C-ORM: docs, API.

Last 100 entries

References on Entropy; Amusing "Alexa.." broadcast; Increase Efficiency with GPS Vehicle Tracking for Cat Soft LLC; The Shame of Chile's Education System; Playing mp4 gifs in Firefox on Opensuses Leap 42.2; Concurrency at Microsoft; Globalisation: Uk -> Chile; OpenSuse 42.2 and Synaptics Touch-Pads; Telephone System Quotes for Cat Soft LLC; Even; Cherry Jam; Lebanese Writer Amin Maalouf; Learning From Trump; Chinese Writer Hu Fayun; C++ - it's the language of the future; And; Apricot Jam; Also; Excellent Article on USA Politics; Oh Metafilter; Prejudice Against The Rurals; Also, Zizek; Trump; Why Trump Won; Doxygen + Latex on CentOS 6; SMASH - Solve 5 Biggest Problems in Physics; Good article on racism, brexit, and social divides; Grandaddy are back!; Consciousness From Max Entropy; Democrats; Harvard Will Fix Black Poverty; Modelling Bicycle Wheels; Amusing Polling Outlier; If Labour keeps telling working class people...; Populism and Choice; Books on Defeat; Enrique Ferrari - Argentine Author; Transcript of German Scientists on Learning of Hiroshima; Calvert Journal; Owen Jones on Twitter; Possible Japanese Authors; Complex American Literature; Chutney v5; Weird Componentized Virus; Interesting Argentinian Author - Antonio Di Benedetto; Useful Thread on MetaPhysics; RAND on fighting online anarchy (2001); NSA Hacked; Very Good LRB Article on Brexit; Nussbaum on Anger; Tasting; Apple + Kiwi Jam; Hit Me; Sudoku - CSP + Chaos; Recycling Electronics In Santiago; Vector Displays in OpenGL; And Anti-Aliased; OpenGL - Render via Intermediate Texture; And Garmin Connect; Using Garmin Forerunner 230 With Linux; (Beating Dead Horse) StackOverflow; Current State of Justice in China; Axiom of Determinacy; Ewww; Fee Chaos Book; Course on Differential Geometry; Okay, but...; Sparse Matrices, Deep Learning; Sounds Bad; Applebaum Rape; Tomato Chutney v4; Have to add...; Culturally Liberal and Nothing More; Weird Finite / Infinite Result; Your diamond is a beaten up mess; Maths Books; Good Bike Route from Providencia / Las Condes to Panul; Iain Pears (Author of Complex Plots); Plum Jam; Excellent; More Recently; For a moment I forgot StackOverflow sucked; A Few Weeks On...; Chilean Book Recommendations; How To Write Shared Libraries; Jenny Erpenbeck (Author); Dijkstra, Coins, Tables; Python libraries error on OpenSuse; Deserving Trump; And Smugness; McCloskey Economics Trilogy; cmocka - Mocks for C; Concept Creep (Americans); Futhark - OpenCL Language; Moved / Gone; Fan and USB issues; Burgers in Santiago; The Origin of Icosahedral Symmetry in Viruses; autoenum on PyPI; Jars Explains; Tomato Chutney v3

© 2006-2015 Andrew Cooke (site) / post authors (content).

Installing Gecode/J (Opensuse)

From: "andrew cooke" <andrew@...>

Date: Sat, 13 Sep 2008 20:29:23 -0400 (CLT)

First, you need the C library - http://www.gecode.org/download.html

This is just the usual ./configure --prefix=... ; make; make install

Next, the Java library - http://www.gecode.org/gecodej/download.html

This needs to find the C libs installed previously, so if they weren't in
a standard location you'll need to do something like:

export PKG_CONFIG_PATH=".../gecode-2.2.0/lib/pkgconfig"

before the ./configure --prefix=... ; make; make install

(You also need a JDK, ant, etc).

The documentation can be built with "make doc", but it's doxygen,not
javadoc, which is no doubt much cooler, but is also frustrating if you're
a seasoned Java coder (I suspect this is written by a bunch of academics
who are only touching Java in a bid to be popular...).  You can build
javadoc using

javadoc -d javadoc -subpackages org -sourcepath .

(assuming you're in the main gecodej dir) but it has doxygen markup all
over the place.

And the docs suck big time.  There's a general intro to constraints at
http://kti.mff.cuni.cz/~bartak/constraints/ but it's completely separate
from Gecode (so it's not clear how things tie in) and the english isn't
that great .

There's also a Ruby interface Gecode/R - http://gecoder.rubyforge.org/ -
which as a few more examples.

Ah well.  Onwards...


Programming Constraint Services

From: "andrew cooke" <andrew@...>

Date: Sat, 13 Sep 2008 23:49:27 -0400 (CLT)

Just found a good reference for all this - Christian Schulte's thesis -

I am not sure it describes Gecode - I think it's describing the Oz
precursor - but in the first couple of chapters it's already a answered a
whole pile of questions I had (probably worth reading the article I linked
to earlier first since as general background).  If understanding the
implementation details (at some limited ;evel) will help you understand
the system, this is for you.

Will continue reading tomorrow.


Commented GecodeJ Example

From: "andrew cooke" <andrew@...>

Date: Sun, 14 Sep 2008 11:33:22 -0400 (CLT)

This is Queens (again), but with a bit more explanation that in the
GecodeJ docs.  The output looks like:

Copy constructor for:

package org.acooke.jbv.example;

import static org.gecode.Gecode.branch;
import static org.gecode.Gecode.distinct;

import java.util.Iterator;

import org.gecode.DFSIterator;
import org.gecode.IntValBranch;
import org.gecode.IntVar;
import org.gecode.IntVarBranch;
import org.gecode.Options;
import org.gecode.Space;
import org.gecode.VarArray;

 * A space is a node in the search tree - it does the same work as a
 * stack frame might in a recursive search.
public class Queens extends Space {

  public static final int BOARD_SIZE = 8;

   * We force there to be one queen per row by the way we store the
   * data (we store only a column for each row, rather than a [row,
   * column] pair).  This is a good thing - it gives us a constraint
   * for free and reduces the search space.
  VarArray<IntVar> columnForRow;

   * This is used to create the initial space, so we define the
   * starting conditions.
  public Queens() {
    // the VarArray needs a reference to the space and a size
    columnForRow = new VarArray<IntVar>(this, BOARD_SIZE,
        // the next args construct the contents by calling
        // the constructor of the given class with the args
        // (which in this case will be min and max values -
        // the domain limits are inclusive(!), hence the "-1")
        IntVar.class, 0, BOARD_SIZE-1);
    // (note - this is a static import from Gecode which provides a
    // selection of pre-packaged constraints)
    // add the constraint that every value is distinct
    distinct(this, columnForRow);
    // another constraint saying that
    // x[i] + delta[i] != x[j] + delta[j]
    // gives us one constraint along diagonals
    distinct(this, diagonals(1), columnForRow);
    // and this gives the other
    distinct(this, diagonals(-1), columnForRow);
    // once all constraints have been applied we may still need to
    // search.  so here we describe how to partition the remaining
    // space with an additional constraint
    // http://kti.mff.cuni.cz/~bartak/constraints/ordering.html
    // (again this is a static import from Gecode)
    // so we need to give the space and variables
    branch(this, columnForRow,
        // @see IntVarBranch - this describes which variable to pick
        IntVarBranch.INT_VAR_NONE, // anything!
        // @see IntValBranch - what to do with the values
        IntValBranch.INT_VAL_SPLIT_MAX); // split in half

   * Offsets for constraints on diagonals.
   * @param scale 1 or -1, to give the two directions.
   * @return
  private static int[] diagonals(int scale) {
    int[] delta = new int[BOARD_SIZE];
    for (int i = 0; i < BOARD_SIZE; ++i) {
      delta[i] = i * scale;
    return delta;

   * This is used to clone the space for child nodes.
   * @param share If true, data can be shared (basically, if share is
   * false you've got to expect that different instances will be accessed
   * by different threads).
   * @param s Another instance of this class to copy (not sure why Space
   * doesn't have the signature Space<S extends Space>).
  protected Queens(Boolean share, Queens q) {
    super(share, q);
    System.err.print("Copy constructor for:\n" + q.toString());
    // there's a constructor that does all the work for us
    columnForRow = new VarArray<IntVar>(this, share, q.columnForRow);

  public String toString() {
    StringBuilder builder = new StringBuilder();
    for (IntVar queen: columnForRow) {
      for (int column = 0; column < BOARD_SIZE; ++column) {
        // we need to be careful here - we can't access values if
        // they haven't been assigned.
        if (! queen.assigned()) {
        } else if (queen.val() == column) {
        } else {
    return builder.toString();

  public static void main(String[] args) {
    Queens space = new Queens();
    // let's use depth first search with whatever the defaults are
    // (there doesn't seem to be an interface that exposes Iterable)
    Iterator<Queens> results =
      new DFSIterator<Queens>(space, new Options());
    while (results.hasNext()) {
      System.out.println("Result:\n" + results.next().toString());


Not to be popular...

From: "andrew cooke" <andrew@...>

Date: Mon, 15 Sep 2008 08:54:37 -0400 (CLT)

---------------------------- Original Message ----------------------------
From:    "Mikael Zayenz Lagerkvist" <zayenz@...>
Date:    Mon, September 15, 2008 5:42 am

"I suspect this is written by a bunch of academics
who are only touching Java in a bid to be popular..."

Well, we might be academics, but the Java interface was done out of
neccessity, not to be popular.

Mikael Zayenz Lagerkvist, http://www.ict.kth.se/~zayenz/

GecodeJ Not for "Real Use"

From: "andrew cooke" <andrew@...>

Date: Mon, 15 Sep 2008 08:56:41 -0400 (CLT)

Turns out GecodeJ is only intended for teaching; for decent efficiency you
apparently need to use the C++ library.


Big pity...



From: "andrew cooke" <andrew@...>

Date: Mon, 15 Sep 2008 09:08:24 -0400 (CLT)

I missed this earlier.  At first glance it seems to have some of the same
annoyances as GecodeJ (eg ranges are inclusive instead of half open), but
the documentation is hugely better: there's a readable guide at
http://choco-solver.net/index.php?title=User_guide and javadocs at

Also, it seems to be a pure Java implementation, so hopefully extending it
won't be so tricky.


Comment on this post