Packages

Scoped Elixir interface and C NIF for clingo 5.8.3

Current section

Files

Jump to
clingo_elixir README.md
Raw

README.md

# clingo_elixir

[![Native Clingo builds](https://github.com/davfuenmayor/clingo_elixir/actions/workflows/native.yml/badge.svg?branch=main)](https://github.com/davfuenmayor/clingo_elixir/actions/workflows/native.yml)
[![Run in Livebook](https://livebook.dev/badge/v1/blue.svg)](https://livebook.dev/run?url=https%3A%2F%2Fgithub.com%2Fdavfuenmayor%2Fclingo_elixir%2Fblob%2Fmain%2Flivebooks%2Fintro.livemd)

An Elixir NIF for [clingo](https://potassco.org/clingo/). Write ASP and get
copied Elixir models back.

```elixir
Clingo.solve!("a. b :- a.").models |> Enum.map(& &1.shown)
# [["a", "b"]]

Clingo.models("{a;b;c}.", models: :all) |> Enum.take(2)
```

Keep a control for incremental solving.

```elixir
alias Clingo.Control

Clingo.with_control(fn control ->
  Control.add!(control, "#external enabled. answer :- enabled.")
  Control.ground!(control)
  Control.assign_external!(control, "enabled", true)
  Control.solve!(control)
end)
```

## Platforms and installation

Add the Hex dependency:

```elixir
{:clingo_elixir, "~> 0.1.0"}
```

Requires Elixir 1.20 and 64-bit Erlang/OTP 29 or newer. Mix downloads the
[clingo 5.8.3](https://github.com/potassco/clingo/releases/tag/v5.8.3) runtime
for Linux (x86-64 and ARM64), macOS (Intel and Apple Silicon) and Windows
(x86-64). See [MULTIPLATFORM.md](MULTIPLATFORM.md) to build your own bundle.

## Livebooks

Use the **Run in Livebook** badge to open the [course index](livebooks/intro.livemd).
The beginner route builds a room reservation model through facts, negation,
and choices. The standalone [timetable project](livebooks/planning/03-course-selection.livemd)
brings grounding and aggregates together to find a clash-free enrollment.
The index also has routes for the Elixir API and solver extensions.

Run Setup in Livebook's Standalone runtime. It installs the Hex dependencies
and downloads the matching solver bundle. The lessons fetch their own input
files when opened by URL.

## API and contributing

- [Elixir API](docs/ELIXIR_API.md) covers solving, callbacks, ASTs, and export.
- [Contributor guide](CONTRIBUTING.md) covers bindings, testing, and ownership.

Licensed under [MIT](LICENSE). Vendored material retains its original licenses.