CN113901275A - Method and equipment for acquiring topology sequence of specified vertex - Google Patents

Method and equipment for acquiring topology sequence of specified vertex Download PDF

Info

Publication number
CN113901275A
CN113901275A CN202111076079.2A CN202111076079A CN113901275A CN 113901275 A CN113901275 A CN 113901275A CN 202111076079 A CN202111076079 A CN 202111076079A CN 113901275 A CN113901275 A CN 113901275A
Authority
CN
China
Prior art keywords
vertex
mark
current
specified
parent
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111076079.2A
Other languages
Chinese (zh)
Inventor
刘睿民
李天砚
易水寒
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Weixun Boray Data Technology Beijing Co ltd
Original Assignee
Weixun Boray Data Technology Beijing Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Weixun Boray Data Technology Beijing Co ltd filed Critical Weixun Boray Data Technology Beijing Co ltd
Priority to CN202111076079.2A priority Critical patent/CN113901275A/en
Priority to PCT/CN2021/134698 priority patent/WO2023040057A1/en
Publication of CN113901275A publication Critical patent/CN113901275A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/901Indexing; Data structures therefor; Storage structures
    • G06F16/9024Graphs; Linked lists
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a method and a device for acquiring a topological sequence of specified vertexes, wherein each vertex in a directed graph is provided with a mark, and the method comprises the following steps: when an acquisition instruction of a topological sequence of a specified vertex in the directed graph is detected, the specified vertex and each parent vertex at the upstream of the specified vertex are reversely traversed from the specified vertex based on a depth-first search function; generating a topological sequence according to a reverse traversal result; the label is a first label when the current vertex is not accessed, a second label when the current vertex is accessed and the current vertex has an unvisited parent vertex, a third label when the current vertex is accessed and the current vertex does not have the unvisited parent vertex, and the label of each vertex in the topological sequence is the third label, so that the whole directed graph is prevented from being scanned and traversed, the waste of computing resources is avoided, and the efficiency of acquiring the topological sequence of the specified vertex in the directed graph is improved.

Description

Method and equipment for acquiring topology sequence of specified vertex
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for obtaining a topology sequence of specified vertices.
Background
In the introduction to computer algorithms, it is described how to topologically order a Directed Acyclic Graph (DAG) using depth-first search (dfs). After topological sorting the directed acyclic graph G = (V, E), the result is a linear sequence of vertices of the graph, such that if G contains an edge (u, V), then u appears before V in the sequence (if the graph is looped, such a linear sequence is not possible). The topological ordering of a graph can be viewed as a sequence of all vertices in the graph arranged along a horizontal line. Such that all directed edges point from left to right. Thus, the topological ordering is different from the ordering in the usual sense.
At present, the topology ranking algorithm commonly used in the art is the above-mentioned algorithm, and in the specific implementation process, the following steps are mainly performed:
1. performing a depth-first search traversal by calling a corresponding function, such as dfs _ travel ();
2. in the process of carrying out depth-first search traversal function dfs _ travel () each time, the access completion time of the vertexes is recorded, and the vertexes are stored in an array storing the topological sorting order according to the access completion time of the vertexes. Thus, the array topoSort [ ] stores all vertices that have been accessed in chronological order.
3. And (4) carrying out reverse order arrangement on the array topoSort [ ], and finally carrying out topological ordering to obtain a linear sequence.
The prior art has the following disadvantages:
1. all vertexes of the whole graph need to be traversed, the topological sequences of all vertexes of the whole graph are obtained, the traversing efficiency is low, and a large amount of computing resources are wasted;
2. if some of the vertices are already complete, pruning cannot be performed for a particular vertex topology sequence.
Therefore, how to improve the efficiency of obtaining the topological sequence of the specified vertices in the directed graph is a technical problem to be solved at present.
Disclosure of Invention
The invention provides a method for acquiring a topological sequence of an appointed vertex, which is used for solving the technical problems of computing resource waste and low efficiency when acquiring the topological sequence of the appointed vertex in a directed graph in the prior art.
The method comprises the following steps:
when an acquisition instruction of a topology sequence of a specified vertex in the directed graph is detected, performing reverse traversal on the specified vertex and each parent vertex upstream of the specified vertex from the specified vertex based on a depth-first search function, and generating the topology sequence according to a reverse traversal result, wherein the reverse traversal process specifically comprises the following steps:
if the mark of the current vertex is the first mark, accessing the current vertex, changing the mark of the current vertex into the second mark, and continuously searching the parent vertex of the current vertex according to the depth-first search function;
if the mark of the current vertex is the second mark and the current vertex does not have a parent vertex or the mark of the parent vertex of the current vertex is a third mark, changing the mark of the current vertex into the third mark;
if the mark of the specified vertex is the third mark, determining that the reverse traversal is completed;
the mark is the first mark when the current vertex is not visited, the mark is the second mark when the current vertex is visited and the current vertex has an unvisited parent vertex, the mark is the third mark when the current vertex is visited and the current vertex does not have an unvisited parent vertex, and the mark of each vertex in the topological sequence is the third mark.
In some embodiments of the present application, after changing the label of the current vertex to the third label, the method further comprises:
and storing the current vertex into a preset array for storing topology sequencing, and determining a reverse traversal result after storing the specified vertex into the preset array.
In some embodiments of the present application, the method further comprises:
when the obtaining instruction is detected and the designated vertex has a target parent vertex marked as the third mark, performing reverse traversal on each vertex between the designated vertex and the target parent vertex from the designated vertex based on a depth-first search function, and generating the topology sequence according to a reverse traversal result.
In some embodiments of the present application, before traversing the specified vertex and parent vertices upstream from the specified vertex in reverse based on a depth-first search function, the method further comprises:
obtaining each father vertex at the upstream of the specified vertex after the directed graph is composed based on an adjacency list;
initializing the label of each vertex in the directed graph to the first label.
Correspondingly, the invention also provides a device for acquiring the topology sequence of the specified vertex, wherein each vertex in the directed graph is provided with a mark, and the device comprises:
the first traversal module is configured to, when an acquisition instruction of a topology sequence of a specified vertex in the directed graph is detected, perform reverse traversal on the specified vertex and parent vertices upstream of the specified vertex from the specified vertex based on a depth-first search function, where a reverse traversal process specifically includes:
if the mark of the current vertex is the first mark, accessing the current vertex, changing the mark of the current vertex into the second mark, and continuously searching the parent vertex of the current vertex according to the depth-first search function;
if the mark of the current vertex is the second mark and the current vertex does not have a parent vertex or the mark of the parent vertex of the current vertex is a third mark, changing the mark of the current vertex into the third mark;
if the mark of the specified vertex is the third mark, determining that the reverse traversal is completed;
the generating module is used for generating the topological sequence according to the result of the reverse traversal;
the mark is the first mark when the current vertex is not visited, the mark is the second mark when the current vertex is visited and the current vertex has an unvisited parent vertex, the mark is the third mark when the current vertex is visited and the current vertex does not have an unvisited parent vertex, and the mark of each vertex in the topological sequence is the third mark.
In some embodiments of the present application, the apparatus further comprises a logging module configured to:
and storing the current vertex into a preset array for storing topology sequencing, and determining a reverse traversal result after storing the specified vertex into the preset array.
In some embodiments of the present application, the apparatus further comprises a second traversal module configured to:
when the obtaining instruction is detected and the designated vertex has a target parent vertex marked as the third mark, performing reverse traversal on each vertex between the designated vertex and the target parent vertex from the designated vertex based on a depth-first search function, and generating the topology sequence according to a reverse traversal result.
In some embodiments of the present application, the apparatus further comprises:
the composition module is used for obtaining each father vertex at the upstream of the specified vertex after the directed graph is composed based on the adjacency list;
and the initialization module is used for initializing the mark of each vertex in the directed graph to the first mark.
By applying the technical scheme, each vertex in the directed graph is marked, and when an acquisition instruction of a topological sequence of a specified vertex in the directed graph is detected, the specified vertex and each parent vertex upstream of the specified vertex are reversely traversed from the specified vertex based on a depth-first search function; generating the topological sequence according to the result of the reverse traversal; the label is a first label when the current vertex is not accessed, the label is a second label when the current vertex is accessed and the current vertex has an unvisited parent vertex, the label is a third label when the current vertex is accessed and the current vertex does not have the unvisited parent vertex, and the label of each vertex in the topological sequence is the third label, so that the whole directed graph is prevented from being scanned and traversed, the waste of computing resources is avoided, and the efficiency of acquiring the topological sequence of the specified vertex in the directed graph is improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic flowchart illustrating a method for obtaining a topology sequence of specified vertices according to an embodiment of the present invention;
FIG. 2 is a schematic diagram illustrating a directed graph in an embodiment of the present invention;
FIG. 3 is a schematic diagram illustrating another directed graph in an embodiment of the present invention;
fig. 4 is a schematic structural diagram of an apparatus for obtaining a topology sequence of specified vertices according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The embodiment of the present application provides a method for obtaining a topology sequence of an appointed vertex, as shown in fig. 1, including the following steps:
step S101, when an acquisition instruction of a topological sequence of a specified vertex in a directed graph is detected, the specified vertex and each parent vertex upstream of the specified vertex are reversely traversed from the specified vertex based on a depth-first search function.
In this embodiment, the directed graph may be a directed acyclic graph, where the topological sequence of the specified vertex in the directed graph is a topological sequence formed by upstream vertices that must be completed to complete the specified vertex, and the upstream vertices are parent vertices upstream of the specified vertex. Each vertex in the directed graph is provided with a mark, the mark is a first mark when the current vertex is not visited, the mark is a second mark when the current vertex is visited and the current vertex has an unvisited parent vertex, and the mark is a third mark when the current vertex is visited and the current vertex does not have the unvisited parent vertex. When an acquisition instruction about the topological sequence is detected, the specified vertex and each parent vertex upstream of the specified vertex are reversely traversed from the specified vertex based on the depth-first search function, wherein the reverse traversal is to perform backtracking search on the vertex.
The acquisition instruction can be automatically triggered when the user sends the instruction or reaches a preset condition, the depth-first search belongs to one of graph algorithms, the process is briefly to deepen each possible branch path until the path can not be deepened any more, and each node can only be visited once.
In a specific application scenario of the present application, the first mark is white, the second mark is gray, and the third mark is black, and those skilled in the art can flexibly set other expressions of the mark according to actual needs, which does not affect the protection scope of the present application.
The reverse traversal process specifically comprises:
if the mark of the current vertex is the first mark, accessing the current vertex, changing the mark of the current vertex into the second mark, and continuously searching the parent vertex of the current vertex according to the depth-first search function;
if the mark of the current vertex is the second mark and the current vertex does not have a parent vertex or the mark of the parent vertex of the current vertex is the third mark, changing the mark of the current vertex into the third mark;
and if the mark of the specified vertex is the third mark, determining that the reverse traversal is completed.
In the embodiment, reverse traversal is performed based on a depth-first search function in combination with the marks of the designated vertex and each parent vertex, if the mark of the current vertex is a first mark, the current vertex is not accessed, the current vertex is accessed, the mark of the current vertex is changed into a second mark, and the parent vertex of the current vertex is continuously searched according to the depth-first search function; if the label of the current vertex is the second label and the current vertex does not have a parent vertex or the label of the parent vertex of the current vertex is a third label, indicating that the traversal process corresponding to the current vertex is finished, and changing the label of the current vertex into the third label; and if the mark of the designated vertex is the third mark, the designated vertex and each parent vertex are completely traversed, and the reverse traversal is determined to be completed.
In order to reliably determine the result of the reverse traversal, in some embodiments of the present application, after changing the label of the current vertex to the third label, the method further includes:
and storing the current vertex into a preset array for storing topology sequencing, and determining a reverse traversal result after storing the specified vertex into the preset array.
In the implementation, a preset array for storing the topological sort is predefined and constructed, and after the mark of each vertex is changed into a third mark, each vertex is sequentially stored in the preset array, so that a reverse traversal result is determined.
To improve the traversal efficiency, in some embodiments of the present application, before reversely traversing the designated vertex and parent vertices upstream of the designated vertex from the designated vertex based on a depth-first search function, the method further includes:
obtaining each father vertex at the upstream of the specified vertex after the directed graph is composed based on an adjacency list;
initializing the label of each vertex in the directed graph to the first label.
In this embodiment, before performing reverse traversal, the directed graph is patterned based on the adjacency list, then parent vertices upstream of the specified vertex are obtained, and then the label of each vertex in the directed graph is initialized to the first label. The specific process of patterning the directed graph based on the adjacency list will be apparent to those skilled in the art, and will not be described in detail herein.
And S102, generating the topology sequence according to the reverse traversal result.
In this embodiment, after the reverse traversal is completed, the designated vertex and the label of each parent vertex upstream of the designated vertex are the third labels, and a topology sequence may be generated according to the result of the reverse traversal, that is, the label of each vertex in the topology sequence is the third label.
To further improve traversal efficiency, in some embodiments of the present application, the method further comprises:
when the obtaining instruction is detected and the designated vertex has a target parent vertex marked as the third mark, performing reverse traversal on each vertex between the designated vertex and the target parent vertex from the designated vertex based on a depth-first search function, and generating the topology sequence according to a reverse traversal result.
In this embodiment, when the obtaining instruction is detected and the designated vertex has the target parent vertex marked as the third mark, the corresponding reverse traversal is already completed for the target parent vertex, so that the backtracking search is not performed on the target parent vertex, but the reverse traversal is performed on each vertex between the designated vertex and the target parent vertex from the designated vertex based on the depth-first search function, and a topology sequence is generated according to the result of the reverse traversal, thereby improving the traversal efficiency.
By applying the technical scheme, each vertex in the directed graph is marked, and when an acquisition instruction of a topological sequence of a specified vertex in the directed graph is detected, the specified vertex and each parent vertex upstream of the specified vertex are reversely traversed from the specified vertex based on a depth-first search function; generating the topological sequence according to the result of the reverse traversal; the label is a first label when the current vertex is not accessed, the label is a second label when the current vertex is accessed and the current vertex has an unvisited parent vertex, the label is a third label when the current vertex is accessed and the current vertex does not have the unvisited parent vertex, and the label of each vertex in the topological sequence is the third label, so that the whole directed graph is prevented from being scanned and traversed, the waste of computing resources is avoided, and the efficiency of acquiring the topological sequence of the specified vertex in the directed graph is improved.
In order to further illustrate the technical idea of the present invention, the technical solution of the present invention will now be described with reference to specific application scenarios.
The embodiment of the application provides a method for acquiring a topological sequence of an appointed vertex, which comprises the following steps:
step 1, aiming at the directed graph G = (V, E), composition is carried out on the directed graph G = (V, E) by using an adjacency list.
Specifically, for each vertex v, a parent vertex set is initialized, and vertex u on the edge (u, v) is stored in the parent vertex set of vertex v.
And 2, initializing the vertexes, marking the vertexes, and marking all the vertexes to be white.
Wherein, the rule for marking the vertex is as follows:
a vertex is marked as white, which means that the vertex has not been visited;
the vertex is marked with gray, which represents that the vertex has been visited but not traversed;
the vertex is marked black, which represents that the vertex has been traversed.
And 3, traversing and searching the constructed directed graph, and marking the vertex of the directed graph.
And starting depth-first search traversal on the directed graph by taking the specified vertex as an entrance.
When the vertex is accessed and a parent vertex which is not marked as black is still available, marking the vertex as gray, and continuously performing depth-first search on the parent vertex; when the gray vertex has no father vertex or the father vertex is completely marked as black, the gray vertex is changed into a black vertex; the vertex is marked black, which represents that the vertex has been traversed.
If the vertex is marked as black, the vertex and the parent vertex thereof are completely traversed and accessed, an array for storing topology sequencing is defined and constructed, and then all the traversed and accessed vertexes are stored in the array according to the sequence of completion time.
In the process of traversing each vertex of the directed graph, the judgment condition for searching and traversing the vertex is as follows:
if the vertex v is black, returning; if vertex v is gray, it indicates that a loop exists;
marking the vertex v as gray, and sequentially performing parent vertex traversal and search on the parent vertex of the vertex v, for example, calling a dfs (v.fast) function, marking the vertex v as black after the traversal search is finished, and storing the black vertex v into an array for storing the topological sort.
And 4, determining a topological sequence of the specified vertex based on the topological sorting in the array.
Where the code description is as follows:
func dfs(Vertex v) {
if color[c] == black then return
if color[c] == grey then return Cycle
color[v] = grey
for father in v.fathers do
dfs(father)
end for
color[v] = black
push v in topoSort
return
in addition, because the vertex is marked, the vertex cannot be traced back forward after being marked as black, so that tracing traversal and search of the vertex before the vertex marked as black are avoided, the depth-first search is simplified, and the calculation amount is saved.
This scheme will be described below with reference to a specific directed graph.
As shown in fig. 2, which is a directed graph according to an embodiment of the present invention, vertex 3 is an end point (i.e., a designated vertex), and a topological sequence of vertex 3 is obtained.
The method of the invention, wherein a group of topological sequences are: 1- >2- >6- >7- >4- >3, and the specific acquisition method and steps are described as follows.
Vertices 5, 8, and 9 are not related to completion 3 and are therefore not included in the topological sequence of vertex 3.
The steps of performing depth-first search on the directed graph in fig. 2 to obtain the topology sequence of the designated vertex 3 are shown in table 1, where dfs () is a depth-first search function.
TABLE 1
Figure 50228DEST_PATH_IMAGE001
From the table above, the final result can be found to be: 1- >2- >6- >7- >4- > 3.
The present embodiment will be described in detail below with reference to fig. 2 and table 1.
According to the method for acquiring the topology sequence of the specified vertex, the fixed point 3 in the directed graph is taken as the specified vertex, depth-first search aiming at a target task is carried out, and the step of acquiring the topology sequence of the vertex 3 is as follows:
1. all vertices are initialized to white color, indicating they have not been visited, and entry of dfs begins at vertex 3 because a topological sequence for vertex 3 is to be obtained.
2. dfs (3): change 3 to gray vertex and know that 3 has parent vertices of 2 and 4, select 2.
3. dfs (2): change 2 to gray vertex, and know that 2's father vertex has 1, choose 1.
4. dfs (1): change 1 to gray vertex and know that 1 has no parent vertex.
5. Completing 1: changing 1 to a black vertex, adding 1 to the topoSort [ ] array, rolling back to 2, and finding that the parent vertices of 2 are all black.
6. And (3) completing 2: change 2 to black vertex, add 2 to topoSort [ ] array, roll back to 3, find the white parent vertex of 3 with 4 remaining.
7. dfs (4): change 4 to gray vertex and know that the parent vertex of 4 has 1 and 7, where 1 is already a black vertex, select 7.
8. dfs (7): change 7 to gray vertex, and at the same time know that 7 has 6 parent vertices, select 6.
9. dfs (6): change 6 to gray vertex while knowing that 6 has no parent vertex.
10. And (6) completion: change 6 to a black vertex, add 6 to the topoSort [ ] array, roll back to 7, finding that the parent vertices of 7 are all black.
11. And 7, finishing: change 7 to black vertex, add 7 to the topoSort [ ] array, go back to 4, and find the parent vertices of 4 all black.
12. And (4) completion: change 4 to black vertex, add 4 to the topoSort [ ] array, roll back to 3, finding that the parent vertices of 3 are all black.
13. And (3) completion: change 3 to a black vertex, add 3 to the topoSort [ ] array, exit dfs.
14. Obtaining a topological sequence topoSort [ ] based on the vertex 3: 1- >2- >6- >7- >4- > 3.
Referring to fig. 3 as another directed graph, the vertex 12 is designated as an end point, and the topological sequence of the vertex 12 obtained with reference to the traversal order of fig. 2 is: 2- >0- >8- >7- >6- >9- >11- >12, but if vertex 6 has been marked before the traversal search is performed and the mark is black, that is to say traversal and access have been completed in advance for vertex 6, then in this case the topological order of vertex 12 obtained is: 6- >9- >11- > 12. In this way, no backtracking search is performed on vertex 6, thereby avoiding waste of computing resources.
By applying the technical scheme, starting from a target task, the specified vertex of the directed graph is traversed and accessed by using a depth-first search method, and the topological sequence of the specified vertex of the directed graph is generated, so that the whole directed graph is prevented from being scanned and traversed, the whole directed graph cannot be scanned and traversed as the conventional traversal method, the waste of a large amount of computing resources is avoided, and the traversal efficiency of the directed graph is improved. And if the vertexes which are actually traversed and accessed exist before the reverse traversal is carried out, the vertexes are timely returned in the traversal process, and the invalid traversal and scanning cannot be carried out blindly, so that the depth-first search is greatly optimized, and the calculation efficiency in the actual application process is greatly improved.
The embodiment of the present application further provides an apparatus for acquiring a topology sequence of specified vertices, where each vertex in a directed graph has a label, as shown in fig. 4, the apparatus includes:
a first traversal module 401, configured to, when an obtaining instruction of a topology sequence of a specified vertex in the directed graph is detected, perform reverse traversal on the specified vertex and parent vertices upstream of the specified vertex from the specified vertex based on a depth-first search function, where a process of the reverse traversal specifically is:
if the mark of the current vertex is the first mark, accessing the current vertex, changing the mark of the current vertex into the second mark, and continuously searching the parent vertex of the current vertex according to the depth-first search function;
if the mark of the current vertex is the second mark and the current vertex does not have a parent vertex or the mark of the parent vertex of the current vertex is a third mark, changing the mark of the current vertex into the third mark;
if the mark of the specified vertex is the third mark, determining that the reverse traversal is completed;
a generating module 402, configured to generate the topology sequence according to a result of the reverse traversal,
the mark is the first mark when the current vertex is not visited, the mark is the second mark when the current vertex is visited and the current vertex has an unvisited parent vertex, the mark is the third mark when the current vertex is visited and the current vertex does not have an unvisited parent vertex, and the mark of each vertex in the topological sequence is the third mark.
In a specific application scenario of the present application, the device further includes a logging module, configured to:
and storing the current vertex into a preset array for storing topology sequencing, and determining a reverse traversal result after storing the specified vertex into the preset array.
In a specific application scenario of the present application, the apparatus further includes a second traversal module, configured to:
when the obtaining instruction is detected and the designated vertex has a target parent vertex marked as the third mark, performing reverse traversal on each vertex between the designated vertex and the target parent vertex from the designated vertex based on a depth-first search function, and generating the topology sequence according to a reverse traversal result.
In a specific application scenario of the present application, the apparatus further includes:
the composition module is used for obtaining each father vertex at the upstream of the specified vertex after the directed graph is composed based on the adjacency list;
and the initialization module is used for initializing the mark of each vertex in the directed graph to the first mark.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit the same; although the present application has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not necessarily depart from the spirit and scope of the corresponding technical solutions in the embodiments of the present application.

Claims (8)

1. A method for obtaining a topological sequence of specified vertices, wherein each vertex in a directed graph carries a label, the method comprising:
when an acquisition instruction of a topology sequence of a specified vertex in the directed graph is detected, performing reverse traversal on the specified vertex and each parent vertex upstream of the specified vertex from the specified vertex based on a depth-first search function, and generating the topology sequence according to a reverse traversal result, wherein the reverse traversal process specifically comprises the following steps:
if the mark of the current vertex is the first mark, accessing the current vertex, changing the mark of the current vertex into the second mark, and continuously searching the parent vertex of the current vertex according to the depth-first search function;
if the mark of the current vertex is the second mark and the current vertex does not have a parent vertex or the mark of the parent vertex of the current vertex is a third mark, changing the mark of the current vertex into the third mark;
if the mark of the specified vertex is the third mark, determining that the reverse traversal is completed;
the mark is the first mark when the current vertex is not visited, the mark is the second mark when the current vertex is visited and the current vertex has an unvisited parent vertex, the mark is the third mark when the current vertex is visited and the current vertex does not have an unvisited parent vertex, and the mark of each vertex in the topological sequence is the third mark.
2. The method of claim 1, wherein after changing the label of the current vertex to the third label, the method further comprises:
and storing the current vertex into a preset array for storing topology sequencing, and determining a reverse traversal result after storing the specified vertex into the preset array.
3. The method of claim 1, wherein the method further comprises:
when the obtaining instruction is detected and the designated vertex has a target parent vertex marked as the third mark, performing reverse traversal on each vertex between the designated vertex and the target parent vertex from the designated vertex based on a depth-first search function, and generating the topology sequence according to a reverse traversal result.
4. The method of claim 1, wherein prior to traversing the specified vertex and parent vertices upstream from the specified vertex in reverse based on a depth-first search function starting from the specified vertex, the method further comprises:
obtaining each father vertex at the upstream of the specified vertex after the directed graph is composed based on an adjacency list;
initializing the label of each vertex in the directed graph to the first label.
5. An apparatus for obtaining a topological sequence of specified vertices, wherein each vertex in a directed graph has a label, the apparatus comprising:
the first traversal module is configured to, when an acquisition instruction of a topology sequence of a specified vertex in the directed graph is detected, perform reverse traversal on the specified vertex and parent vertices upstream of the specified vertex from the specified vertex based on a depth-first search function, where a reverse traversal process specifically includes:
if the mark of the current vertex is the first mark, accessing the current vertex, changing the mark of the current vertex into the second mark, and continuously searching the parent vertex of the current vertex according to the depth-first search function;
if the mark of the current vertex is the second mark and the current vertex does not have a parent vertex or the mark of the parent vertex of the current vertex is a third mark, changing the mark of the current vertex into the third mark;
if the mark of the specified vertex is the third mark, determining that the reverse traversal is completed;
the generating module is used for generating the topological sequence according to the result of the reverse traversal;
the mark is the first mark when the current vertex is not visited, the mark is the second mark when the current vertex is visited and the current vertex has an unvisited parent vertex, the mark is the third mark when the current vertex is visited and the current vertex does not have an unvisited parent vertex, and the mark of each vertex in the topological sequence is the third mark.
6. The apparatus of claim 5, further comprising a logging module to:
and storing the current vertex into a preset array for storing topology sequencing, and determining a reverse traversal result after storing the specified vertex into the preset array.
7. The device of claim 5, further comprising a second traversal module to:
when the obtaining instruction is detected and the designated vertex has a target parent vertex marked as the third mark, performing reverse traversal on each vertex between the designated vertex and the target parent vertex from the designated vertex based on a depth-first search function, and generating the topology sequence according to a reverse traversal result.
8. The apparatus of claim 5, wherein the apparatus further comprises:
the composition module is used for obtaining each father vertex at the upstream of the specified vertex after the directed graph is composed based on the adjacency list;
and the initialization module is used for initializing the mark of each vertex in the directed graph to the first mark.
CN202111076079.2A 2021-09-14 2021-09-14 Method and equipment for acquiring topology sequence of specified vertex Pending CN113901275A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202111076079.2A CN113901275A (en) 2021-09-14 2021-09-14 Method and equipment for acquiring topology sequence of specified vertex
PCT/CN2021/134698 WO2023040057A1 (en) 2021-09-14 2021-12-01 Method and device for acquiring topological sequence of specified vertex

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111076079.2A CN113901275A (en) 2021-09-14 2021-09-14 Method and equipment for acquiring topology sequence of specified vertex

Publications (1)

Publication Number Publication Date
CN113901275A true CN113901275A (en) 2022-01-07

Family

ID=79028073

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111076079.2A Pending CN113901275A (en) 2021-09-14 2021-09-14 Method and equipment for acquiring topology sequence of specified vertex

Country Status (2)

Country Link
CN (1) CN113901275A (en)
WO (1) WO2023040057A1 (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023241641A1 (en) * 2022-06-15 2023-12-21 华为技术有限公司 Graph processing method and apparatus
CN117390088A (en) * 2023-11-01 2024-01-12 九科信息技术(深圳)有限公司 Method, device and storage medium for mining relation between objects

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103840871B (en) * 2014-01-14 2017-01-11 浙江工商大学 Encoding and reconstruction method of three-dimensional model topological data robust transmission in wireless network
CN105303612B (en) * 2014-12-03 2017-12-15 河南理工大学 A kind of extract digital network method based on Triangulated irregular network model
CN110659284A (en) * 2019-08-20 2020-01-07 北京清红微谷技术开发有限责任公司 Block sequencing method and system based on tree graph structure and data processing terminal
CN111178532B (en) * 2019-12-11 2023-12-12 本源量子计算科技(合肥)股份有限公司 Quantum circuit matching method and device, storage medium and electronic device
CN112165405B (en) * 2020-10-13 2022-04-22 中国人民解放军国防科技大学 Method for testing big data processing capacity of supercomputer based on network topological structure

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023241641A1 (en) * 2022-06-15 2023-12-21 华为技术有限公司 Graph processing method and apparatus
CN117390088A (en) * 2023-11-01 2024-01-12 九科信息技术(深圳)有限公司 Method, device and storage medium for mining relation between objects

Also Published As

Publication number Publication date
WO2023040057A1 (en) 2023-03-23

Similar Documents

Publication Publication Date Title
Bolelli et al. Spaghetti labeling: Directed acyclic graphs for block-based connected components labeling
CN113901275A (en) Method and equipment for acquiring topology sequence of specified vertex
Munagala et al. I/O-complexity of graph algorithms
CN110909364B (en) Source code bipolar software security vulnerability map construction method
CN112712546A (en) Target tracking method based on twin neural network
CN109299443B (en) News text duplication eliminating method based on minimum vertex coverage
CN105808779A (en) Picture roaming parallel computing method based on pruning and application
CN111428093A (en) Entity alignment-based visual map fusion method and system
CN108052743B (en) Method and system for determining step approach centrality
CN110781311A (en) Enterprise consistent action calculation system and method
CN111241228B (en) Comprehensive drawing method based on vector data and graphic processing technology
CN107798424A (en) Intelligent processing system of going on a tour based on big data
CN111951059A (en) Real estate valuation method, device, terminal and readable storage medium
CN116661786A (en) Design page generation method and device
CN109684185A (en) Heuristic traversal-based big data processing capacity test method for supercomputer
Meseguer et al. Constraint satisfaction as global optimization
Vörös A strategy for repetitive neighbor finding in octree representations
Zhang et al. Enhanced branch-and-bound framework for a class of sequencing problems
Buchhold et al. Nearest-neighbor queries in customizable contraction hierarchies and applications
CN109189833B (en) Knowledge base mining method and device
Arleo et al. GraphRay: Distributed pathfinder network scaling
CN117312608B (en) Depth-first search-based river network node degeneracy method
Corrêa et al. A bit-parallel russian dolls search for a maximum cardinality clique in a graph
Rathi et al. Applications of depth first search: a survey
KR100471417B1 (en) A Method for Visualizing Protein Interaction Networks

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information
CB02 Change of applicant information

Address after: Room 701, floor 7, building 3, courtyard 6, lizexi street, Chaoyang District, Beijing 100102

Applicant after: Beijing birui Data Technology Co.,Ltd.

Address before: Room 701, floor 7, building 3, courtyard 6, lizexi street, Chaoyang District, Beijing 100102

Applicant before: WEIXUN BORAY DATA TECHNOLOGY (BEIJING) Co.,Ltd.