An open API service indexing awesome lists of open source software.

https://github.com/pjritee/pl_search_cpp

A C++ module that uses Prolog ideas for search and constraint programming
https://github.com/pjritee/pl_search_cpp

backtracking-search constraint-logic-programming constraint-programming cplusplus prolog

Last synced: 11 days ago
JSON representation

A C++ module that uses Prolog ideas for search and constraint programming

Awesome Lists containing this project

README

          

# pl_search_cpp

pl_search_cpp is a C++ library that approximates Prolog predicates using a continuation-passing style. It provides a framework for defining and executing Prolog-like predicates, including support for backtracking, choice points, and unification.

## Features

- Prolog-like predicates
- Continuation-passing style execution
- Backtracking and choice points
- Unification of terms
- Support for variables, integers, floats, atoms, and lists

## Installation

### Prerequisites

- C++11 or later
- CMake 3.10 or later

### Building the Library

1. Clone the repository:

```sh
git clone https://github.com/yourusername/pl_search_cpp.git
cd pl_search_cpp
```

2. Create a build directory and navigate to it:

```sh
mkdir build
cd build
```

3: Run CMake to configure the project:

```sh
cmake ..
```

4: Build the project:

```sh
make
```

This will build the pl_search library and place it in the lib directory.

## Examples

The examples directory contains the following examples of using the library.

- A solver for the SEND+MORE=MONEY puzzle with lots of comments about the approach and code details (send_more_money.cpp).
- An example of a user defined Term type (prolog_list.hpp).
- An implementation of the Prolog append predicate using the above type (append_pred.hpp).
- A main program ( prolog_list.cpp) that exercises the definitions above.
- A Makefile to build the executables.
- A serious use of this library was for searching for the Orthogonal Designs listed in the OD_Designs repo.

## Documentation

Documentation can be found here [docs/index.html](https://pjritee.github.io/pl_search_cpp/docs/html/index.html)

## License

This project is licensed under the MIT License - see the LICENSE file for details.

## Version History
* 1.7
- Change clear_stacks in engine.cpp so that trail entries created before execute is called are also cleaned up.
- Fix two warnings.
* 1.6
- Change CList so that the contained list becomes immutable.
* 1.5
- Change the constructor of CList to copy the supplied list.
* 1.4
- Change from private to protected in term and pred classes to increase flexibility when subclassing. For example, termcolour can now be used in subclasses of various terms.
* 1.3
- Add an if-then-else predicate.
* 1.2
- Several (small) code optimizations - improved send_more_money by about 30%
- dynamic_cast(t.get()) is faster than dynamic_pointer_cast(t)
- redo PVar::dereference to avoid shared_ptr copies
- add Term* Term::deref_term() to avoid copying shared_ptr (for internal use)
- In Var::bind use raw pointer for pointer test
- change env_stack and trail_stack to use normal pointers
- Turned on -O2 optimization in cmake - approximately another 10% improvement
* 1.1
- Fix problems in unify
- Remove the test_choice method from Pred
- merge solve into main in send_more_money.cpp for better testing with valgrind
* 1.0
- Initial release.