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

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

Awesome Lists containing this project

README

          

---
output:
md_document:
variant: gfm
---

[![R-CMD-check](https://github.com/dirkschumacher/rpicosat/workflows/R-CMD-check/badge.svg)](https://github.com/dirkschumacher/rpicosat/actions)
[![CRAN Status](http://www.r-pkg.org/badges/version/rpicosat)](https://CRAN.R-project.org/package=rpicosat)
[![Codecov test coverage](https://codecov.io/gh/dirkschumacher/rpicosat/branch/master/graph/badge.svg)](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()
```