https://github.com/salar-shdk/ac3
cpp AC3 algorithm implementation
https://github.com/salar-shdk/ac3
ac3-algorithm algorithms constraint-satisfaction-problem cpp cpp17 csp
Last synced: 11 days ago
JSON representation
cpp AC3 algorithm implementation
- Host: GitHub
- URL: https://github.com/salar-shdk/ac3
- Owner: salar-shdk
- License: gpl-2.0
- Created: 2021-11-25T05:53:46.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-11-26T05:51:53.000Z (over 4 years ago)
- Last Synced: 2026-05-26T22:31:50.023Z (17 days ago)
- Topics: ac3-algorithm, algorithms, constraint-satisfaction-problem, cpp, cpp17, csp
- Language: C++
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AC3
AC3 algorithm cpp implementation.
# Usage Example
Define your domains as vectors like the given example. Note that position in this vector maters.
``` cpp
// domains = {
// 'a': [0, 2, 4],
// 'b': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
// }
vector> variable_domain = {
{0, 2, 4},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
};
```
Define your constraints as NdArray like the given example. You must have [NumCpp](https://github.com/dpilger26/NumCpp) library installed in your system.
* Only supports equation as constraints.
* You must define actions in relevant position like the given example.
``` cpp
// constraints:
// a + b - 4 = 0
nc::NdArray equation = {
{1, 1, -4},
};
// actions:
// = -> 1
// > -> 2
// < -> 3
// >= -> 4
// <= -> 5
vector action = {1};
```
Then Create AC3 object and call calculate. the result is in the same type of the input domains.
``` cpp
AC3 ac3(variable_domain, equation, action);
auto result = ac3.calculate();
```
# Dependencies
* I strongly recommend to check these two projects if you have not checked yet.
[NumCpp](https://github.com/dpilger26/NumCpp)
[CppItertools](https://github.com/ryanhaining/cppitertools#enumerate)