JCOP's util package contains several useful classes which are used by several other packages to simplify things a bit. Util currently contains classes PreciseTime and JcopRandom along with several comparators.
PreciseTime is used to measure all kind of times in JCOP. Apart from regular time (called
clock time) there are CPU, User and System times (for more information see
CPU/User/System time on Wikipedia. Note that by CPU time JCOP understands User + System time), which allows to
measure CPU/User/System time of current thread. Keep in mind that despite its name, PreciseTime is
not perfectly precise. Times returned depends very much on used operating system and even though returned time is in
miliseconds precision, it need not be in miliseconds accuracy.
This class works together with PreciseTimestamp which stores all four times (clock, cpu, system, user) as one timestamp and represents one point in time. When two different timestamps are created, you can get how much time were spent between them. PreciseTimestamp is preferred to be used in JCOP whenever you want to measure time.
JcopRandom is extension to simple
java.util.Random. It has two goals in mind. First is to have static access so that you do not need to create
new Random() instances for just one random number. The other is however much more important. JcopRand
could be initialized with random seed (just as
java.util.Random can), but whenever you do this, all random numbers in whole JCOP (as long as all parts of JCOP
uses JcopRandom) will return random numbers in the same order. You can then run one experiment again
with exactly the same results (well, almost the same - same as long as they do not depend on time for example) really
These classes implements java.util.Comparator interface and are used to sort arrays of elements in JCOP. For example, in SimpleCompareRender, you need to sort results by their fitness. So you just create a ResultEntryFitnessComparator and you can sort list of ResultEntries to be displayed best to worst.
Even though Log4j is not part o Util package, it belongs here. It is a third-party library used to low-level debugging and logging and is very easy to use. For examples on usage I recommend reading Short introduction to log4j on its homepage.
The only requirement for Log4j to work properly in JCOP is to initialize it correctly. This can be done in several
ways, but the preferred one is using
log4j.properties file. Log4j looks for this file in your classpath
and tries to configure itself from it. There are three such files bundled with JCOP - log disabled completely (file
log4j-off.properties), log enabled to console (file
log4j-console.properties) and log
enabled to console and file (configuration
log4j-console-file.properties). They all reside inside
jcop.jar archive or available to download from SourceForge.
You can use one of them (copy it to your source folder and rename it to
or write your own (see log4j documentation for details
then). If you have not configured log4j properly, you are most likely to get something like this in console:
log4j:WARN No appenders could be found for logger (cz.cvut.felk.cig.jcop.solver.SimpleSolver). log4j:WARN Please initialize the log4j system properly.