I need to find a Hamiltonian cycle in a directed graph using propositional logic, and to solve it by sat solver. So after I couldn't find a working solution, I found a paper that describes how to construct a CNF formula to find an Hamiltonian path:
Xi,j
- node j is in position i in the path
List of constraints:
- Each node j must appear in the path
x1j ∨ x2j ∨ · · · ∨ xnj
- for every node j - No node j appears twice in the path
¬xij ∨ ¬xkj
for all i, j, k with i 6= k. - Every position i on the path must be occupied -
xi1 ∨ xi2 ∨ · · · ∨ xin
for each i - No two nodes j and k occupy the same position in the path -
¬xij ∨ ¬xik
for all i, j, k with j != k - Nonadjacent nodes i and j cannot be adjacent in the path -
¬xki ∨ ¬xk+1,j
for all (i, j) !∈ E and k = 1, 2, . . . , n − 1.
My question is, how can I find Hamiltonian cycle using these constraints? I understand that I need to check if there's a cycle (v1==vn
), that's one thing (But I got constraint 2). Second, it's a directed graph and I don't know how can I assure that the vertices would be in the right order of the edges, I thought about this:
Every two nodes must have edges - Xki ^ Xk+1j
for each (i,j)∈ E and k = 1, 2, . . . , n − 1.
But it doesn't seem to work, any help would be appreciated.
EDIT
What I did was to add another constraint -
- No edges from the set: (i,j)!∈ E that are the last and the first
Asked By : Dor Cohen
Answered By : D.W.
Just add the constraint that $x_{1j}=x_{nj}$ for all $j$, and make a special exception to constraint 2 so that you omit constraint 2 in the case where $i=1$ and $k=n$.
Everything works fine for a directed graph. You just need to interpret constraint 5 appropriately.
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/49593
0 comments:
Post a Comment
Let us know your responses and feedback