| 1 |
# Welcome to Kiwi |
| 2 |
|
| 3 |
[](https://github.com/nucleic/kiwi/actions) |
| 4 |
[](https://github.com/nucleic/kiwi/actions) |
| 5 |
[](https://codecov.io/gh/nucleic/kiwi) |
| 6 |
[](https://kiwisolver.readthedocs.io/en/latest/?badge=latest) |
| 7 |
|
| 8 |
Kiwi is an efficient C++ implementation of the Cassowary constraint solving |
| 9 |
algorithm. Kiwi is an implementation of the algorithm based on the |
| 10 |
[seminal Cassowary paper](https://constraints.cs.washington.edu/solvers/cassowary-tochi.pdf). |
| 11 |
It is *not* a refactoring of the original C++ solver. Kiwi has been designed |
| 12 |
from the ground up to be lightweight and fast. Kiwi ranges from 10x to 500x |
| 13 |
faster than the original Cassowary solver with typical use cases gaining a 40x |
| 14 |
improvement. Memory savings are consistently > 5x. |
| 15 |
|
| 16 |
In addition to the C++ solver, Kiwi ships with hand-rolled Python bindings. |
| 17 |
|
| 18 |
# How to use |
| 19 |
## C++ with CMake |
| 20 |
Write the following in your CMakeLists.txt to include Kiwi as a dependency: |
| 21 |
``` cmake |
| 22 |
include(FetchContent) |
| 23 |
|
| 24 |
FetchContent_Declare( |
| 25 |
kiwi |
| 26 |
GIT_REPOSITORY https://github.com/nucleic/kiwi |
| 27 |
GIT_TAG {release name} |
| 28 |
) |
| 29 |
|
| 30 |
FetchContent_MakeAvailable(kiwi) |
| 31 |
|
| 32 |
target_link_libraries(your_target PRIVATE kiwi::kiwi) |
| 33 |
``` |
| 34 |
C++ code example: |
| 35 |
``` cpp |
| 36 |
#include <kiwi/kiwi.h> |
| 37 |
#include <iostream> |
| 38 |
|
| 39 |
int main() { |
| 40 |
// initialize the solver |
| 41 |
kiwi::Solver solver; |
| 42 |
// initialize the variables |
| 43 |
kiwi::Variable x = kiwi::Variable("x"); |
| 44 |
kiwi::Variable y = kiwi::Variable("y"); |
| 45 |
solver.addConstraint(x + y == 10); |
| 46 |
solver.addConstraint(x - y == 4); |
| 47 |
// solve the system of equations |
| 48 |
solver.updateVariables(); |
| 49 |
std::cout << "x: " << x.value() << ", y: " << y.value() << std::endl; |
| 50 |
// Output: x: 7, y: 3 |
| 51 |
return 0; |
| 52 |
} |
| 53 |
``` |
| 54 |
You can also use tests to see more examples of how to use the solver: [SimlpexTest](https://github.com/nucleic/kiwi/blob/main/tests/SimplexTest.cpp) and [SolverTest](https://github.com/nucleic/kiwi/blob/main/tests/SolverTest.cpp). |