The maximum clique problem - branch and bound

Problem Description:

  Given an undirected graph G = ( V E ), where V is a non-empty set, called the set of vertices ;

  E is a V unordered collection of elements constituting the tuple is referred to as the set of edges , undirected graph edges are unordered pairs of vertices Disorder "()" indicates common parentheses.

  If U V , and for any two vertices U , V U there is ( U V ) ∈ E , called U is G in complete subgraph .

  G complete subgraph of U is G groups if and only if U is not included in G larger holons in FIG. G is the largest group refers G up to the number of vertices contained within the groups.

  If U ∈ V, and for any U , V U there is ( U V ) ∈E, called U is G the blank of FIG . G blank of FIG U is G independently set if and only if U is not included in G larger blank of FIG. G maximum independent set is G up to the number of vertices contained in an independent set.

  For any undirected graph G = ( V E ), which complement graph G '= ( V ',  E ') is defined as: V ' = V , and ( U V ) ∈ E 'if and only if ( U v ) ∈ E .

  If U is G complete subgraph, then it is also G 'of FIG empty, and vice versa. Thus, G is the group G exists one relationship between 'the independent set. Specially, U is G largest group if and only if U is G 'maximum independent set .


Problem Definition:

  Solution space tree node type: bbnode

  Priority slipknot point queue element type CliqueNode (cn represents a fixed point corresponding to the node group, un denotes the maximum upper bound of vertex .level sub tree rooted tree node represents a subset of nodes in the namespace tree in which the hierarchy; CH left son node tag)

  ch = 1 ch = 0 son left his son the right

  solution space ptr pointer to the corresponding node in the tree

  cn + n-level + 1 represents the number of points on a given boundary value un.

Code Description:

Related structure is defined:

class bbnode{
    friend class Clique;
private:
    bbnode * parent;
    bool LChild;
};
class CliqueNode{
    friend class Clique;
public:
    operator int () const {return un;}
private:
    int cn,
        un,
        level;
    bbnode *ptr;
};
class Clique{
    friend void main(void);
public:
    int BBMaxClique(int []);
private:
    void AddLiveNode(MaxHeap<CliqueNode> &H,int cn,int un,int level,bbnode E[],bool ch);
    int * * a ,n;
};

AddLiveNode: the current configuration of the slipknot is added to a subset of spatial points tree and the insertion point slipknot priority queue.

void Clique::AddLiveNode(MaxHeap<CliqueNode> &H,int cn,int un,int level,bbnode E[],bool ch)
{
    bbnode * b = new bbnode;
    b->parent = E;
    b->LChild = ch;
    CliqueNode N;
    N.cn = cn;
    N.level = level;
    N.un = un;
    N.Insert(N);
}

Algorithm core code: BBMaxClique

Subset of the tree root node is the initial extension node cn 0      

i represents the current level at which the extended solution space node tree.

 

First visit left his son:

  Add this vertex group, check the current vertex and the other vertex, if there are groups attached to side.

  Both sides feasible, into priority queues slipknot point, AddLiveNode (), then examine the current node extended right son node, only when un> bestn, the right subtree may contain optimal solution;

  Otherwise, not feasible.

int Clique::BBMaxClique(int bestx[])
{
    MaxHeap<CliqueNode> H(1000);
    bbnode * E = 0;
    int i=1,
        cn = 0,
        bestn = 0;
    while(i != n+1)
    {
        bool OK = true;
        bbnode * B = E;
        for(int j = i-1;j>0;B=B->parent,j--)
        {
            if(B->LChild && a[i][j]==0)
            {
                OK = false;
                break;
            }
        }
        if(OK)
        {
            if(cn + 1 > bestn)
                bestn = cn + 1;
            AddLiveNode(H,cn+1,cn+n-i+1,i+1,E,true);
        }
        if(cn+n-i >= bestn)
            AddLiveNode(H,cn+1,cn+n-i+1,i+1,E,true);
        CliqueNode N;
        H.DeleteMax(N);
        E = N.ptr;
        cn = N.cn;
        i = N.level;
    }
    for(int j=n;j>0;j--)
    {
        bestx[j] = E->LChild;
        E = E->parent;
    }
    return bestn;
}

Reproduced in: https: //my.oschina.net/u/204616/blog/545329

Guess you like

Origin blog.csdn.net/weixin_34320159/article/details/91990172