https://github.com/dirkschumacher/rpicosat
PicoSAT bindings for R
https://github.com/dirkschumacher/rpicosat
logic logic-programming picosat r sat sat-solver satisfiability
Last synced: about 1 year ago
JSON representation
PicoSAT bindings for R
- Host: GitHub
- URL: https://github.com/dirkschumacher/rpicosat
- Owner: dirkschumacher
- License: other
- Created: 2017-07-14T09:02:26.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-01-22T11:34:28.000Z (over 4 years ago)
- Last Synced: 2023-03-23T04:47:42.333Z (over 3 years ago)
- Topics: logic, logic-programming, picosat, r, sat, sat-solver, satisfiability
- Language: R
- Size: 90.8 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output:
md_document:
variant: gfm
---
[](https://github.com/dirkschumacher/rpicosat/actions)
[](https://CRAN.R-project.org/package=rpicosat)
[](https://app.codecov.io/gh/dirkschumacher/rpicosat?branch=master)
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
# rpicosat
R bindings to the [PicoSAT solver release 965](http://fmv.jku.at/picosat/) by Armin Biere. The PicoSAT C code is distributed under a MIT style license and is bundled with this package.
## Install
### Install development version
```{r, eval=FALSE}
devtools::install_github("dirkschumacher/rpicosat")
```
### Install stable version from CRAN
```{r, eval = FALSE}
install.packages("rpicosat")
```
## API
* `picosat_sat` can solve a SAT problem. The result is a `data.frame` + meta data, so you can use it with `dplyr` et al.
* `picosat_solution_status` applied to the result of `picosat_sat` returns either *PICOSAT_SATISFIABLE*, *PICOSAT_UNSATISFIABLE* or *PICOSAT_UNKNOWN*
The following functions can be applied to solutions and make available some statistics generated by the `PicoSAT` solver:
* `picosat_added_original_clauses` #clauses
* `picosat_decisions` #decisions
* `picosat_propagations` #propagations
* `picosat_seconds` seconds spent in the C function `picosat_sat`
* `picosat_variables` #variables
* `picosat_visits` #visits
## Example
Suppose we want to test the following formula for satisfiability:
$$
(A \Rightarrow B) \wedge (B \Rightarrow C) \wedge (C \Rightarrow A)
$$
This can be formulated as a CNF (conjunctive normal form):
$$
(\neg A \vee B) \wedge (\neg B \vee C) \wedge (\neg C \vee A)
$$
In `rpicosat` the problem is encoded as a list of integer vectors.
```{r}
formula <- list(
c(-1, 2),
c(-2, 3),
c(-3, 1)
)
```
```{r example}
library(rpicosat)
res <- picosat_sat(formula)
res
```
Every result is also a `data.frame` so you can process the results with packages like `dplyr`.
```{r}
as.data.frame(res)
```
We can also test for satisfiability if we assume that a certain literal is `TRUE` or `FALSE`
```{r}
picosat_sat(formula, c(1)) # assume A is TRUE
```
```{r}
picosat_sat(formula, c(1, -3)) # assume A is TRUE, but C is FALSE
```
## License
This R package is licensed under MIT. The PicoSAT solver bundled in this package is licensed MIT as well: Copyright (c) Armin Biere, Johannes Kepler University.
## Other packages
There are [numerous other packages](https://github.com/search?utf8=✓&q=picosat) providing bindings to PicoSAT. After writing this package I discovered [another package](https://github.com/dtimes6/Rpicosat) on github providing bindings to PicoSAT in R.
## Tests
```{r}
covr::package_coverage()
```