2.2 Installation

First of all, you need to download JCOP files. Download latest version from download page.

The archive contains all you need to run JCOP - both its JAR file and all libraries used in JCOP (such as log4j or JFreeChart). Contents of the archive are displayed in figure 1. You can extract this archive anywhere you like, you will just have to add it to your libraries.

Usually you will need to add just jcop.jar and other libraries will be loaded automatically. If not, add them manually the same way as you added jcop.jar. Follows instructions on how to add a JAR to a project for commonly used IDE.

JCOP archive contents

Figure 1: JCOP archive contents.

IntelliJ IDEA 9.0.1 Community Edition

Create new project from File → New Project. Select Create project from scratch and follow the wizard (don't forget to add at least one module). Then go to File → Project Structure and choose Libraries from Project settings. Click the New Project Library ("+" icon, alt+insert) and type jcop as name. You should see something like figure 2.

IntelliJ IDEA new library

Figure 2: IntelliJ IDEA new library.

After you have created new library, click Attach Classes and add jcop.jar file. Result should look like figure 3.

IntelliJ IDEA Attached Jar Directories

Figure 3: IntelliJ IDEA Attached Jar Directories.

JCOP is now ready. To test it, try to run a test application.

NetBeans IDE 6.8

Create new Java Application project in File → New Project, select category as shown in figure 4.

NetBeans IDE new project

Figure 4: NetBeans IDE new project.

Right click on Libraries in project tree and select Add JAR/Folder as show in figure 5 and add jcop.jar.

NetBeans IDE Add JAR/Folder

Figure 5: NetBeans IDE Add JAR/Folder.

JCOP is now ready. To test it, try to run a test application.

Eclipse IDE for Java Developers (

Create new project from File → New → Java project. Right click on project and select Properties as show in figure 6.

Eclipse project properties

Figure 6: Eclipse project properties.

Navigate to Java Build Path and select Libraries. There, click Add External JARs and jcop.jar as in figure 7.

Eclipse Add External JARs

Figure 7: Eclipse Add External JARs.

JCOP is now ready. To test it, try to run a test application.

Test Application

To test that JCOP was installed, you can use this simple application. Just add new Java Main Class to your project with following code and run it (you might need to change package to one that you put Main Class in).

package jcoptest;

import cz.cvut.felk.cig.jcop.algorithm.graphsearch.bfs.BreadthFirstSearch;
import cz.cvut.felk.cig.jcop.problem.knapsack.Knapsack;
import cz.cvut.felk.cig.jcop.result.render.CSVRender;
import cz.cvut.felk.cig.jcop.result.render.JFreeChartRender;
import cz.cvut.felk.cig.jcop.result.render.SimpleRender;
import cz.cvut.felk.cig.jcop.result.render.XMLRender;
import cz.cvut.felk.cig.jcop.solver.SimpleSolver;
import cz.cvut.felk.cig.jcop.solver.Solver;
import java.io.File;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        Solver solver = new SimpleSolver(new BreadthFirstSearch(), new Knapsack("9000 4 100 18 114 42 136 88 192 3 223"));
        solver.addListener(new JFreeChartRender("Test"));
        solver.addRender(new SimpleRender());
        solver.addRender(new CSVRender(new File("test.csv")));
        solver.addRender(new XMLRender(new File("test.xml")));

If everything went fine you should see this in console:

0 [main] INFO cz.cvut.felk.cig.jcop.solver.SimpleSolver  - Started solver.
16 [main] INFO cz.cvut.felk.cig.jcop.solver.SimpleSolver  - Started optimize, BreadthFirstSearch [] on Knapsack [line=9000 4 100 18 114 42 136 88 192 3 223].
16 [main] WARN cz.cvut.felk.cig.jcop.solver.SimpleSolver  - Got exception CannotContinueException.
16 [main] INFO cz.cvut.felk.cig.jcop.solver.SimpleSolver  - Stopped optimize.
31 [main] INFO cz.cvut.felk.cig.jcop.solver.SimpleSolver  - Stopped solver.

=== Algorithm BreadthFirstSearch [] used on problem Knapsack [line=9000 4 100 18 114 42 136 88 192 3 223] ===
  CPU Time:                       1 [ms]
  System Time:                    1 [ms]
  User Time:                      1 [ms]
  Clock Time:                    15 [ms]
  Optimize counter:              16 [-]
  Optimize/sec (CPU):         16000 [1/s]
  Optimize/sec (Clock):        1066 [1/s]
  Best solution:         Configuration{attributes=[1, 1, 0, 1], operationHistory={0:Empty knapsack created, 1:AddOperation{knapsackItem=KnapsackItem{index=0, weight=18, price=114}}, 2:AddOperation{knapsackItem=KnapsackItem{index=1, weight=42, price=136}}, 3:AddOperation{knapsackItem=KnapsackItem{index=3, weight=3, price=223}}}}
  Depth:                          3 [-]
  Fitness:                    473,0 [-]
  Ended with exception:  cz.cvut.felk.cig.jcop.algorithm.CannotContinueException: No more items in queue

, graph like figure 8 should pop up and files test.xml and test.csv should be in your application working directory (see expected contents, xml and csv respectively, below).

Graph of test application

Figure 8: Graph of test application.

<?xml version="1.0" standalone="yes"?>
  <experiment date='Tue Mar 16 10:26:59 CET 2010'></experiment>
  <entry exception='CannotContinueException' clock-time='15' system-time='1' user-time='16' algorithm='BreadthFirstSearch []' cpu-time='16' optimize-counter='16' problem='Knapsack [line=9000 4 100 18 114 42 136 88 192 3 223]'>
    <best-solution fitness='473.0'>
        <operation index='0' label='Empty knapsack created'></operation>
        <operation index='1' label='AddOperation{knapsackItem=KnapsackItem{index=0, weight=18, price=114}}'></operation>
        <operation index='2' label='AddOperation{knapsackItem=KnapsackItem{index=1, weight=42, price=136}}'></operation>
        <operation index='3' label='AddOperation{knapsackItem=KnapsackItem{index=3, weight=3, price=223}}'></operation>
        <attribute index='0' value='1' human-readable-value='1'></attribute>
        <attribute index='1' value='1' human-readable-value='1'></attribute>
        <attribute index='2' value='0' human-readable-value='0'></attribute>
        <attribute index='3' value='1' human-readable-value='1'></attribute>
Algorithm,Problem,CPU Time [ms],System Time [ms],User Time [ms],Clock Time [ms],Optimize counter,Optimize/sec (CPU) [1/s],Optimize/sec (Clock) [1/s],Exception,Best solution,Depth,Fitness,Operations
BreadthFirstSearch [],Knapsack [line=9000 4 100 18 114 42 136 88 192 3 223],16,1,16,15,16,1000,1066,class cz.cvut.felk.cig.jcop.algorithm.CannotContinueException,"[1, 1, 0, 1]",3,473.0,"Empty knapsack created, AddOperation{knapsackItem=KnapsackItem{index=0, weight=18, price=114}}, AddOperation{knapsackItem=KnapsackItem{index=1, weight=42, price=136}}, AddOperation{knapsackItem=KnapsackItem{index=3, weight=3, price=223}}"