English | 日本語
A header-only C++20 library for matroids using ZDDs.
This library depends on the following ZDD package:
| SAPPOROBDD | OS | Compiler |
|---|---|---|
| v.20230102 | Ubuntu 22.04 | GCC 11.4.0 |
| Ubuntu 24.04 | Clang 16.0.6 | |
| macOS 14 | GCC 12.4.0 | |
| Clang 15.0.7 |
If you have not installed SAPPOROBDD, please follow these steps:
-
Clone this repository with submodules.
git clone --recursive https://github.com/emthrm/matroidd.git -b v0.1.0
-
Install SAPPOROBDD using dd_package.
cd ./matroidd/third_party/dd_package sh ./downloader.sh -
Specify
/path/to/matroidd/third_party/dd_package/SAPPOROBDD/includeas an include path.
-
Clone this repository.
git clone https://github.com/emthrm/matroidd.git -b v0.1.0
-
cd ./matroidd -
Generate a project buildsystem. It is recommended to specify the absolute path to the static library of SAPPOROBDD in
MATROIDD_SAPPOROBDD_FULL_LIBPATH.cmake -S . -B ./build -DMATROIDD_SAPPOROBDD_FULL_LIBPATH=/path/to/matroidd/third_party/dd_package/SAPPOROBDD/lib/BDD64.a -
Install this library.
cmake --install ./build
See matroiDD User Guide.
#include <array>
#include <cassert>
#include <iostream>
#include <ranges>
#include <vector>
// SAPPOROBDD
#define B_64 // Use SAPPOROBDD in 64-bit mode.
#include "BDD.h" // BDD_NewVar
#include "ZBDD.h" // ZBDD::Card
// matroiDD
#include "matroidd/generators.hpp" // matroidd::FromBases
#include "matroidd/matroid.hpp" // matroidd::Matroid
#include "matroidd/util/util.hpp" // matroidd::BddVarType
int main() {
constexpr int kN = 3;
// Create input variables for SAPPOROBDD.
for (const matroidd::BddVarType i : std::views::iota(1, kN + 1)) {
assert(BDD_NewVar() == i);
}
// Create a matroid object
// corresponding to the collection of bases {{1, 2}, {1, 3}}.
const matroidd::Matroid matroid = matroidd::FromBases(
std::vector{std::array<int, 2>{1, 2}, std::array<int, 2>{1, 3}});
// Output the number of independent sets.
std::cout << matroid.IndependentSets().Card() << '\n'; // 6
return 0;
}(For developers using SAPPOROBDD)
See BDDopID.yml.
matroiDD is released under the MIT License.