转自:https://blog.csdn.net/golden1314521/article/details/51470999/
几种问题及其关系
首先解释一下什么是NP问题,什么是NP hard问题,什么是NP完全问题。
- P Problem:这个应该最易理解,就是一个问题可以在Polynominal的时间的得到解决,当然,是对于任意input size。
- NP Problem:对于一类问题,我们可能没有一个已知的快速的方法得到问题的答案,但是如果给我们一个candidate answer,我们能够在polynominal的时间内验证这个candidate answer到底是不是我们已知问题的答案,这类问题叫做NP problem。所以很显然 P Problem是NP problem的一个子集。
- NP-hard Problem:对于这一类问题,用一句话概括他们的特征就是“at least as hard as the hardest problems in NP Problem”, 就是NP-hard问题至少和NP问题一样难。
- NP-Complete Problem:对于这一类问题,他们满足两个性质,一个就是在polynomial时间内可以验证一个candidate answer是不是真正的解,另一个性质就是我们可以把任何一个NP问题在polynomial的时间内把他的input转化,使之成为一个NP-complete问题(即规约)。NP-Complete Problem问题可以互相转换 (在多项式时间内),只要其中一个问题可以在多项式时间内解决,那么其他问题也都将可以在多项式时间内解决。
规约——一种技巧
归约(reduction): 规约是证明NP-hard问题的一种常用方法,通常用P<=Q,这个就表示P is reducible to Q , or Q is the reduction from P or P is reduced to Q(P问题可以归约到Q问题,or可以把P归约到Q) 。这里的reduction的符号可以当成是 比较难易程度的小于等于号,意味着P至少比Q容易,或者Q至少比P难。
归约主要做的就是以下两个转化(注意两个转化都要在polynomial的时间内完成)【已知Q 亦是NP-hard问题】,
1. 把P的输入转化到Q的输入;
2. 把Q的输出转化到P的输出。
下图展示了上述规约过程。其中
如何对问题证明
下面来列出了一些常见的证明问题及其证明套路。
- 证明NP问题。这个容易,即给你一个结果,你能在polynomial的时间内验证该结果的正确性。
- 证明NP-hard问题。我们要证明一个问题是NP-hard的时候,我们通常要做的是找到一个已被证明了的NPC问题,并把这个NPC问题归约到该问题上去(即NPC<=NP-hard)。
-
证明NP-Complete问题。分以下两步:
- 第一步证明这个问题属于NP;
- 第二步,证明这个问题是NP-hard的。
下图列出了几个已被发现NP-Complete问题(更全面的NP-Complete问题列表,见链接A compendium of NP optimization problems,以及List of NP-complete problems),及其规约关系。可以看出所有的NP问题都可以规约到SAT(即NP<=SAT),也就是说SAT至少与NP问题一样难,或者如果解决了3SAT问题,所有的NP问题就解决了。同样的,SAT<=3SAT,3SAT<=Independent Set,Independent Set<=Vertex Cover OR Clique。
规约关系具有传递性,所以有3SAT<=Vertex Cover,NP<=NP-Complete。 事实上,由于NP-Complete
NP-Complete间的规约例子
1. 3SAT<=Independent Set
-
在图G中若顶点集合S满足其中的任意两个顶点之间不存在边,则称S为独立集。The input of Independent Set is a graph m的独立集).
-
转化过程:Given an instance 3SAT problem with (G,m) of Independent Set as follows:
- Graph G has a triangle(edge or vertex) for each clause, with vertices labeled by the clause’s literals
- Add edge between any two vertices that represent opposite literals.
- The goal g is set to the number of clauses.
The graph below corresponding to - 假设上图有一个最大独立集,则每个三角形中有且仅有一个顶点在该独立集中,设该顶点取值为1,其余顶点取值0,则其肯定是一个满足的3SAT的赋值。
-
容易证明该规约过程用了多项式时间。
- 把P的输入转化到Q的输入:P的输入是包含g=m。
- 把Q的输出转化到P的输出:Q的输出是x¯=1. 则该赋值是满足的。
2. 3SAT <= Vertex Cover
- 图的顶点覆盖(有时是节点覆盖)是一组顶点的集合,使得图的每个边缘至少与集合中的一个顶点相连接。在这里Vertex Cover问题是给定图g的点覆盖。(我们常说的最小顶点覆盖的问题称为顶点覆盖问题,毫无疑问,它也是一个NP-Complete问题)。
-
转化过程:
- 按照如下方法构造Graph,对应每一个变量C连起来。
- 下面的graph对应于
- 若上图存在最小点覆盖,则将二元点对中在该最小点覆盖中的那一个赋值为1。则该赋值就是一个满足3-SAT的赋值。
-
假设有n+3m+3m个边。显然可以在多项式时间完成该转换。
- 把P的输入转化到Q的输入:P的输入是包含g=2m+n。
- 把Q的输出转化到P的输出:Q的输出是xi=0。
3. 3SAT <= ILP
- ILP就是Integer Linear Programming,即所有变量都要求是整数。
-
转化过程:
- 对于 每个clause,我们都对应于ILP中的一个constraint,比如 3SAT中有4个变量,1.
- 3SAT问题(x1∨x¯2∨x¯3)∧(x1∨x2∨x4)对应的ILP如下:
{x1+(1−x2)+(1−x3)=1x1+x2+x4=1
- 至于input/output的转换,就如转换过程的描述,异常简单。在此不再叙述。
4. 3SAT <= Hamiltonian cycle problem
-
转化过程:
- 对每个变量x¯i=1,则形成从右向左的一个路径。
- 对每个(vi,1,vi+1,1),(vi,3m+3,vi+1,3m+3),(vi,1,vi+1,3m+3),(vi,3m+3,vi+1,1)。
- 添加两个节点(t,s)。这时得到的图中有 hamiltonian cycle,其中一个如下图的虚线所示。
- 对于每一个clause
- 若图xi=0。则该赋值肯定是3SAT可满足的。
- 该转化过程要创建(3m+2)×2×n+4(n−1)+5+2m个边,是多项式时间的。
- 把P的输入转化到Q的输入:P的输入是包含G。
- 把Q的输出转化到P的输出:Q的输出是G的一个Hamiltonian cycle;P的输出是3SAT的一个赋值。
5. Subset sum problem <= Partition problem
- 问题描述:
- Subset sum problem:given a set (or multiset) of integers k。
- Partition problem: partition problem (or number partitioning) is the task of deciding whether a given multiset W2.
-
转化过程:
- 给定一个子集和的实例为W,即
W={T,2A−k,A+k}.∑w∈Ww=4A。
- 假设找到了W2,则有
∑w∈W1w=∑w∈W2w=2A。2A−k所在的子集的其它元素就是一个满足子集和问题的子集。
- 给定一个子集和的实例为W,即
-
把P的输入转化到Q的输入:P的输入是集合W={T,2A−k,A+k}.
- 把Q的输出转化到P的输出:Q的输出是2A−k所在的子集的其它元素集合。
6. Clique problem<=Subgraph isomorphism problem
- 问题描述
- Clique problem:给定一个图k的团。
- Subgraph isomorphism problem:给定两个图G2同构。
- 转换过程:
- 令k个顶点的完全图(即团)。
- 如果子图同构问题的答案是肯定的,那么枚举Cnk。
- 把P的输入转化到Q的输入:P的输入是图G2。
- 把Q的输出转化到P的输出:Q的输出是Yes/No;P的输出是G的一个团。
7. Partition problem <= Knapsack problem
- 问题描述:
- Partition problem: partition problem (or number partitioning) is the task of deciding whether a given multiset W2, i.e.
∑t∈W1t=∑t∈W2t=∑t∈Wt2.
- Knapsack problem:Given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible. 给定一个物品集合U′⊂U使得
∑u∈U′s(u)≤B,∑u∈U′w(u)≥K.
- Partition problem: partition problem (or number partitioning) is the task of deciding whether a given multiset W2, i.e.
- 转化过程:
- For each B,K添加如下条件
B=K=∑u∈Uu2,那么有∑u∈U′s(u)=∑u∈U′w(u)=∑u∈Uu2。
- For each B,K添加如下条件
8. Vertex Cover <=Independent Set
- 问题描述:
- Vertex Cover:给定一个图k的点覆盖。
- Independent Set:给定一个图k的独立集。
- 转化过程:
- 把参数为|V|−k的独立集问题。
- 若k的点覆盖。
- 把P的输入转化到Q的输入:P的输入是图|V|−k;
- 把Q的输出转化到P的输出:Q的输出是V−S′.
9. Independent Set <= Clique problem
- 问题描述:
- Independent Set:给定一个图k的独立集。
- Clique problem:给定一个图k的团。
- 转化过程:
- 把k的团问题。
- 如果找到补图k的独立集。
- 把P的输入转化到Q的输入:P的输入是图k;
- 把Q的输出转化到P的输出:Q的输出是补图V−S′.
10. Hamiltonian cycle problem <= Hamiltonian path problem
- 问题描述:
- Hamiltonian cycle problem:a graph cycle (i.e., closed loop) through a graph that visits each node exactly once
- Hamiltonian path problem: a graph path between two vertices of a graph that visits each vertex exactly once.
- 转化过程:
- 在原图G′。如上图所示。
- 假设新图G的Hamiltonian cycle。
11. Hamiltonian cycle problem <= Traveling salesman problem
- 问题描述:
- Hamiltonian cycle problem:a graph cycle (i.e., closed loop) through a graph G=(V,E) that visits each node exactly once。
- Traveling salesman problem: 即给定一个带权图k的回路。
- 转化过程:如何得到k
- V’=V,k=0..
- E’为完全图的边。还要定义边的权重:
w(u,v)={0,if(u,v)∈E1,if(u,v)∉E
- 如果G的一个Hamiltonian cycle problem。
参考资料
- 关于P,NP,NPC等问题
- 澄清P问题、NP问题、NPC问题的概念
http://www.matrix67.com/blog/archives/105 - 完備 (複雜度)
http://zh.wikipedia.org/wiki/%E5%AE%8C%E5%82%99_(%E8%A4%87%E9%9B%9C%E5%BA%A6) - P/NP/NPC/NP-hard
http://ccckmit.github.io/ct/htm/book.html - Cook-Levin理論
http://zh.wikipedia.org/wiki/Cook-Levin%E7%90%86%E8%AB%96
提到了两篇论文 - A Sample Proof of NP-Completeness
http://cgm.cs.mcgill.ca/~athens/cs507/Projects/2001/CW/npproof.html - 算法导论自学笔记
http://blog.csdn.net/xiazdong/article/category/1270511 - Reductions & NP-completeness
https://www.cs.cmu.edu/~ckingsf/bioinfo-lectures/npcomplete.pdf - Reductions Between NPCs
http://mlnotes.com/2013/04/29/npc.html - Lecture Notes on Complexity and NP-completeness 1. Reduc
http://www.cs.berkeley.edu/~vazirani/s99cs170/notes/npc.pdf - Reductions Between NPCs
http://mlnotes.com/2013/04/29/npc.html - Everyday encounters with NP-complete problems
http://cstheory.stackexchange.com/questions/446/everyday-encounters-with-np-complete-problems - NP-hardness of an optimization problem
http://cstheory.stackexchange.com/questions/14787/np-hardness-of-an-optimization-problem?rq=1 - Is the following optimization problem NP-hard?
http://cstheory.stackexchange.com/questions/10615/is-the-following-optimization-problem-np-hard - Is the following optimization problem (a variant to a previous problem) NP-hard?
http://cstheory.stackexchange.com/questions/10727/is-the-following-optimization-problem-a-variant-to-a-previous-problem-np-hard?rq=1 - What are NP-complete problems and why are they so important?
http://math.stackexchange.com/questions/726/what-are-np-complete-problems-and-why-are-they-so-important