Reputation: 43
So I came across this problem in my textbook. I was wondering how to develop a reduction from the Graph Reachability problem to SAT (CNF) problem. (i.e. formula is satisfiable iff there exists a path in graph G from start to end node)
1) I can't wrap my head around how to go from something that can be solved in polynomial time (Graph Reachability) to something that is NP (SAT).
2) I can't seem to find a way to formulate these nodes/edges of Graph into actual clauses in CNF that correspond to reachability.
I tried to think about algorithms like Floyd-Warshall that determine if a path exists from start to end node but I can't seem to formulate that idea into actual CNF clauses. Help would be much appreciated!
Upvotes: 2
Views: 1281
Reputation: 59303
It probably wouldn't be too hard to come up with the kind of answer you're expecting, but here's the real answer instead:
"Reducing" a problem X to problem Y means transforming any instance of X to an instance of Y such that the answer to Y provides the answer to X. Usually, we require a P-time reduction, i.e., the transformation of the problem and the extraction of the answer must both happen in polynomial time.
Graph Reachability is easily solved in linear time, which is certainly polynomial time, so the reduction from Graph Reachability to SAT is very simple:
Upvotes: 1
Reputation: 329
With respect to your first question: Since you're only devising a way to reduce a problem in P into a problem in NP (and not the other way around), this isn't actually a problem. You can turn any Graph Reachability problem into a SAT problem, but that doesn't mean you can turn any SAT problem into a Graph Reachability problem.
Upvotes: 0
Reputation: 1707
We did something similar to your task a few years ago. Our approach was based exactly on Floyd-Warshall (F.-W.) algorithm. Intuitively, you would like to something like this:
A bit more formally:
nodes <- get_nodes_from_path(path)
node_lits <- logical_and([n.literal for n in nodes])
path_lit <- get_new_literal()
path_clause <- if_then_else(node_lits, path_lit)
Finally, you could the following:
all_paths <- exactly_one(all_path_clauses)
all_paths <- True
SAT solver would be forced to select one of paths and this would lead to selecting corresponding nodes.
Upvotes: 0