clingo_elixir

Native Clingo builds Run in Livebook

An Elixir NIF for clingo. Write ASP and get copied Elixir models back.

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.

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:

{:clingo_elixir, "~> 0.1.0"}

Requires Elixir 1.20 and 64-bit Erlang/OTP 29 or newer. Mix downloads the clingo 5.8.3 runtime for Linux (x86-64 and ARM64), macOS (Intel and Apple Silicon) and Windows (x86-64). See MULTIPLATFORM.md to build your own bundle.

Livebooks

Use the Run in Livebook badge to open the course index. The beginner route builds a room reservation model through facts, negation, and choices. The standalone timetable project 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

Licensed under MIT. Vendored material retains its original licenses.