Problem Description:
Given a weighted graph g= (v,e), each vertex v∈v has a weight of W (V). If the Uvs and any (u,v) ∈e have u∈u or v∈u, you are called U as a vertex overlay of Figure G. The minimum weight vertex overlay of g is the minimum vertex coverage of the vertex weights contained in G.
Problem solving:
In this paper, we use the Priority Queue Branch-bound method to solve the minimum weight vertex cover, save the Partial solution space tree which is currently constructed in the process of searching the algorithm, and save the optimal solution of the optimal value when the algorithm search reaches the leaf node. Priority queue priority is the weighted value of each live node, and the active node with the smallest weight becomes the next extension node.
<1>, algorithm ideas:
The algorithm BBVC the optimal value and the optimal solution of the minimum weight vertex coverage, and the algorithm cover determines whether the vertex is completely covered in the graph, and the algorithm Addlivenode adds the resulting child node to the smallest heap of the active node priority queue, and the algorithm mincover returns the optimal value and the optimal solution of the minimum weight vertex coverage.
<2> Algorithm Program:
#include <iostream> #include <fstream> #include "MinHeap.h" using namespace std; Minimum heap node class Heapnode//Heap node classes; {friend class dealnode; public:operator int () const{r
Eturn cn;} Private:int I,//i indicates the node number in the heap CN,//CN indicates the current added cover top The sum of the weights in the points *x, the//x array indicates those vertices are added to the row of the overlay vertices *c;
The C array identifies all adjacent vertices in the overlay vertex in X};
The VC class is used to operate on the inside of the node in the heap class Dealnode {friend mincover (int **,int [],int);
Private:void BBVC ();
BOOL Cover (Heapnode E);
void Addlivenode (minheap
Where the smallest heap code MinHeap.h
Template <class type> class Minheap//Minimum heap class; {public: Minheap (Type a[], int n); A constructor with two parameters, not applied in this program; minheap (int ms); constructor overloads, which initialize only the size of the heap, do not initialize the nodes in the heap, and the storage of the heap elements is in the array ~minheap (); form, and no parent, child pointer, access to the Father node, using the array designator; bool Insert (const Type &x); Inserts an element in the heap; bool Removemin (Type &x); Delete top minimum node of heap; void Makeempty ();
Make the heap empty bool IsEmpty ();
BOOL Isfull ();
int Size (); Protected:void filterdown (const int start, const int endofheap); Top-down construction heap void Filterup (const int start);
Bottom-up construction heap private:type *heap;
int maxSize;
const int defaultsize; int currentsize;
Heap current node number size}; Template <class type> minheap<type>::minheap (intms):d Efaultsize {maxSize = (ms>defaultsize)? ms:defaultsize;
Heap=new Type[maxsize];
currentsize=0; } template <class type> minheap<type>::minheap (Type a[], int n):d efaultsize (+) {maxSize = (n>defaul tsize)?
N:defaultsize;
Heap=new Type[maxsize];
Currentsize=n;
for (int i=0; i<n; i++) heap[i]=a[i];
int curpos= (currentSize-2)/2;
while (curpos>=0) {Filterdown (CurPos, currentSize-1);
curpos--;
}} template <class type> minheap<type>::~minheap () {delete []heap; } template <class type> void minheap<type>::filterdown (const int start, const int endofheap) {int I=star
T, j=i*2+1;
Type Temp=heap[i];
while (J<=ENDOFHEAP) {if (j<endofheap&&heap[j]>heap[j+1]) j + +;
if (Temp