蛮力顶点覆盖算法的优化

时间:2016-10-05 03:57:04

标签: c++ algorithm optimization vertex-cover

我正在编写一个强力算法来解决这个顶点覆盖:

BruteForceVertexCover( Graph G = (V,E) ){
    for size= 1 ... |V|
        vector<int> v = {0...size-1}
        do{
            if(test(G, v)) return v;     //test if v covers G
        }
        while(v has next combinations of lenght size);
    return empty vector<int>;
}

//this stops when find a answer, and it will find,
//since it tries all combinations of all sizes

,其中

bool test( Graph G = (V,E), vector<int> v ){
    for each u in v:
        for each w in G[u]
            remove u from G[w]     //this is linear in size of vector G[w]
        clear G[v]                 //removed all (bidirectional) edges that have u
    for i = 0 ... |V|
        if(G[i] is not empty) return false;
        return true;
}

我试着用很多图表(但它们的最大尺寸是20个顶点),这需要十年时间......我可以对这种蛮力进行任何优化,以便它运行得更快吗?

0 个答案:

没有答案