Powered by AppSignal & Oban Pro

Loge: DIMACS smoke test

notebooks/dimacs.livemd

Loge: DIMACS smoke test

root = Path.expand("..", __DIR__)

Mix.install([
  {:loge, path: Path.join(root, "loge"), override: true},
  {:loge_dimacs, path: Path.join(root, "loge_dimacs")},
  {:kino_loge, path: Path.join(root, "kino_loge")}
])

Solving

Expected: Satisfiable, one model, 1 -2 3.

Loge.run!(Loge.Dimacs.Engines.Clasp, "c x1, not x2, x2 or x3\np cnf 3 3\n1 0\n-2 0\n2 3 0\n",
  models: 1,
  time_limit: 10
)

Models 0 enumerates all of them. Expected: Satisfiable, three models.

Loge.run!(Loge.Dimacs.Engines.Clasp, "p cnf 2 1\n1 2 0\n", models: 0, time_limit: 10)

Expected: Unsatisfiable, no models.

Loge.run!(Loge.Dimacs.Engines.Clasp, "p cnf 1 2\n1 0\n-1 0\n", models: 1, time_limit: 10)

Other SAT solvers

CaDiCaL and Kissat run as executables found on PATH (nixpkgs: cadical, kissat), or named in the Logic Engine Settings cell. Expected: Satisfiable, one model, 1 -2 3; without the executable, an error naming it.

Loge.run!(Loge.Dimacs.Engines.Cadical, "c x1, not x2, x2 or x3\np cnf 3 3\n1 0\n-2 0\n2 3 0\n",
  time_limit: 10
)
Loge.run!(Loge.Dimacs.Engines.Kissat, "c x1, not x2, x2 or x3\np cnf 3 3\n1 0\n-2 0\n2 3 0\n",
  time_limit: 10
)

MaxSAT

A WCNF source, here in the format without a problem line, and clasp, which searches until the model is optimal. Expected: Satisfiable, optimum found, cost 2, the last model 1 -2.

Loge.run!(
  Loge.Dimacs.Engines.ClaspMaxsat,
  "c exactly one of x1 and x2; x1 is worth 3, x2 is worth 2\nh 1 2 0\nh -1 -2 0\n3 1 0\n2 2 0\n",
  time_limit: 10
)

QBF

A QDIMACS source and DepQBF, found on PATH or named in the settings (not in nixpkgs). Expected: Satisfiable (the formula is true), the partial certificate 1.

Loge.run!(
  Loge.Dimacs.Engines.Depqbf,
  "c exists x1, for all x2, exists x3: x1, x2 or x3, not both x2 and x3\np cnf 3 3\ne 1 0\na 2 0\ne 3 0\n1 0\n2 3 0\n-2 -3 0\n",
  time_limit: 10
)

Expected: Unsatisfiable (false), the partial certificate -1: the value of the universal x1 for which no x2 works.

Loge.run!(
  Loge.Dimacs.Engines.Depqbf,
  "c for all x1, exists x2: x2 <-> x1, and x1 or x2\np cnf 2 3\na 1 0\ne 2 0\n-1 2 0\n1 -2 0\n1 2 0\n",
  time_limit: 10
)

Linting

Expected: under the editor, variable 4 exceeds the header and the clause count differs from it; evaluating raises Loge.Error with both findings.

Loge.run!(Loge.Dimacs.Engines.Clasp, "p cnf 3 3\n1 -4 0\n2 0\n", models: 1, time_limit: 10)

Expected: under the editor, the innermost quantifier set is universal, which QDIMACS does not allow.

Loge.run!(Loge.Dimacs.Engines.Depqbf, "p cnf 2 1\ne 1 0\na 2 0\n1 2 0\n", time_limit: 10)