I struggled a bit with that task. But I want to know, how I can detect if there is an even cycle in a directed graph using answer set programming with clingo. If there is an even cycle, the program should return satisfiable, if there is no even cycle then unsatisfiable.
vertexes are coded as vt(x)
, and edges as edge(x,y)
.
Example 1: vt(a), vt(b), vt(c), vt(d)
with edge(a,b), edge(b,c), edge(c,a)
should return unsatisfiable.
Here we have one odd cycle with a,b,c
.
Example 2: vt(a), vt(b), vt(c), vt(d)
with edge(a,b), edge(b,c), edge(c,a), edge(a,d), edge(d,a)
should return satisfiable.
Here we have one odd cycle a,b,c
and one even cycle a,d
.
I tried using a reachable/3
predicate where the third component is a counter which counts the current length of the path. Then check if the number is even, though it doesnt work properly.