Please note that Pisinger's algorithms may be used for academic, non-commercial purposes only.
This package provides a Julia interface to some Pisinger's algorithms.
This package is not registered in the Julia Package Manager.
Pkg.add("https://github.com/atoptima/PisingerKnapsack.jl.git")
Pkg.build("PisingerKnapsack")
Methods return two arguments : obj
is the total cost of the knapsack and sol
is a vector
in which the value of the ith entry is the number the ith item is in the knapsack.
obj, sol = minknap(costs::Vector, weights::Vector, capacity::Real)
obj, sol = bouknap(costs::Vector, weights::Vector, itemub::Vector, capacity::Real)
obj, sol = mulknap(costs::Vector, weights::Vector, capacity::Vector)
You need cmake and a C compiler to compile Pisinger algorithms. The compilation takes place in PisingerKnapsack.jl/deps/libpisinger/
. The structure of the folder is :
libpisinger
├── bouknap
│ └── CMakeLists.txt
├── minknap
│ └── CMakeLists.txt
└── minmcknap
└── CMakeLists.txt
For each algorithm, one subfolder contains a cmake file. The build step download in each subfolder the source code of the corresponding algorithm. Then, it creates a build
folder, runs cmake
and make
. At the end, each subfolder will contain a build
folder with a dynamic library inside. For example :
libpisinger
├── bouknap
│ ├── CMakeLists.txt
│ ├── bouknap.c
│ └── build
│ ├── CMakeCache.txt
│ ├── Makefile
│ └── libbouknap.dylib
If the build step does not work, these are the steps to build the dynamic libraries of Pisinger's algorithms :
- Download source files in Pisinger's website and, for each algorithm, move the corresponding file to
PisingerKnapsack.jl/deps/libpisinger/<algoname>
- Create directory
build
inPisingerKnapsack.jl/deps/libpisinger/<algoname>
- Go to the folder
build
, runcmake ..
, thenmake
- Create a file
deps.jl
and add insideconst _jl_lib<algoname> "<ABSOLUTE_PATH_TO>/PisingerKnapsack.jl/deps/libpisinger/<algo_name>/build/<dynamic_lib>"