3
=======================
4
Multiplexer 3-8 Problem
5
=======================
7
The multiplexer problem is another extensively used GP problem. Basically, it
8
trains a program to reproduce the behavior of an electronic `multiplexer
9
<http://en.wikipedia.org/wiki/Multiplexer>`_ (mux). Usually, a 3-8
10
multiplexer is used (3 address entries, from A0 to A2, and 8 data entries,
11
from D0 to D7), but virtually any size of multiplexer can be used.
13
This problem was first defined by Koza (see :ref:`refPapersMux`).
18
The primitive set is almost the same as the set used in :ref:`Parity
19
<parity>`. Three Boolean operators (and, or and not), imported from
20
:mod:`operator`, and a specific if-then-else primitive, which return either
21
its second or third argument depending on the value of the first one.
23
.. literalinclude:: /../examples/gp/multiplexer.py
26
As usual, we also add two terminals, a Boolean true and a Boolean false.
31
To speed up the evaluation, the computation of the input/output pairs is done
32
at start up, instead of at each evaluation call. This pre-computation also
33
allows to easily tune the multiplexer size, by changing the value of
36
.. literalinclude:: /../examples/gp/multiplexer.py
40
After that, the evaluation function is trivial, as we have both inputs and
41
output values. The fitness is then the number of well predicted outputs over
42
the 2048 cases (for a 3-8 multiplexer).
44
.. literalinclude:: /../examples/gp/multiplexer.py
45
:pyobject: evalMultiplexer
47
The complete :example:`gp/multiplexer`.
54
*John R. Koza, "Genetic Programming I: On the Programming of Computers by
55
Means of Natural Selection", MIT Press, 1992, pages 170-187.*