1.3.4 two-point coverage

xiaoxiao2021-03-06  76

The two-point diagram is a non-map drawing, which can be two points to set a and set B, and any two vertices in the same episode are boundless in the figure (ie, any one is a vertex in the collection A, The other is in the collection B). When and only when each of B is connected to one vertex in A, a subset A 'covers the set B (or briefly, A' is an overlay). The size of the A 'is the number of vertices in A'. When it is only when A 'is the smallest in the subset of coverage B, A' is covered.

Examples 1-10 Examples of Figure 1 - 6 showing two-point diagram of 1 7 top points, a = {1, 2, 3, 16, 17} and b = {4, 5, 6, 7, 8, 9 , 10, 11, 12, 13, 14, 15}, subset A '= {1, 1 6, 1 7} is the smallest cover of B. Looking for the smallest coverage in the two-point diagram, the problem is two-point coverage (B I p A R t I t e - C O V E R) problem. The smallest coverage is useful in Example 1 2 - 3, as it can solve the problem of "translation in the conference" to translate "".

Different coverage problems are similar to the assembly coverage (S E T - C O V E R). The elements of K collections s = {S1, S2,., SK} are given in the collection coverage problem, and the elements in each collection Si are members of the Complete Works. When and only when èi s'si = u, the number of sets of S 'covers U, S' is overwritten. When and only when there is no smaller collection that can override u, it is called the minimum coverage. The set coverage problem can be converted to a two-point coverage (vice versa), that is, the vertex of S1, SK, B is representing the element in the U. When and only when the corresponding set of the S is included, there is a side between the vertices of A and B.

Example 1 - 11 Let S = {S1 ,.., S5}, u = {4, 5 ,.., 15}, S1 = {4, 6, 7, 8, 9, 1 3}, S2 = {4, 5, 6, 8}, s3 = {8, 1 0, 1 2, 1 4, 1 5}, S4 = {5, 6, 8, 1 2, 1 4, 1 5}, S5 = { 4, 9, 1 0, 11}. S '= {S1, S4, S5} is a coverage of 3, no smaller coverage, S' is minimum coverage. This set coverage can be mapped to two-fold diagram of Figures 1-6, ie, the vertices 1, 2, 3, 1 6, and 1 7 respectively indicate the set S1, S2, S3, S4 and S5, and the vertex j represents the elements in the collection. 4 ≤ j ≤ 1 5.

The collection coverage problem is N p-complex problems. Since the collection coverage and the binary coverage are the same problem, the two-point coverage is also N p-complex issues. It may not be possible to find a fast algorithm to solve it, but can use greedy algorithms to find a fast heuristic method. One may be step-by-step establishment override A ', each step of selecting a vertex to add overwritten. The choice of vertex utilizes greed guidelines: The number of elements that have not been overwritten in B is mostly overwritten from A. Example 1-12 Investigating the diagram shown in Figure 1 - 6, initializing A '= and there is no vertices in B, vertices 1 and 1 6 can cover six vertices in B, vertex 3 cover five, vertex 2 And 1 7 is covered separately. Therefore, the vertex 1 or 1 6 is added in the first step to A '. If the vertex 1 6 is added, it covers the vertex to {5, 6, 8, 1 2, 1 4, 1 5}, unclociated vertices. To {4, 7, 9, 1 0, 11, 1 3}. The vertex 1 covers four vertices ({4, 7, 9, 1 3}), the vertex 2 covers one ({4}), the vertex 3 covers one ({1 0}), the vertex 1 6 cover zero, vertex 1 7 covers four {4, 9, 1 0, 11}. Next, 1 or 1 7 can be selected to add A '. If the vertex {1 0, 11} is still not overwritten, at this time, the vertices 1, 2, 1 6 do not overwrite any one, the vertex 3 covers one, and the vertex 1 7 covers two, so select the vertex 1 7 At that, all vertices have been covered, and A '= {1 6, 1, 1 7}.

Figure 1 - 7 gives the pseudo code for greed to cover the heuristic method, which can prove: 1) When and only when the initial two-point diagram is not covered, the algorithm cannot be covered; 2) Heuristic method may not find two-point map Minimum coverage.

1. Selection and complexity analysis of data structure

To implement algorithms of Fig. 13-7, the description method of the A 'is required and how to record the number of unclociated nodes in B can be covered by the node. Since only adding operations are used for collection A ', a one can be used to describe A', and the number of elements in A 'is recorded by m. Record the members in A 'in C [0: M-1]. For the top point I, the NE WI is the number of vertices that the N e wi is the b-that I can overwrite. Gradually select the maximum vertex of N e wi value. Since some of the original unclociated vertices are now overwritten, they also modify each N e wi value. In this update, the vertices that are covered by V is checked in B, which is a vertex for such a vertex, and the N e wi values ​​of all the vertices of the over-covered J of A are 1.

Example 1-13 Investigating Figure 1 - 6, initial (N e W1, N e W2, N e W3, N e W16, N e W17) = (6, 4, 5, 6, 4). Assuming in Example 1 - 1 2, the first step is selected to select the vertex 1 6. In order to update the value of N e Wi, all recently covered vertices in B, these vertices are 5, 6, 8, 1 2, 1 4 and 1. 5. When the vertex 5 is checked, the N e wi values ​​of the vertices 2 and 1 6 are reduced separately, because the vertex 5 is no longer covered nodes covered by vertices 2 and 1 6; when checking the vertex 6, vertices 1, 2, The corresponding value of 1 6 is reduced by 1; Similarly, check the vertex 8, 1, 2, 3 and 1 6 is reduced by 1; when all recently covered vertices, the N e wi value obtained is (4 1, 0, 4). Next selection vertex 1, the latest top points are 4, 7, 9, and 1 3; check the vertex 4, n e w1, n e w2, and N e w1 7 value minus 1; check the vertex 7, N The value of e w1 is reduced because the vertex 1 is the only vertex covering 7. In order to implement the process of the vertex, you need to know the value of N e Wi and the vertices that have been overwritten. A two-dimensional array can be used to achieve this, N e w is an integer array, and new [i] is equal to N e Wi, and C O V is a Boolean array. If the vertex I is not covered, C O V [I] is equal to F a L s E, otherwise C O V [I] is T R u e. The pseudo code of Figures 1-7 will now be refined to give Figure 1-8.

m = 0; // Currently covered size

All I, New [I] = Degree [i]

For all I, C O V [I] = f a L S e in B

While (some I, new [i]> 0 in A) {

Set V is a vertex with the largest N e w [i];

C [M ] = V;

FOR (all adjacent to V. J) {

IF (! COV [J]) {

CoV [J] = True;

For all the vertices adjacent to J, it makes it n e w [k] minus 1

}}}

IF (some vertices are not covered) failed

Else finds an overlay

Figure 1-8 Refining of Figure 1-7

The time to update N e w is O (e), where e is the number of edges in the two-point diagram. If the adjacency matrix is ​​used, the time required to flow (N2) is needed to look for the edges in the figure, if the adjacent link table, the time (N E) is required. The actual update time is O (N2) or O (N E) according to the description method. The time required to gradually select the vertex is (S i z e o f A), where S I z e o f A = | A |. Because all of A is likely to be selected, the number of steps required is O (S Ize O F a), the total complexity of the overlay algorithm is O (S Ize O f A 2 N2) = O (N2) or O (s Ize of A2 N E).

2. Reduce complexity

The complexity of each step V is reduced to (1) by using an ordered array n e Wi, a max selection tree. However, with an ordered array, the N e Wi value is reordered at the end of each step. If the box sort is used, the time required for this order is (S I z E O FB = | B |) (see 3. 8. 1 box sort). Since the general S i z E O F b is much larger than S I z E O F A, the ordered array does not always improve performance. If you use the maximum pile, you need to reconstruct the stack to record the change of the N e w value, and can be rebuilt at each N e w value. This subtraction operation can cause up to the N E value to move up to one layer in the heap, so this reconstruction has a total reduction of 1 (1) for each N EW value, the total amount of reduction is O (e ). Therefore, in all the steps of the algorithm, the maximum heap is maintained for only O (E), and thus the total complexity of the overlay algorithm is O (N2) or O (N E) using the maximum heap.

If you use the maximum selection tree, you need to rebuild the Select tree each time you update the N e w, the required time is (LOG S I z e o f A). The best time to rebuild is at the end of each step, not when the NEW value is reduced each time, the number of times of reconstruction is O (E), so the total reconstruction time is O (E Log S Ize OFA), this Time is longer than the reconstruction time of the largest heap. However, by maintaining a vertex box having the same N e w value, the same time limit can be obtained and utilized when the maximum stack is used. Since N e w is ranging from 0 to S i z e o f b, S i z e o f B 1 box is required, and the box i is a two-way linked list, and the link all N e w value is the vertex of I. At the end of a certain step, if N e w [6] changes from 1 2 to 4, it is necessary to move it from the first 2 boxes to the fourth box. Using the analog pointer and a node array Node (where Node [i] represents vertex I, Node [i]. Left and node [i]. Right is a two-way linked list pointer), can move the vertex 6 from the first 2 boxes to the first 4 boxes, remove Node [0] from the first 2 boxes and insert them into the fourth box. With this box pattern, the complexity of the heuristic algorithm can be covered with O (N2) or O (N E). (The diagram depending on the use of the adjacency matrix or linear table).

3. DETATIVE

In order to achieve the above two-way link box, Figure 1 - 9 defines the private member of the class U N D I R E C T E D. N o D e TY PE is a class with private integer members L E f T and R I g H t, which is a bidirectional chain table node, and the program 1 3-3 gives the code of the private member of U N D i R e c T E D.

Void Createbins (int B, int N)

Create b empty boxes and n nodes

Void destroybins () {delete [] node;

DELETE [] bin;

Void Insertbins (int B, int V)

Add a vertection in the box B v

Void Movebins (int Bmax, int Tobin, int V)

Move vertices from current box v to box to b i n

Int * bin;

B i n [i] points to the first patch representative of the two-way linked list of the box

N o d e Type * node;

N o d e [i] represents the node of the storage vertend point i

Figure 1-9 U N D i R E C TEE DID required for a two-way linked box

Program 13-3 definition of box function

Void undirected :: Createbins (int b, int n) {// Create b empty box and n nodes

Node = new nodetype [n 1];

BIN = New Int [B 1];

// Set the box

For (INT i = 1; i <= b; i )

BIN [I] = 0;

}

Void undirected :: INSERTBINS (int B, int V)

{// If b is not 0, insert V into B. B

IF (! b) return; // b is 0, not inserted

Node [v] .left = b; // Add on the left

IF (bin [b]) node [bin [b]]. Left = v;

Node [v] .right = bin [b];

BIN [B] = V;

}

Void Undirected :: Movebins (int Bmax, int tobin, int v)

{/ Move the vertex V from its current homing to TO B I n.

// v left, right node

INT L = NODE [V] .left;

INT R = Node [V] .right;

// Remove from the current box

IF (r) node [r] .left = node [v] .left;

IF (l> bmax || bin [l]! = v) // is not the left node

Node [l] .right = r;

Else Bin [l] = r; / / The leftmost side of the box L

// Add to Box to B I N

I N S E R T B I N S (Tobin, V);

}

Function C R E A T E B I N S Dynamically assigned two arrays: N O D E and B I n, N O D E [i] indicates vertex I, BIN [i] points to the vertices of the two-way linked list of its N e w value I, and the F O R loop will set all the bidirectional linkers empty. If b ≠ 0, the function INSERTBINS is inserted into the box B. Because B is the NEW value of the vertex V, b = 0 means that the vertex V cannot override any vertices that have not been overwritten in B. Therefore, this box is not useful at the time of establishing coverage, so you can wipe it. When b ≠ 0, the vertex n is added to the top of the two-way linked list box of the New value B, which needs to add Node [V] to the left of the first node in bin [b]. Since the left node of the table should point to the box to which it belongs, it is set to B. If the box is not empty, the LEFT pointer of the current first node is set to a new node. The right pointer of Node [V] is set to B i n [b], which may be 0 or pointing to a pointer to a first node. Finally, B i n [b] is updated to a new first node in the table. Movebins move the vertex V from its current position in the two-way linked list to the NEW value of Tobin. There is a BMA x such that all box B i n [j] is: such as j> BMA X, then B i n [j] is empty. The code first determines the left and right nodes in the current bidirectional linked list, followed by N O D E [V] from the double-linked list, and re-inserts it to B i n [to B i n] using the I n S E R t b i n s function.

4. Undirected :: BipartiteCover

The input parameter L of the function is used to allocate vertices in the diagram (assignment to set a or b). L [I] = 1 means the vertex I is in the set A, and L [I] = 2 represents the vertex in B. The function has two output parameters: C and M, m for the size of the established coverage, C [0, M - 1] is a vertex that forms a coverage. If the two-point map is not overwritten, the function returns F a L s E; otherwise returns T R u e. Complete code See programs 1 3 - 4. Program 13-4 Construct greed overlay

Bool undirected :: bipartitecover (int L [], int C [], int & M)

{// Looking for a two-point map cover

// L is the reference number of the input vertex, L [I] = 1, and only when I is in A

// c is an array of record coverage

// If there is no overlay in the figure, return F a L S e

// If there is an overlay in the figure, returns T R u e;

// Return the size of the overlay in m; return over C [0: M - 1]

INT N = VE R T I c e s ();

// Plug-in structure

INT sizeofa = 0;

For (int I = 1; i <= n; i ) / / Determine the size of the collection A

IF (L [I] == 1) SIZEOFA ;

INT sizeofb = n - sizeofa;

Createbins (SizeOfb, N);

INT * new = new int [n 1]; / / vertex i covers N e w [i] unclocated vertex

Bool * change = new bool [n 1]; // change [i] is T R u e and only when NEW [i] has changed

BOOL * COV = New Bool [N 1]; // COV [i] is true and only when the vertex i is overwritten

I n i t i a l i z e p o s ();

LinkedStack

S;

// Initialization

For (i = 1; i <= n; i ) {

COV [I] = Change [I] = false;

IF (L [i] == 1) {// i in A

New [i] = degree (i); // i covers so much

INSERTBINS (New [i], i);}}

// Constructing coverage

INT COVERED = 0, // covered vertices

Maxbin = sizeofb; // may not empty maximum box

M = 0; // C Cursor

While (MAXBIN> 0) {// Search all boxes

// Select a vertection

IF (bin [maxbin]) {// box is not available

INT V = bin [maxbin]; // First vertex

C [m ] = v; // Add V to overwrite

/ / Mark the newly covered vertices

INT J = Begin (V), K;

While (j) {

IF (! COV [J]) {// j has not been overwritten

CoV [J] = True;

C O V e r e D ;

/ / Modify N e w

K = Begin (j);

While (k) {

NEW [K] -; // J is not included

IF (! Change [k]) {

S.Add (k); // Only in the stack

Change [k] = true;

K = NextVe R t e x (j);}

}

J = NextVe R t e x (v);

/ / Update the box while (! S.isempty ()) {

S. D e l e t e (k);

Change [k] = false;

Movebins (SizeOfb, New [K], K);

}

Else Maxbin -;

}

DE A C T I v A T E P O S ();

D E S T R O Y B I n ();

DELETE [] NEW;

DELETE [] CHANGE

DELETE [] COV;

Return (Covered == SIZEOFB);

}

Program 1 3 - 4 First calculates the size of the sets A and B, initialize the necessary two-way linked table structure, create three arrays, initialize the map travers, and create a stack. The array C O V and C H A N g e then initialized to F A L S E and inserted a vertex in the A, inserted into the corresponding bidirectional linked list according to their number of top points.

In order to construct the cover, first check the bidirectional linked list in order to deliver the sizeOfb to 1. When a non-empty table is found, the first vertex V is added to the overlay. This policy is to select the maximum NE OV [J] to TRUE, indicating that the vertex j is now overwritten, and will have The number of vertices covered B plus 1. Since J is the vertex of the recent w value. Add the selected vertex to the overlay array C and check all the vertices adjacent to it. If the vertex j is adjacent to V and has not been overwritten, the NEW value of the C cover, all A. The NEW value of the vertex is 1. The next While loop reduces these NEW values ​​and saves the NEW value to a stack in a stack. When all the COV values ​​of the vertex adjaced to the vertex V adjacency, the N EW value reflects the number of new vertices that can be overwritten in A, however the vertices in A are updated by the New value, in the wrong bidirectional linked list. In the next While loop moves these vertices to the correct table.

Reprinted from Shada Studio

转载请注明原文地址:https://www.9cbs.com/read-108009.html

New Post(0)