afsolver
v0.1.1
Published
Lightweight solver for Dung-style argumentation framework semantics (conflict-free, admissible, complete, preferred, grounded, stable extensions)
Downloads
150
Readme
afsolver
A lightweight TypeScript solver for Dung-style abstract argumentation framework (AF) semantics: conflict-free, admissible, complete, preferred, grounded, and stable.
This is the TypeScript sibling of the Python afsolver
package — same algorithms, same test
cases, ported 1:1.
Install
bun add afsolveror with npm/pnpm/yarn:
npm install afsolverQuick start
import { ArgumentationFramework } from "afsolver";
const af = new ArgumentationFramework(
["a", "b", "c"],
[["a", "b"], ["b", "a"], ["c", "b"]], // a<->b mutual attack, c attacks b
);
af.preferred(); // [Set {'a', 'c'}]
af.grounded(); // Set {'a', 'c'}
af.extensions(); // object with all six semantics at onceArguments are optional — if omitted, they're inferred from the attacks
pairs:
const af = new ArgumentationFramework([], [["b", "a"], ["c", "b"], ["d", "c"]]);
af.arguments; // ['b', 'a', 'c', 'd']API
new ArgumentationFramework(arguments = [], attacks = [])
| Method | Returns |
|---|---|
| .conflictFree() | ReadonlySet<string>[] — conflict-free sets |
| .admissible() | ReadonlySet<string>[] — admissible sets |
| .complete() | ReadonlySet<string>[] — complete extensions |
| .preferred(contains?) | ReadonlySet<string>[] — preferred (maximal admissible) extensions, optionally restricted to those containing all arguments in contains |
| .grounded() | ReadonlySet<string> — the (unique) grounded extension |
| .stable() | ReadonlySet<string>[] — stable extensions |
| .minimalAdmissible(contains?) | ReadonlySet<string>[] — non-empty admissible sets minimal by set inclusion, optionally restricted to those containing all arguments in contains |
| .extension(name) | dispatch to any of the six semantics above by string name |
| .extensions() | object with all six semantics computed at once |
preferred
With no contains argument, returns all preferred extensions. Pass
contains to restrict the result to only those that include a given
argument (or set of arguments):
const af = new ArgumentationFramework(
["a", "b", "c", "d", "e"],
[["b", "a"], ["c", "b"], ["d", "b"], ["c", "e"], ["e", "c"]],
);
af.preferred(); // [{'a', 'c', 'd'}, {'a', 'd', 'e'}]
af.preferred(["a", "c"]); // [{'a', 'c', 'd'}]minimalAdmissible
With no contains argument, returns the smallest non-trivial admissible
sets overall. Pass contains to restrict the result to the smallest
admissible sets that include a given argument (or set of arguments):
const af = new ArgumentationFramework(
["a", "b", "c", "d", "e"],
[["b", "a"], ["c", "b"], ["d", "b"], ["c", "e"], ["e", "c"]],
);
af.minimalAdmissible(); // [{'c'}, {'d'}, {'e'}]
af.minimalAdmissible(["a"]); // [{'a', 'c'}, {'a', 'd'}]The empty set is always excluded — it's trivially admissible and a subset of everything else, so including it would hide the smallest non-trivial results.
Development
bun install # install dependencies
bun test # run tests
bun run typecheck # tsc --noEmit
bun run build # emit dist/ (esm + .d.ts)