These instructions are for installing libqif
to use with C++. For python, see the README.
The easiest way to install libqif (especially on macOS) is via Homebrew:
brew tap chatziko/tap
brew install --HEAD libqif
brew test --HEAD libqif
To upgrade to the latest version:
brew reinstall libqif
On Linux: Homebrew is also available on linux. You need to use some compiler supporting c++17, eg
brew install -cc=gcc-9 --HEAD libqif
It installs everything under /home/linuxbrew/.linuxbrew
, so you need
to either configure your system to use libraries from there, or symlink
eveything under /usr/local
:
sudo ln -s /home/linuxbrew/.linuxbrew/include/qif* /usr/local/include/
sudo ln -s /home/linuxbrew/.linuxbrew/lib/libqif* /usr/local/lib/
sudo ldconfig
Create a simple test.cpp
file:
#include <qif>
using namespace qif;
int main() {
chan C("1 0 0; 0 1 0; 0 0 1");
prob pi = probab::uniform<double>(3);
std::cout
<< "Bayes vulnerability of \n"
<< C << " under " << pi << " is "
<< measure::bayes_vuln::posterior(pi, C) << "\n";
}
Compile and run with:
g++ test.cpp -std=c++17 -lqif -larmadillo -lgmp -lmp++ -o test
./test
# or with clang
clang++ test.cpp -std=c++17 -lqif -larmadillo -lgmp -lmp++ -o test
You can find more sample programs in the samples directory.
In macOS 10.4 you might also need -L/usr/local/lib
.
If OR-Tools are used you also need to link with -lortools
.
Prerequisites
Optionally
On Ubuntu, these can be installed with:
sudo apt-get install g++ cmake libgmp-dev libglpk-dev libgsl0-dev
Get the code (note the --recursive
to fetch the submodules).
git clone --recursive https://github.com/chatziko/libqif.git
To compile / install:
mkdir <path>/build && cd <path>/build
cmake ..
make
sudo make install
To run the tests
make tests_cpp
./tests_cpp/run
To build the samples:
make samples
./samples/<sample>
Several libqif methods can use OR-Tools for linear optimization and network flow. When installing via Homebrew, OR-Tools are installed automatically.
When installing manually, you should install OR-Tools before compiling libif.
The easiest way is to locate the .tar.gz
file for your system in the
OR-Tools binary distributions,
then install it by simply copying the libraries and header files under /usr/local
:
wget <binary-distribution-url> | tar -xzf -
sudo cp -r ortools*/{lib,include} /usr/local/
Alternatively, you can install OR-Tools from source via cmake. The instructions in that link are dated, a method that has been tested is below:
git clone https://github.com/google/or-tools --depth 1 --branch=v7.2
mkdir or-tools/build && cd or-tools/build
cmake -DBUILD_DEPS:BOOL=ON ..
sudo cmake --build . --target install
sudo cp -r dependencies/install/* /usr/local