Getting Started with

Groovy Java Genetic Programming

Genetic Programming (JGProg) is an open-source pure Java implementation of a strongly-typed Genetic Programming experimentation platform. Three example "worlds" are provided, in which a population evolves and solves the problem. Now that's Groovy. The source code is released under the GNU General Public Licence.

Go to the Groovy Java main home page

Go to the Groovy Java Genetic Programming home page


  1. What's Genetic Programming?
  2. Quickstart
  3. Program Tree Representation in JGProg
  4. The Classes of JGProg
  5. Running JGProg

What's Genetic Programming?

Genetic Programming (GP) is a subset of the field of Evolutionary Programming (EP) which is itself a subset of the field of Artificial Intelligence (AI). Loosely and simply, AI is the subject of how machines can solve problems. Evolutionary Programming is the subject of how machines can solve problems using the software equivalents of the mechanisms of biological evolution. Genetic Programming is the subject of how machines can solve problems using the software equivalents of the mechanisms of biological evolution where the thing which is evolving is a program structured as a tree. This is as opposed to Genetic Algorithms (GA) where the thing which is evolving is a binary representation of a program, or more usually, parameters to a fixed, non-evolving program. There's also Neural Networks (NN) which is a subset of AI which attempts to solve problems by using modular neurons and a learning algorithm, and there's Artificial Life (A-Life, AL) which is a kind of subset of AI where the problem to solve is more biological than anything else (e.g. "survive by eating food and fighting rivals"). I say "kind of" because the "creatures" of A-Life can use any of the mechanisms of AI to solve the problem, including GP, GA, NN, etc.

Of course, this "hierarchy" hasn't prevented cross-pollination: GP has been used to generate neural networks, for example.

Rather than reinvent the wheel, I'll just point you to an excellent What is GP? page written by Dr. GP himself, Dr. John Koza. And if you're really interested in stuff about Genetic Programming, there are many books you can buy. The best books by far are Dr. Koza's "trilogy":

You can get these books from, which is where the above links point to, and cheaper than from

Of course, if you can only afford one of those books, get the first one.

There's another set of books if you're into science fiction, all by James P. Hogan, combining evolutionary programming and fiction:


Ready to try it?

First, you'll need Java. For Windows, Solaris, and Linux you can go to Sun Microsystems to get it. For other operating systems you'll have to find it, usually from the operating system vendor themselves (Apple for MacOS, IBM for AIX or OS/2, Hewlett-Packard for HPUX, etc).

Be sure to get Java v1.2 or above, and be sure to follow the installation instructions. They're usually pretty simple.

Next, you'll need to download JGProg. You can do that at the JGProg Project Page. Look for File Releases, the jgprog-jar module, and click on the [zip] link. This will give you the zip file containing the JGProg jar file and the HTML documentation.

Unzip the zip file to some directory. Go to that directory and use this command:

java -classpath jgprog.jar com.groovyj.jgprog.SymbolicRegressionWorld

This is a quick little run which attempts to evolve a real-valued function of one variable given 20 random points along the curve y=x4+x3+x2+x.

Here's something from the digital world for you to try:

java -classpath jgprog.jar com.groovyj.jgprog.MultiplexerWorld

This run takes a little longer to solve. It's the "11-multiplexer" problem, which is essentially a boolean-valued function of 11 variables. The 11 variables are A0, A1, A2, D0, D1, D2, D3, D4, D5, D6, and D7. The object is to get the output to match one of the D inputs based on the binary-encoded value of A0, A1, and A2. Since there are 11 boolean inputs, there are 2048 combinations. Each individual in the population is tested against all 2048 cases.

Program Tree Representation in JGProg

JGProg represents programs using nodes. Each node can have zero or more children. If a node has zero children, it is called a terminal, and if it has one or more children, it is called a function.

Each node performs some computation and returns the result. For example, the "One" node simply returns the value 1. The "Add" node, which has two children, evaluates its children, adds their results, and returns that.

This is not to say that nodes are limited to mathematical operations. They can do any operation you can think of, and they don't have to return anything.

Each node is captured in an instance of the Node class, which is extended to provide all the different kinds of nodes (e.g. One, Add, etc).

JGProg is called "strongly-typed" because each node must have a return type, such as integer, boolean, float, or void. The types of children a node can take are also fixed. For example, a float-typed Add node may only take float-typed children. Some nodes allow any kind or most kinds of return types. Some nodes may only return one type. In general, a node, when given its return type, restricts the types of its children as well. Strong typing has the effect of getting around Koza's "closure" requirement, which states that any node should be able to use the output of any other node. Whether strong typing is in general better or worse than closure is a matter of debate, but it sure makes programs make a little more sense.

The Classes of JGProg

Here's a groovy little diagram of the class hierarchy that JGProg uses.

This gives you starting points when looking at the classes: World for defining your own GP problem to solve, and Node for defining your own nodes. Take a look at the javadocs for each of these classes to find out how to define your own stuff.

Running JGProg

(under construction)

Problems on this page? Bug reports? Enhancement ideas? Contact Robert Baruch.
Last Update: 25 April 2000