CN108595208A - A kind of method that the ladder diagram handling function vertex is converted into instruction sequence - Google Patents

A kind of method that the ladder diagram handling function vertex is converted into instruction sequence Download PDF

Info

Publication number
CN108595208A
CN108595208A CN201711488500.4A CN201711488500A CN108595208A CN 108595208 A CN108595208 A CN 108595208A CN 201711488500 A CN201711488500 A CN 201711488500A CN 108595208 A CN108595208 A CN 108595208A
Authority
CN
China
Prior art keywords
vertex
bet
node
adj
tail
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.)
Granted
Application number
CN201711488500.4A
Other languages
Chinese (zh)
Other versions
CN108595208B (en
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.)
Beijing Union University
Original Assignee
Beijing Union University
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 Beijing Union University filed Critical Beijing Union University
Priority to CN201711488500.4A priority Critical patent/CN108595208B/en
Publication of CN108595208A publication Critical patent/CN108595208A/en
Application granted granted Critical
Publication of CN108595208B publication Critical patent/CN108595208B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/30145Instruction analysis, e.g. decoding, instruction word fields
    • GPHYSICS
    • G05CONTROLLING; REGULATING
    • G05BCONTROL OR REGULATING SYSTEMS IN GENERAL; FUNCTIONAL ELEMENTS OF SUCH SYSTEMS; MONITORING OR TESTING ARRANGEMENTS FOR SUCH SYSTEMS OR ELEMENTS
    • G05B19/00Programme-control systems
    • G05B19/02Programme-control systems electric
    • G05B19/04Programme control other than numerical control, i.e. in sequence controllers or logic controllers
    • G05B19/05Programmable logic controllers, e.g. simulating logic interconnections of signals according to ladder diagrams or function charts
    • G05B19/056Programming the PLC
    • GPHYSICS
    • G05CONTROLLING; REGULATING
    • G05BCONTROL OR REGULATING SYSTEMS IN GENERAL; FUNCTIONAL ELEMENTS OF SUCH SYSTEMS; MONITORING OR TESTING ARRANGEMENTS FOR SUCH SYSTEMS OR ELEMENTS
    • G05B2219/00Program-control systems
    • G05B2219/10Plc systems
    • G05B2219/13Plc programming
    • G05B2219/13018Conversion ladder diagram to decision system, machine code, language

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Automation & Control Theory (AREA)
  • Image Generation (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a kind of method that the ladder diagram handling function vertex is converted into instruction sequence, in this method:Scheme G=<V,E>It is combined by the collection of one group of limited vertex V and side E;The printout slight changes of the inorder traversal of tree are just obtained with the instruction sequence of different specification.Binary expression tree is directly preserved in memory, saves the translation process of expression formula, after obtaining the sequence of binary tree subsequently traversed, is carried out the expression formula based on stack and is calculated, to directly obtain result of calculation;This method can cache the secondary result of calculation used below automatically using binary expression tree data structure as target, without all being cached to all results in parallel merged, to save memory space.The processing of ladder diagram is mainly concentrated in and is transcribed into instruction list, is completed by the control task of trapezoidal graph expression so that programmable controller (PLC) can execute these instructions.

Description

A kind of method that the ladder diagram handling function vertex is converted into instruction sequence
Technical field
It is converted into the method for instruction sequence the present invention relates to ladder diagram more particularly to a kind of handling the trapezoidal of function vertex The method that figure is converted into instruction sequence, belongs to technical field of industrial control.
Background technology
Ladder diagram (Ladder Diagrame abbreviation LD) is widely used in industrial control field, the processing to ladder diagram It is mainly concentrated in and is transcribed into instruction list, completed so that programmable controller (PLC) can execute these instructions By the control task of trapezoidal graph expression.The fortune that ladder diagram is substantially a kind of connection structure by between arithmetic element to describe Operator expression formula, expression formula includes only two kinds of operations, corresponding with cascaded structure and parallel-connection structure respectively.Ladder diagram is converted into referring to The method for enabling table is many, but all more or less there is problem.It gives and ladder diagram is translated into IEC 61131-3 instructions The method of table can have the vertex function in the ladder diagram converted, to complete specific funcall.But this method Processing to the vertex function function is simultaneously not perfect, and asking for its input must be calculated in advance by not accounting for the vertex function Topic.Algorithm does not provide the time of algorithm performs simultaneously.
The conversion of ladder diagram to instruction catalogue is inherently conversion of the figure to binary expression tree.Binary expression tree, letter Claim BET, be one kind of binary tree, the ergodic sequence by gained after the inorder traversal to tree is an expression formula.Tree is appointed What subtree claims to become y-bend expression formula subtree, is denoted as SUB-BET.
Invention content
The present invention proposes a kind of method that ladder diagram is converted into binary expression tree:LD-BET methods, this method is not The deficiency for only overcoming previous methods, more important is not to be converted into instruction catalogue as target, but with binary expression tree number It is target according to structure.The printout slight changes of the inorder traversal of tree can be obtained by with the instruction sequence of different specification, i.e., Ladder diagram can be translated into various instruction sequences.At the same time it can also directly preserve binary expression tree in memory, table is saved Up to the translation process of formula, after obtaining the sequence of binary tree subsequently traversed, the expression formula based on stack can be carried out and calculated, from And directly obtain result of calculation.Another feature of the algorithm is can be carried out automatically to the secondary result of calculation used below Caching, without all being cached to all results in parallel merged, to save memory space.
The invention discloses a kind of method that the ladder diagram handling function vertex is converted into instruction sequence, in this method: Scheme G=<V,E>It is combined by the collection of one group of limited vertex V and side E.If G is a figure, then V=G.V indicates the top in figure Point set, E=G.E indicate the side collection in figure;Any one ladder diagram is all expressed as an i.e. DAG of directed acyclic graph.Additionally must Some constraintss must be met, the DAG figures referred to as LDGraph that disclosure satisfy that these constraintss.
2 objects are used in LD-BET methods, one is the node for describing BET trees, another is for describing The vertex of LDGraph.Node object includes vertex, left, right, π attributes, and node set is denoted as N.Constitute the institute of BET trees There is node to constitute a node set NBET, andVertex attributes indicate the vertex that node is included, that is, indicate The node is corresponding with which vertex in figure.Left indicates that left pointer, right indicate that right pointer, π indicate parent pointer, all fingers Needle is directed toward other nodes in BET trees.The unspecial attribute of name of node object, node name is with including vertex therein The attribute of name of object indicates.Node object is created by NODE (vertex) method, makes three knots by ADD-NODE methods Point all becomes to belong to NBETNode.Vertex objects include name, Adj, Adj', buffer, buffer', root, π, d, Color, conntionType, functionType attribute.Vertex title is indicated that Adj indicates the adjoining on vertex by name attributes Table;The form of figure adjacency list describes, and a set { Adj is represented for its adjacency list of vertex v v.Adj1,Adj2,……, Adjn, wherein Adji∈ V, i=1,2 ... ..., n.The set expression has one each element from v to set v.Adj Directed edge;Each element in the adjacency list vertex1.Adj on vertex 1 be vertex 2, vertex 3, vertex 6, vertex 7,vertex 10,vertex 20,vertex 21}.Adj' is a chained list, and parallel connection type vertex is injected for collecting Series branch, series branch it is in parallel merge to use it.One ordered sequence is represented for its chained list of vertex v v.Adj'< Adj'1,Adj'2,……,Adj'n>, wherein Adj'i∈NBET, i=1,2 ... ..., n.Ordered sequence indicates every from v to sequence There are the series branch of an injection v, ordering to represent the sequencing of injection between one element.Buffer, Buffer' is used to cache intermediate result when generating BET subtrees.Root indicates the root with the relevant BET subtrees in the vertex.π tables Show the father vertex on vertex.The distance that d is used to indicate vertex to initial vertax.Color is used for identifying the access state on vertex, so as to Judge whether vertex has been accessed in ergodic process.Vertex objects are created by vertex (name) method, parameter list Show the name attributes on vertex.
Classify according to connection relation and vertex is divided into tandem type vertex and parallel connection type vertex.Tandem type vertex:In-degree in figure All it is not more than 1 vertex with out-degree, uses VSIt indicates.Parallel connection type vertex:In-degree is more than 1 or vertex of the out-degree more than 1 in figure, uses VP It indicates;VS∪VP=G.V.Connection relation is classified to be indicated by vertex attribute connectionType, corresponding value Respectively SERIAL, PARALLEL indicate tandem type vertex and parallel connection type vertex respectively.
Vertex is divided into initial vertax according to function classification, terminates vertex, the vertex relay, the vertex coil, the tops function Point, the vertex auxiliary function, the auxiliary vertex relay and the vertex auxiliary coil;The classification is by vertex attribute functionType It indicates, corresponding value is respectively GS, GT, RELAY, COIL, FUNCTION, VSF, RELAY, VCOIL, corresponding connection relation Respectively:Parallel connection, it is in parallel, it connects, connects, connect, connect, series connection is in parallel.
Description of the drawings
Fig. 1 is a digraph being transformed by Ladder Diagram.
Fig. 2 is the structural schematic diagram of tandem type branch.
Fig. 3 is the structural schematic diagram for adding vertex.
Fig. 4 is the example schematic diagram of a series connection BET tree forming process..
Fig. 5 is the Adj ' attributes on vertex 25 by 1-13 rows treated result figure.
Fig. 6 is the amalgamation result figure of Fig. 5.
Fig. 7 is the processing procedure and result figure of Fig. 6.
Fig. 8 is the common tail vertex that vertex 11 becomes vertex x1 and vertex 14.
Fig. 9 is the output process of caching figure as left subtree result of calculation.
Figure 10 is the process schematic that corresponding BET trees are formed.
Figure 11 is the data structure diagram in the Adj' attributes on vertex 25
Figure 12 is that the BET trees corresponding to Fig. 3 form procedure chart.
Figure 13 is instruction catalogue schematic diagram.
Specific implementation mode
The present invention is described in detail below with reference to the accompanying drawings and embodiments.
Initial vertax:In figure unique one be all connected to any vertex and in-degree be 0 vertex, use GsIt indicates, generally It is drawn in the left end of figure.White vertex in Fig. 1 is tandem type vertex, and grey vertex is parallel connection type vertex.Y0And Y1It is coil classes Type tandem type vertex.
Terminate vertex:In figure unique one can be reached from any vertex and out-degree be 0 vertex, use GtTable Show, is generally drawn in the right end of figure.In LDGraph vertex G is assisted for ease of introducing is uniformly processed to the vertex coilt, own The vertex of coil types is all injected wherein, shown in specific example such as Fig. 3 (1).Terminating vertex and the vertex auxiliary function is all It is added in figure G after artificial.Initial vertax and termination vertex mandatory provision are parallel connection type vertex, and the vertex of vcoil types is used Processing in the vertex auxiliary function, and other parallel connection type vertex do not have to setting functionType attributes, purposes generally Depending on will be with concrete application.In addition to assisting vertex, functionType attributes are known attribute, i.e., are determined with the given of figure G.
Tandem type branch:A path in figure between 2 parallel connection type vertex, the vertex which is passed through are series connection The both ends on type vertex, series branch are parallel connection type vertex, the two vertex are only two parallel connection type vertex in series branch. If ignoring tandem type vertex, every series branch is a line, actually constitutes one by series branch and parallel connection type vertex Width figure can use G'=<VP,EP>Indicate this figure.Series branch's distance of every series branch is 1, does not illustrate this method Middle distance is all referring to the v ∈ V in G'PTo GSDistance.
The tail vertex of series branch:First vertex in series branch, the vertex are a parallel connection type vertex.Series branch Tail vertex abbreviation tail vertex, be expressed as vt, it is clear that there is vt∈VP
The first vertex of series branch:The last one vertex in series branch, the vertex are a parallel connection type vertex.Series branch The referred to as first vertex in first vertex.Tail vertex can reach first vertex along series branch, and first vertex representation is vh, it is clear that there is vh∈VP
Minimum tail vertex and minimum series branch:In the series branch on all injection parallel connection type vertex, there must be one Its tail vertex of series branch is nearest apart from initial vertax compared with other tail vertex, which is known as minimum tail vertex, indicates For vtn.Series branch where minimum tail vertex is known as minimum series branch.Namely the minimum string between two parallel connection type vertex It is the maximum series branch of span to join branch;Minimum series branch is not unique, in Fig. 1,<1,2,25>With<1,3,4,5,25> All it is the minimum series branch on vertex 25, vertex 1 is the minimum tail vertex on vertex 25, and vertex 16, and 13,22,1 be all vertex 25 Tail vertex.
LDGraph is defined:Except GsAnd GtOutside, all parallel connection type vertex in DAG figures all meet, when injecting it along every When the side on tail vertex is reversely walked, its minimum tail vertex is all necessarily passed.For given figure G, converse digraph is denoted as GT.If In GTIn there are v1,v2Two vertex, from vertex v1It sets out and leads to GsIt has passed through v in path2, then claim v2Cover v1.DAG schemes not The phenomenon that will appear mutual covering.Minimum tail vertex completely covers other tail vertex in LDGraph.Only meet The Adj' lists of the figure that LDGraph is defined, each parallel connection type vertex can include just all information that can carry out parallel connection type merging. Fig. 1 is LDGraph, and Fig. 2 is not LDGraph figures, because for vertex 9, if vertex 3 is as minimum tail vertex, it is not covered Lid tail vertex 6, by the series branch on vertex 4 not by vertex 3.If vertex 6 can not be covered as minimum tail vertex Caping point 3, algorithm proposed by the present invention are served only for processing LDGraph.
Fig. 2:Non- LDGraph, if vertex 3 is used as minimum tail vertex, along the reversed of the tail vertex 6 for injecting vertex 9 When side is walked, by the series branch on vertex 4 not by the minimum tail vertex 3 on vertex 9.Equally, if vertex 6 is as most Small tail vertex can not cover vertex 3.
Can have the vertex function in LDGraph, for example, by Fig. 1 vertex 17 and vertex 23 become function The vertex of type.This kind of vertex and relay types vertex are entirely different, and the logical operation relationship output and input is to disconnect, It is considered that output and input it is not related because the output of the vertex function institute calling process can be boolean values Any value.In order to carry out processing to the vertex function need that the auxiliary vertex function and auxiliary are added in LDGraph figures The vertex relay.The rule of addition is that the tail vertex in the series branch where the vertex function is become to the top of vcoil types Point becomes the vertex auxiliary coil, while the vertex addition auxiliary relay is used to indicate on all output sides on the tail vertex The output of coil vertex is assisted as a result, its title is identical as the title on the tail vertex, but for convenience of description, with " tail vertex title " Add " ' " indicate, essence and the vertex relay are not different.Then on the tail vertex and vertex GtBetween addition it is auxiliary containing only one The series branch on the vertex function is helped, assists function vertex titles and tail vertex of the same name, but for convenience of description, is used "~" plus " tail vertex title " indicate.The effect that the series branch is added is that the calculating on the vertex vcoil is made to carry out in advance, to ensure When using the auxiliary vertex relay, these vertex have had result of calculation.But the introducing of this series branch can destroy tail Vertex covering principle, but since this case only can be in processing vertex GtWhen encounter, it is possible to pass through special processing procedure Handle this problem (see BUILD-SUBTREE3 processes).If the vertex 17 and vertex 23 in Fig. 1 become function types Vertex, assist shown in the addition example on vertex such as (2) in Fig. 3.Fine dotted line circle indicates the vertex auxiliary function in figure, slightly Circle of dotted line indicates that the vertex auxiliary relay, vertex 16 and 22 become to assist the vertex coil.
Caudal knot point and minimum caudal knot point:Each vertex can find corresponding node in BET trees in figure LDGraph, So vertex is with node, there are correspondences.Node comprising minimum tail vertex in tree is known as minimum caudal knot point, is expressed as ntn.And The node comprising other tail vertex is known as caudal knot point in tree.The converted corresponding BET subtrees of minimum series branch are known as most end BET subtrees, tree root are expressed as rtn.For the ease of discussing the node for being indicated to include the vertex with vertex symbols sometimes, such as Gt Node indicates to include GtThe node on vertex.
(1) in Fig. 3 is that Fig. 1 additions terminate vertex Gt, vertex 17 and vertex 23 in (2) Fig. 1 become function classes Behind the vertex of type, 2 vertex~16 auxiliary function of addition, the functionType attributes setting on~22, two vertex are needed For VSF, 3 auxiliary relay vertex 16', 16', 22'.The functionType attributes on parallel connection type vertex 16 and 22 are set as VCOIL。
The converted corresponding BET subtrees of branch are known as most end BET subtrees, and tree root is expressed as rtn.Have for the ease of discussing When with vertex symbols indicate include the node, GtNode indicates to include GtThe node on vertex.
Operation node and node of connecting:If the node in BET trees indicates operation, such as AND, OR, ST, EMPTY etc. then claim For operation node, * is used respectively in figure ,+, ST ,~indicate.The vertex that operation node is included is known as operation vertex, is expressed as vop, name attributes indicate operator, and functional attributes are set as OPERATOR, these vertex are all not belonging to figure G, i.e.,The node is series connection node if the vertex attributes of node are a tandem type vertex.
The merging on tandem type vertex merges with parallel connection type vertex:Upper each tandem type vertex of series branch is by AND The merging that node and ADD-NODE processes are carried out is known as becoming tandem type merging;To injecting every, vertex of parallel connection type tandem type point Branch is known as becoming parallel connection type merging by the merging that OR nodes and ADD-NODE processes are carried out.No matter which kind of merges, merging As a result a BET subtree can all be generated.
LD-BET algorithms are made of six parts.Figure G is read in first part.The connection on each vertex in figure is arranged in second part Attribute connectionType.Part III is figure addition auxiliary vertex.Part IV closes the vertex in series branch And Part V merges the series branch for injecting parallel connection type vertex.Each parallel connection type top in BET trees is unfolded in Part VI Point forms a BET tree for being free of parallel connection type vertex.Each section is made of one or more processes again.After the completion of each step The vertex color for scheming G will be reverted to white.
LD-BET
1read the graph G
2SET-CONNECTIONType
3ADD-AUXILIARY-VERTEX
4DFS
5BFS
6BUILD-TREE
First part includes the algorithm that ladder diagram is converted into LDGraph, format verification and discriminates whether it is LDGraph, but These algorithms are not in the row of discussion of the invention, and since discussion of the invention obtaining qualified LDGraph figures G.Divide below It is other that the parts 2-6 are described in detail.
SET-CONNECTIONTYPE(G)
SUB-SET-CONNECTIONTYPE(u)
Connection attribute is arranged for each vertex in the method that SET-CONNECTIONTYPE processes use depth-first search, If it is single-input single-output, then the connection attribute on vertex is set as connecting;Connection attribute is set as simultaneously if multi input or multi output Connection.1-3 rows are all vertex all painted whites that will be schemed in G, and its connection attribute is set as connecting.5th row starts vertex Gs Pressure is set as parallel connection type vertex.7-8 rows judge whether the out-degree on each vertex is more than 1, and if it is the vertex is parallel connection type Vertex;Current vertex u has been directed toward a grey vertex in the 13rd row, and grey in-degree of vertex must be more than 1, so the grey Vertex is arranged to parallel connection type vertex.The all of its neighbor vertex of 9th row opposite vertexes u is traversed, and the color category on these vertex is detected Property, whereinIndicate the adjacent vertexes of u.11st row is provided with vertex π attributes, and the father for recording vertex pushes up Point, this is current converse digraph (transposition figure) G for scheming GTFormation create condition.Whole process accesses all tops in figure G successively Point is primary, shows that the vertex had accessed if adjacent vertex is coated with grey, shows not to be accessed if it is white, At this moment can continue to access White vertex by recursive call SUB-SET-CONNECTIONTYPE processes.In all calculations of this method The color attribute on vertex all is used for recording the access state of certain an object in method.It can be obtained by the depth-first search run time of figure The run time of this process is O (V+E), write on the V in O and E respectively in expression figure G vertex number and number of edges.
ADD-AUXILIARY-VERTEX(G)
ADD-AUXILIARY-VERTEX processes create an auxiliary coil vertex set for including 0 element first Vcoil.All vertex coil and the vertex function in figure G, all vertex coil additions one of the 4th behavior are found out in 2-9 rows Item, which is injected, terminates vertex GtA line.The tail vertex of series branch where 6-9 rows find the vertex function, and be incorporated into To VcoilIt concentrates.Repetition is avoided using the variation of color attribute to be incorporated to.10-20 rows locate all vertex auxiliary coil successively Reason.13rd row creates the vertex auxiliary relay, and 14-16 is about to that the vertex relay is assisted to be added to and the adjacent series branch in tail vertex In, 17 rows change the connection attribute on tail vertex, become VCOIL.18th row creates the vertex auxiliary function, 19-20 rows The vertex function will be assisted to be added to the vertex vcoil and terminate in the series branch that vertex is connected.6th row simplifies find tails Some details on vertex can be reversed by the vertex π attribute function and find tail vertex, and the condition for stopping reverse search having two It is a:Encounter tail vertex or encounters the vertex function.Latter condition, which ensures in series branch, multiple vertex function When need to only handle a tail vertex.Therefore the run time of 1-9 rows is O (V+E), and total run time is also O (V+E).
ADD-NODE(op,leftChild,rightChild)
In the conversion of LDGraph to binary expression tree (binary expression tree), need to use ADD- NODE processes, the process can form the binary tree there are three node, tree root np, left child leftChild, right child rightChild.If left child or right child return to another child there are one being not present.If left and right child deposits Tree root is then being returned to, tree root is an operation node, this o'clock can be seen that from the 1st row and the 14th row.The operation vertex in the 2nd row Functional attributes be set as OPERATOR.8-13 rows have handled several special children, in respective operation vertex quilt It imparts different names, is illustrated in the discussion that the effects of these specific names can be below.17,18 exercise each y-bend Node can be able to conveniently find the father of oneself.The run time of this process is O (1).
DFS(G)
DFS processes merge all tandem type vertex in same series branch according to the sequence of depth-first search.7 rows Current vertex is packaged into node using NODE processes, a new subtree is formed by ADD-NODE processes, makes original BET trees The right subtree of tree root and the node of new packing respectively become the left and right child of the subtree tree root, are then grafted onto again original On tree root, the right child of atom tree tree root is become.The root of 6 enforcement current vertex is directed toward the root of its father vertex, so The root on each vertex of entire series branch is actually the root on the first tandem type vertex of the branch, all indicates to be formed by The tree root of BET subtrees.BET grows up constantly when being searched for along entire series branch, and the node newly created is with the identity of right child It is continuously added in BET, which constantly grows tall, until encountering parallel connection type vertex.The upper first tandem type top of series branch The processing of point is carried out in eighth row, and the vertex packaged by the left child of the BET generated is a parallel connection type adjacent with the vertex Vertex.From the 7th row can be seen that connect merge during left child there is invariance, so being incorporated to BET by eighth row The parallel connection type vertex of tree is exactly the tail vertex of entire series branch.BET trees corresponding to entire series branch are known as " series connection BET Tree ".9-11 rows carry out depth-first search, this puts similar with SET-CONNECTIONTYPE processes.Fig. 4 gives a series connection The example of BET tree forming processes.
In addition it is also necessary to topology distance be arranged for parallel connection type vertex, to carry out topological sorting to parallel connection type vertex.Below Vertex G is terminated in processingtWhen, it needs to know which vertex must be handled prior to other vertex.The setting of 1st behavior distance is just Value.13 and 14 rows are executed whenever encountering parallel connection type vertex.Apart from smaller more forward processing.It is run by the depth-first search of figure The run time that time can obtain this process is O (V+E).
In Fig. 4, one series branch of 1-5 vertex representations, vertex 1 and vertex 5 are parallel connection type vertex, and vertex 2-4 is series connection Type vertex.(1), (2), (3) describe the merging process on vertex in this series branch according to the operation order of algorithm.Light gray Circle indicates that the node in BST trees, " * " indicate concatenation operator AND.The root on all tandem type vertex in series branch belongs to Property finally both points to the tree root of generated BST.
BFS(G)
SKIP-SERIAL-VERTICES(u)
BFS processes handle all parallel connection type vertex in figure G according to the sequence of breadth first search.1-6 rows add 11-13 Row is typical breadth-first search, and the search for entirely scheming G starts from initial vertax Gs.ENQUEUE and DEQUEUE points Team is not represented and method of joining the team.1-13 rows carry out preliminary merging to parallel connection type vertex makes the series branch on injection parallel connection type vertex OR operations are formed, will being incorporated to by OR nodes for each series branch is formed by BET subtrees, all injection parallel connection type tops Point vhSeries branch corresponding to BET subtrees can be saved in vh.Adj' in, which is list, with adjacency list Structure it is similar, but in the list that requires emphasis each element order.8th, 9 row is used for finding first vertex v in series branchh。 SKIP-SERIAL-VERTICES processes for being scanned for along series branch, until encounter the first vertex in the branch and by its It returns.The father vertex for also setting met parallel connection type vertex along band during search, for tandem type vertex, the 2nd row category It is arranged in repetition, because the process of front is arranged the π attributes on tandem type vertex, but for first vertex Extremely important, because may have a plurality of series branch to inject first vertex, it is therefore necessary to specified currently connect with which item point for it Zhi Xianglian, this information can be obtained by returning to the π attributes on vertex, for convenience of description, headed by the vertex represented by title π attributes Father vertex, it is clear that first father vertex is a tandem type vertex.During BFS-PARALLEL-VERTICES, vhπ indicates current First father vertex in handled series branch, the BET subtree roots in root attributes corresponding to the in store series branch, Left child includes the tail vertex of the series branch.∪ indicate two lists it is orderly simultaneously, subsequent list element can be inserted successively Enter to the end of previous list or be inserted into a subsequent set element end of previous list.10th is about to first father vertex In series branch corresponding to the tree roots of BET subtrees be orderly merged into vertex vhAdj' in.vh.Adj' finally possess institute in There is injection vertex vhSeries branch corresponding to BET subtrees tree root.In Fig. 1, the Adj' attributes on vertex 25 are by 1-13 Row processing after its results are shown in Figure 5.
Fig. 5:For the vertex 25 in Fig. 1, after being handled by DFS-SERIAL-VERTICES, vertex 2,5,23,15, The tree root that respectively series connection BET subtrees have been saved in 18,19 root attributes, using the processing of the 1-13 rows of BFS processes, Its result is as shown in the figure.Each element in Adj' lists is represented sequentially as Adj'1,Adj'2……Adj'n, then Adj'1,Adj '2,Adj'3,Adj'4,Adj'5,Adj'6Correspond to 2.root, 5.root, 23.root, 15.root, 18.root, 19.root.
The tail vertex of series branch can be different, can also be identical, if the tail vertex in series branch is identical Series branch can be merged with operator OR in parallel, for the vertex 25 in Fig. 1, in its Adj' list 2.root and 5.root can merge, and 18.root and 19.root can merge.14-28 rows describe the specific implementation process of merging.14,15 Row finds all parallel connection type vertex in figure G, and then 18 rows reset parallel connection type vertex father vertex.Due to breadth first search Reason Adj' in the first stalk tree tree root Adj'1The left child vertex that is included be minimum series branch tail top The vertex is set as the father vertex of current parallel connection vertex u by point, therefore the father vertex on parallel connection type vertex is also minimum tail vertex.Example As being No. 1 vertex for its father vertex of vertex 25 in Fig. 5, rather than other parallel connection type vertex.19-25 rows are to parallel connection type vertex Adj' lists are traversed, the tree root of the series connection BET trees of the in store series branch for all injecting parallel connection type vertex of the list, It include the tail vertex of series branch in the left child of tree root.This two series connection if the tail vertex of Liang Tiao series branches is the same Branch can carry out the merging of or operations.21 rows judge whether two tail vertex are equal, and 22 rows are executed if equal, effect It is that two series connection BET trees are merged into a BET tree by OR operation nodes, the right child of two original trees respectively becomes new conjunction The left child of the left and right child of the right child of Cheng Shu, new synthesis tree can be the left children of any one tree in two original trees, Because they all include identical tail vertex.If the tail vertex of Liang Ge series branches is different, 23 rows are executed, it is by BET The tree root of tree is directly added into temporary table AdjTIn.Due to using the strategy that merges two-by-two, 24 rows and 25 rows have exchanged merging and It is merged role, this gets ready for further merging action.26, which are about to the last one amalgamation result, is saved in interim row Table A djTIn.27th is about to temporary table AdjTIn all elements reverse the right order so that the tail vertex closer from initial vertax (being included in the left child of BET subtree tree roots) more comes behind list, and range measurement unit here is series branch's number, Two its distances of parallel connection type vertex connected by a series branch are 1.Obviously minimum caudal knot point comes the last of list.28th Row resets Adj' attributes with combined achievement.The amalgamation result of Fig. 5 is as shown in 6 figures.
Fig. 6:"+", indicates operator OR in parallel.(1) result that 2.root, 5.root are merged by OR operation nodes. (2) 23.root is remained unchanged.(3) 15.root is remained unchanged.(4) 18.root, 19.root are closed by OR operation nodes And result.
It will be proven below for any one parallel connection type vertex vh, vh.Adj'n.left.vertex must be minimum tail top Point, wherein n indicate the index of the last one element in Adj' lists, and series branch merges by OR operation nodes When tail vertex be ordered into, i.e., the series branch representated by different tail vertex will not be alternately present, that is to say, that identical tail Other tail vertex are not present between vertex, so the case where being not in cross-combining.Such as the vertex 25 in Fig. 1, Merging sequence is not in centainly 2.root, 23.root, 5.root or 18.root, this arrangement feelings of 15.root, 19.root Condition, i.e. 2.root, 5.root mono- are set to one group, and 18.root, 19.root mono- is set to one group, do not have other tops between them Point, but sequence can be random order between every group of each tree.
Card:Due to the effect of the 9th row, 1~13 rows of BFS are actually to carry out breadth first search on figure G'.6~13 Row is to tail vertex vtAdjacent vertex vhIt is traversed, it is clear that vtWith vhDistance be 1, for a certain first vertex vhIf penetrated The tail vertex for entering series branch therein is identical, is vt, then mean vhWith vtBetween have heavy side.For there is heavy side to inject Head vertex vhCan continuously in its Adj' list record by weight the associated tail vertex in side information, so weight side ensure that it is identical Tail vertex must be adjacent in the Adj' lists on first vertex.And weight side can be merged by 14~26 rows in scheming G'.Separately Outside, since breadth first search is substantially according to apart from initial vertax GsShortest path carry out, so vertex Adj' row Arrangement of elements is ordered into table, and the order of each element is exactly tail vertex according to G in list after 28 rows have executedsBy as far as close Order, distance is more far away from Adj' lists more to front row, the processing through 27 rows, distance GsMore far away from Adj' lists more backward Row, and this is exactly desired by us, because subsequent algorithm requires minimum tail, vertex is finally handled.1~13 row is substantially figure G Breadth first search, run time is O (V+E), and the run times of 14~28 rows is O (V+EP), therefore when total operation Between be O (V+E).
BUILD-SUBTREE(u)
The main function of BUILD-SUBTREE processes is will to belong to parallel connection type vertex u and be stored in the series connection in Adj' point The preliminary merging achievement of branch further merges, and the series branch of injection parallel connection type vertex u is made all to form operation in parallel, and result is protected There are in u.root.The processing on single parallel connection type vertex is divided into three kinds of situations and carries out respectively.5 rows handle ordinary circumstance, are protected in np Deposit the tree root for being formed by BET subtrees.3 rows processing vertex is to terminate vertex GtThe case where.The case where 2 rows processing is to have deposited In the BET subtrees handled well, but need the pervious result of secondary use.Before the BUILD-SUBTREE invocations of procedure it is all and The root attributes on connection type vertex are all sky, if not being that empty explanation vertex is handled.The processing of three kinds of situations passes through difference BUILD-SUBTREE-3, BUILD-SUBTREE-2, BUILD-SUBTREE-1 subprocess is called to complete.
BUILD-SUBTREE-3(u)
During BUILD-SUBTREE-3, rtnIndicate the tree root of the most end BET trees of injection u, vtnIndicate u most Small tail vertex.3-6 rows initialize the tail vertex of each series branch in u.Adj' lists.All tail vertex are coated with ash Whether the color expression processing of color, vertex continues, if encountering grey vertex will stop handling.Buffer and buffer' belongs to Property is emptied.The BET subtrees that the two attributes generate temporarily when being all used for caching process parallel connection type vertex, but buffer' is corresponded to Handling result in the vertex vcoil, and buffer corresponds to the handling result on other parallel connection type vertex.7-28 rows utilize u.Adj' All subtrees in list are built into a BET tree.Building process is according to figure G'TDirected edge carries out, the direction on these sides and figure The direction on side is opposite in G'.So build path at this moment belongs to reverse build path, this builds BET subtrees with prior process Path is different.8, the 9 right children for being about to tree root are expressed as np, it is actually series branch's BET subtrees without tail vertex Tree root.The tail vertex representation of every series branch is at vt, series branch at this moment is the series branch after the merging of BFS processes, So being not in identical tail vertex in u.Adj' lists.Current tail vertex vtBy 10 row painted whites, so as to open Begin to handle the vertex, because all vertex are all initially grey.11st row is the BET subtrees for being cached current tail vertex and np Carry out merging in parallel.Because for can be preserved in the form of BET subtrees by the handling result on the tail vertex of current tail vertex covering In buffer, first have to pervious amalgamation result being merged in before being further processed current tail vertex.11st row Effect it is also understood that for be it is a kind of carried out according to vertex out-degree parallel connection type merging.12 and 15-17 rows are current vertex vtAs long as no encountering processed vertex just constantly along G'TSide search, tandem type is carried out once encountering parallel connection type vertex Merge, while handled parallel connection type vertex is added and is marked, indicates that the vertex has processed.Only located on each parallel connection type vertex Reason is primary, and it is primary to also imply that the tandem type generated by minimum tail vertex covering merging is only done.16th row passes through to working as sinciput Point vtMost end BET tree tree roots name modification show vertex vtBe processed, behind the 26th row pass through most end BET tree trees The name of root can detect whether minimum tail vertex needs series connection to be merged into BET subtrees.It is final corresponding to the u of vertex BET trees are all made of the BET subtrees in u.Adj' lists, but without worrying that BET trees are destroyed due to modification node name, Because we change be BET subtrees tree root title, and complete computable BET subtrees are its right children, this point from Eighth row can be seen that.13-14 rows show occur the case where violating covering principle if the vertex encountered has processed, It needs to terminate search immediately, and shows the appearance of the above situation by the blacking vertex.It is black that 18-22 rows, which handle tail vertex, Situation.If current tail vertex functionType attributes are VCOIL, at this moment need that BET that 12-17 rows are generated will be run Tree, the tree root of subtree are stored in np, and parallel connection is merged into the BET subtrees that minimum tail vertex buffer' attributes are cached.Most All injection vertex vs eventuallytSeries branch parallel connection is all merged into v if its tail vertex is the vertex VCOILt.buffer' institute In the BET subtrees of caching.The functionType attributes on parallel connection type vertex are if not VCOIL, then the caudal knot point first has to go here and there Connection is merged into interim BET subtrees np, and amalgamation result parallel connection, which is then merged into minimum tail vertex buffer attributes, again is cached BET subtrees in.Final all injection vertex vstSeries branch, if its tail vertex is non-VCOIL Black vertices, all will close And arrive vt.buffer in the BET subtrees cached.The case where 23-24 rows processing minimum tail vertex, since 11 rows are first carried out, Therefore the BET subtrees that buffer attributes are cached do not have to reprocessing.The non-minimum tail vertex of 25 rows processing encounters most in search The case where small tail vertex, this is most cases.At this moment current vertex vtIt is exactly minimum tail vertex vtn, interim BET trees are simultaneously combined And in the BET subtrees cached to buffer attributes.After all tail vertex have been handled in u.Adj' lists, handling result is protected There are in buffer the and buffer' attributes on minimum tail vertex.For the subtree in buffer, at this moment need to determine whether to by Minimum tail vertex series connection is merged into BET trees, is affirmative reply under normal circumstances.But if being minimum tail vertex through it His path has been handled or minimum tail vertex is VCOIL types vertex, then no longer needs to carry out tandem type merging to minimum tail vertex.26- 27 rows complete the above process.Since it is desirable that minimum caudal knot point is nearest from tree root, it will be added to by AND' operation nodes In the BET subtrees of buffer cachings.Final minimum caudal knot point becomes the right child of the BET subtree tree roots.AND' operations node is real It is exactly AND operation node on border, additional effect is labeled to the node, to show that the right child of this node is one A minimum caudal knot point.It should be noted that in BET subtrees, the position of minimum caudal knot point is different from the position of other caudal knot points, preceding Person is right child and the latter is left child, during this design feature can be used in then.28 rows finally buffer and Two BET subtrees in buffer' carry out parallel connection type merging, then return it into.With different cache attributes to BET subtrees into The purpose of row caching is to ensure that the subtree in buffer' by priority processing, because BET trees are always according to first left and then right order It is handled and is accessed, so the order of the merging parameter of 27 rows meets requirement of the subtree in buffer' by priority processing. The processing procedure of Fig. 6 and the results are shown in Figure 7, wherein node 1 is minimum caudal knot point.
Each parallel connection type vertex is only primary by processing, i.e., goes to all series branches therein to only form a BET injection Subtree, but in fig. 8, vertex x1 or vertex 14 are required for the result on vertex 11.If vertex 11 is not minimum tail vertex, It is handled as black tail vertex during BUILD-SUBTREE-3.If vertex 11 is minimum tail vertex by BUILD- The processing of SUBTREE-1 processes.
BUILD-SUBTREE-1(u)
Fig. 7:Adj'1,Adj'2,Adj'3,Adj'418.root, 15.root, the 23.root in Fig. 6 are corresponded to respectively, 2.root。rtnFor 2.root, vtnFor vertex 1.(1)vtFor vertex 16, after the row of 15-17,12 and 25 has executed, vtFor vertex 13, vt.buffer the result in is as shown.(2)vtResult after having been executed for 13,11 row of vertex in np is as shown.(3)vtFor vertex Result after 13,15 rows have executed in np is as shown, at this moment vtFor vertex 13.(4)vtFor vertex 13,16,17,12 rows then again Result after 15 rows have executed in np is as shown.Next 16,17,12 rows are executed again, at this time vt==vtn, then execute 25 Row, the result of np are stored in vtn.buffer in.(5)vtThe result of np is same after having been executed for vertex 22,11 and 15-17 rows 23.root, the result after 25 rows have executed is as shown, and result is equally stored in vtn.buffer in.(6)vtFor vertex 1,11 The result of np is as shown after row has executed, which is stored in v after the execution of 24 rowstn.buffer in.(7)vtFor vertex 1,27 Result after row executes is as shown.
If root attributes be it is empty if the vertex accessed for the first time, if had existed in root BET trees (general BET's Tree root be operator node) but root node corresponding to vertex title be not parallel connection type vertex title then indicate the 2nd time access, no Meet access of the expression 2 times of above-mentioned 2 kinds of situations or more to the vertex.Processing corresponding to 3 kinds of situations is to generate BET subtrees, Caching vertex, direct return cache vertex are added for BET subtrees.First processing is completed by BUILD-SUBTREE-3 processes, and Latter two processing is completed by BUILD-SUBTREE-1 processes.During BUILD-SUBTREE-1, the 2nd row is found currently first The father π of the root node for the BET subtrees that vertex is preserved, it gets ready for subtree is added back again.If residing The parallel connection type vertex u of reason is processed, then needs by ST nodes caching u.root's as a result, final right with parallel connection type vertex institute The parallel connection type node answered substitutes the BET subtrees in root attributes.Np in 5th row is the tree root of a BET subtree, the ground of caching Location is provided by the right child of np, i.e. the name attributes of u provide.This is feasible because to scheming top all in G pre-processings Point all has been assigned different names, and parallel connection type vertex name has been assigned different numbers.It is in parallel to improve space efficiency Buffer address represented by the name on type vertex may finally need to be optimized, so that these address arrangements are together, composition One continuous space, but this partial content is not in the row of this method discussion.The result of calculation of the left children of np will pass through ST nodes It is saved in right child, when needing the result of original left child again, directly gives right child.6-8 rows are 5 row institutes The BST trees newly formed are added to again in original BST trees, if original subtree u.root is that right child is present or right child Otherwise son is exactly left child.When encountering processed parallel connection type vertex the 2nd time, BST trees are than first treated same vertices Shi Chang great many, at this moment the subtree pointed by u.root is one of branch, in order to the original result of branch into Row caching, 5-8 rows are practical, and do is to shear off the subtree pointed by u.root, by the grafting of ST nodes with current vertex name The referred to as caching vertex of buffer address, then take back in original BET trees.9th enforcement u.root has been directed toward a new node, should The title on the included vertex of node reveals the information of buffer address.The application of cache node can be understood as to the excellent of BST Change, because can only carry out the calculating of primary really expression formula when the result of same stalk tree is used for multiple times, calculates knot Fruit repeatedly can directly use afterwards, it is not necessary to reprocess.This optimization is mainly completed by the above process.3rd, 4 rows are handled Be if π itself is a ST node, do not have to for subtree addition caching because caching have existed for, at this moment only need Return cache address, the address are the names on the included vertex of the right child of current node.It is not difficult to find out, the fortune of whole process The row time is O (1).
The position for carrying out node is needed to adjust when u.functionType is TERMINAL in BUILD-SUBTREE, but At this moment node parent pointer need not be safeguarded, because these nodes are all GtThe child of node, it is impossible to be quoted again by other nodes.
BUILD-SUBTREE-2(u)
BUILD-SUBTREE-2 processes are for handling the vertex TERMINAL Gt, the 1st row opposite vertexes G firsttIn all tails Vertex is ranked up according to the d attributes on tail vertex, and tail vertex passes through Gt.Adj' the left child of each subtree tree root obtains in list, SORT is actually to carry out topological sorting to these tail vertex, may insure that the apex ratio for coming front comes subsequent top in this way Point is first handled, so that subsequent vertex can utilize the generation of forward apex as a result, because GtIn tail vertex may and be discontented with The relationship of sufficient vertex covering.2-10 rows are to Gt.Adj' all subtrees in list are traversed, if the root node of subtree is not ST nodes, then need execute 4-7 rows " left rotating " operation, so as to the vertex of coil types from series branch It separates, becomes the output caching of left subtree result of calculation, process is as shown in Figure 9.It should be noted that coil Type vertex operation node used when merging is ST, can be seen that this point from ADD-NODE processes.
Fig. 8:Vertex 11 becomes the common tail vertex of vertex x1 and vertex 14
The position for carrying out node is needed to adjust when u.functionType is TERMINAL in BUILD-SUBTREE, but At this moment node parent pointer need not be safeguarded, because these nodes are all GtThe child of node, it is impossible to be quoted again by other nodes.
BUILD-SUBTREE-2(u)
BUILD-SUBTREE-2 processes are for handling the vertex TERMINAL Gt, the 1st row opposite vertexes G firsttIn all tails Vertex is ranked up according to the d attributes on tail vertex, and tail vertex passes through Gt.Adj' the left child of each subtree tree root obtains in list, SORT is actually to carry out topological sorting to these tail vertex, may insure that the apex ratio for coming front comes subsequent top in this way Point is first handled, so that subsequent vertex can utilize the generation of forward apex as a result, because GtIn tail vertex may and be discontented with The relationship of sufficient vertex covering.2-10 rows are to Gt.Adj' all subtrees in list are traversed, if the root node of subtree is not ST nodes, then need execute 4-7 rows " left rotating " operation, so as to the vertex of coil types from series branch It separates, becomes the output caching of left subtree result of calculation, process is as shown in Figure 9.It should be noted that coil Type vertex operation node used when merging is ST, can be seen that this point from ADD-NODE processes.
Fig. 9:YnIt is the vertex of a coil type, (2) are the results of (1) left rotating.
Since the vertex of the coil types in series branch always comes finally, all its corresponding knots in BET subtrees Point must be the right child of ST nodes, and a in Fig. 9 is minimum tail vertex, and a and b again send result after should carrying out series connection merging Enter coil types vertex.8-10 is about to coil types vertex and vcoil types vertex merges respectively, due to every series connection point Branch is all independent output branch, is carried out by EMPTY nodes so merging, which shows to merge two branches mutual It is not related, independently of one another.11 rows merge np subtrees and np' subtrees, np' subtrees be left child show the subtree prior to The processing of np subtrees.Since the run time of " leftrotating " operation and ADD-NODE processes is O (1), so 2-10 rows Run time is O (VP), the run time of the 1st row is by right | VP| the algorithm that a vertex is ranked up determines, might as well set sort algorithm Run time be O (VPlgVP), so the run time of BUILD-SUB-TREE2 processes is determined by the sort algorithm of the 1st row, For O (VPlgVP)。
BUILD-TREE(G)
1np=BUILD-SUBTREE (Gt)
2WALK-PARALLEL-NODE(np)
3return np
WALK-PARALLEL-NODE(n)
In addition to terminating vertex, it is all tail vertex to scheme all parallel connection type vertex in G, they all with respective BET subtrees phase Corresponding, the tree root of subtree is stored in its root attribute.In the BET trees being ultimately formed each tail vertex have accordingly by Node pointed by its root attribute.BUILD-TREE processes are to establish the BET trees terminated corresponding to vertex, and the tree is namely most Required BET trees eventually, but also include there are many caudal knot point in setting at this time, these nodes are needed by WALK-PARALLEL- NODE processes recursively construct BET subtrees corresponding with these nodes, until caudal knot point is not present in BET trees.WALK- PARALLEL-NODE processes carry out preorder traversal to all nodes in BET subtrees, and the input parameter n of the process is the knot of BET Point, that is, if when the condition of 3 rows or 8 rows meets, is needed by BUILD-SUBTREE mistakes when traversing a certain caudal knot point The BET subtrees of input parameter is in the tail vertex that journey structure is included using caudal knot point, so BET trees will whenever encountering caudal knot point Growth.The strategy that whole process uses is first to build to traverse again, so first to judge its left and right child when carrying out further traversal Whether son is caudal knot point, if it is builds BET subtrees, and then the tree root again along new subtree is traversed.The father of caudal knot point ties Point is all operation node, so needing the judgement of the 2nd row.3-7 rows handle the case where left child, and 8-12 rows handle the feelings of right child Condition.5,6 rows and 10, the information of the tree root addition father node of the new subtree of 11 behaviors.7,12,16,17 rows complete typical first sequence time Go through function.13-15 rows handle minimum caudal knot point, since minimum caudal knot point is the right child of its father node, so traversal It finally being traversed when new subtree, this conforms exactly to the processing sequence of caudal knot point, i.e., minimum caudal knot point must be handled finally, because It is nearest from node is terminated, but this is different from execution sequence.Final BET trees will execute according to first left and then right order, so The father node and then left and right child that minimum caudal knot point must be found are exchanged.The use of operation node and' can facilitate us to realize AND' is finally reduced into AND by above-mentioned task, 15 rows.Complete BET trees can be returned after BUILD-TREE processes have executed Tree root.If the input parameter G of BUILD-TREE (G) process is Fig. 1, the forming process of the BET trees corresponding to the figure is as schemed Shown in 10.
Figure 10 is the process that the BET trees corresponding to Fig. 1 are formed.(10) in Figure 10 are original parallel connection type node by with grey Node is replaced by the subtree of tree root.
(1) is that the 1st row executes as a result, then according to first left and then right preorder traversal during BUILD-TREE in Figure 10 Secondary ordered pair BET trees (1) are traversed, and can encounter parallel connection type vertex 25 first, then BUILD-SUBTREE are called to build the vertex BET subtrees, shown in (7) in result such as Fig. 7.Then this new subtree is traversed again, if encountering parallel connection type top Point just calls BUILD-SUBTREE to build the BET subtrees on the vertex, and the progress of this process recurrence is until no parallel connection in BET trees Until type vertex.Serial number in Figure 10 indicates the sequence of parallel connection type vertex processing, and light vertex is replaced by BET subtrees below Generation.Since vertex 25 is accessed 2 times so needing to add ST operation nodes, it is by left that the AND operation that thick line indicates, which accords with, The result of rotating processing.And vertex 25 is finally formed by BET trees from BET trees shown in (7) in Fig. 7, becomes in Figure 10 (9) shown in BET trees.The more operator nodes of BET trees shown in (7) in Figure 10, it is extra caused by this is initial vertax Node sky node can be converted thereof by DELETE-REDUNDANCE-NODE processes.
If the vertex 17,23 in Fig. 1 becomes the vertex function, as shown in figure 3, the then shape of the BET trees corresponding to it It is as shown in figure 12 at process.Wherein (1) is to terminate vertex G after executing the 1st rows of BUILD-SUBTREE-2tAttribute Adj' number According to structure.(2) it is that BET trees are formed by after the above process has executed, the tree root of the tree is finally assigned during BUILD-TREE It is worth to np, then BET trees is traversed according to the order of first left and then right preorder traversal.It is just called whenever encountering parallel connection type vertex BUILD-SUBTREE processes, to build the BET subtrees on the vertex, this process recurrence is carried out until no parallel connection in BET trees Until type vertex.Serial number in Figure 12 indicates the sequence of parallel connection type vertex processing, and light vertex is replaced by BET subtrees below Generation.Since vertex 22,16,25 is accessed repeatedly so needing to add ST operation nodes, thick line node indicates to include function The node on vertex, dotted line node indicate to include the node on the vertex auxiliary relay.(11) the BET trees being ultimately formed are indicated.Below Illustrate the forming process of the BET trees of (9).
Figure 11:Data structure in the Adj' attributes on vertex 25.Wherein, thick line node is indicated comprising the vertex function Node, dotted line node indicate to include the node on the vertex auxiliary relay."+" node indicates to merge the parallel connection of identical caudal knot point.
For vertex 25, by the processing of BFS, the data structure of attribute Adj' is as shown in figure 11.Then it calls BUILD-SUBTREE-3 constructs the BET trees on vertex 25.Minimum tail vertex vtnFor vertex 1, rtnFor 2.root.Tail vertex when beginning vtFor vertex 16, when 13 rows are judged, condition is true, because the vertex VCOIL is handled prior to vertex 25.Next operation The right subtree of 20 rows, 18.root is saved in the buffer' attributes on vertex 1.Then the 7th row is executed, tail vertex becomes vertex 13, by executing 12 rows and 15-17 rows, tail vertex is constantly moved to minimum tail vertex, and the parallel connection type vertex that will be met on the way Series connection is merged by the interim BET subtrees representated by np.BET trees will be finally formed by and be saved in tail vertex vtBuffer In, tail vertex v at this momenttFor minimum tail vertex 1.Next the 7th row is executed, tail vertex becomes vertex 23, and processing procedure is same The process for handling vertex 16 is similar, and when only executing 20 row, since the buffer' on minimum tail vertex at this time is not empty, result is also It needs to merge with the progress parallel connection of the result on vertex 16, forms the left subtree represented by Figure 12 (9).Then the 7th row, tail vertex are executed Become minimum tail vertex 1, executes the left subtree of right child of the formed BET trees as represented by Figure 12 (9) after 11 rows.Due to the 26th Condition be true so minimum tail vertex is merged by the series connection of the 27th row in BET trees, right son of the formation as represented by Figure 12 (9) Tree.28th result for being about to buffer' and buffer carries out parallel connection type merging, forms the BET subtrees as represented by Figure 12 (9).
Since tandem type vertex only has an initial edge and a terminal edge in LDGgraph figures, and parallel connection type vertex it Between cannot be connected directly, so having | VP|<|VS+ 2 |, then O (VP)=O (VS), O (E)=O (VS), it can finally obtain:O(V) =O (V+E)=O (VS)。
Even if we increase some auxiliary vertex and auxiliary side (1) formula is still set up, because of the number on the vertex auxiliary relay Amount does not exceed number of edges, and the quantity on the vertex auxiliary function does not exceed | VS|.If not considering process BUILD- Sequencer procedure in SUBTREE-2, for BUILD-TREE processes, each vertex for scheming G is traversed to, and tandem type vertex is only It is accessed once.Parallel connection type vertex as tail vertex can be accessed repeatedly, but the number accessed is by the pact of its incidence edge Beam, so total access times on parallel connection type vertex are O (E), while in view of the BET trees for constructing each parallel connection type vertex only carry out Once, the main process constructed is to replace parallel connection type vertex with the subtree that tandem type node is leaf node, so to parallel connection type Vertex total processing time is O (VP+ E), then total processing time is O (V+E), and according to (1) formula, there is BUILD-TREE processes Processing time be O (VS), i.e. the processing time of the process is only linearly related with tandem type number of vertices.If it is considered that process Sequencer procedure in BUILD-SUBTREE-2, then the run time of BUILD-TREE processes is by GtThe sorting time on tail vertex It determines, the run time of sequence is O (VSlgVS), because of O (VP)=O (VS)。
DELETE-REDUNDANCE-NODE(n)
DELETE-REDUNDANCE-NODE processes carry out preorder traversal to BET trees, pass through the 3rd when encountering redundant nodes Row and the 5th row are set to sky node, and to ensure that its left child is not empty after emptying, to facilitate BET trees to be converted into instructing The processing of table.In addition to leaf node, when there is left child or right child is empty node, the node is just identified as redundant nodes.Figure Processing of the BET trees Jing Guo DELETE-REDUNDANCE-NODE processes in 10 (10) and Figure 12 (11), the father node of node 50 All become sky node.
So far, the processing that BET trees are converted by LDGraph is fully completed.It can be easily by its turn after obtaining BET trees It changes various instruction catalogues into, the method that BET trees are converted into meeting the instruction catalogue of IEC 61131-3 specifications is given below.
OUTPUT(n)
OUTPUT processes carry out inorder traversal to BET trees, are answered according to the property the output phase of encountered node in ergodic process Instruction code.When being converted to right subtree, needed for instruction addition bracket if not isolated node.7-9 rows are to meeting knot Point is judged that if it is non-orphaned right subtree, and tree root is operation node AND or OR, then needs to add for the subtree right Bracket, and left bracket is added by PRINT-INSTRUCTIONS processes.
PRINT-INSTRUCTIONS(n)
During PRINT-INSTRUCTIONS, 2-14 rows carry out instruction code conversion, 16-28 rows pair to right subtree tree root Left subtree tree root carries out instruction code conversion.Two kinds of conversion methods are very similar, only to right subtree tree root be non-isolated node simultaneously And be operation node AND or OR conversion need add left bracket.If print sentences terminate to indicate printing out with ", " It after the completion plus space but does not enter a new line, is indicated after the completion of printout without any terminating symbol plus line feed.How to be function The vertex of type then executes 7-9 rows or 21-23 rows, and EN and ENO indicate two buffer address, is respectively used to the tops caching function The input and output value of point.ST EN indicate the value of A being put into EN if master register is indicated with A, when by CAL instruct into When row funcall, the subprocess of CAL instruction calls can obtain input first from EN, subprocess then be executed, finally fortune Capable result is stored in ENO.The value of ENO is put into A by LD ENO expressions, then passes through EN, two buffers of EN, logical expression Formula is established with subprocess and is contacted.If it is the node then output vertex title of ST types, at this moment the title on vertex is exactly " ST ". If it is empty node then without any printing.If it is the name of the node then direct output vertex of relay types.
If Figure 13 is instruction catalogue, if only occurring a character string in a row in instruction catalogue, as thick in instruction catalogue The case where body is shown then also needs to add " LD " character string before this instruction character string, this processing is fairly simple, specific Process repeats no more.Although OUTPUT processes are directed to specific instruction format, its method without loss of generality, only need pair Corresponding instruction format, which makes an amendment, during PRINT-INSTRUCTIONS can meet the output requirement of different instruction table.
Conclusion:
The introducing of vertex covering concept enables us to more accurately define LDGraph figures, so as to more precisely Define the scope of application of this method algorithm.LDGraph figures can be converted into BET trees by 6 processes of LD-BET algorithms, Classify according to function and connection relation on vertex in LDGraph figures.The vertex function is needed for its addition auxiliary Vertex terminates vertex G to handle the noncontinuity on the vertex functiontIntroducing so that the processing on coil types vertex is become more For convenience.On the basis of vertex classification, by the algorithm based on depth-first search to the tandem type vertex in series branch Carry out series connection merging;Merging in parallel is carried out to the tail vertex for injecting parallel connection type vertex by the algorithm based on breadth first search. Each parallel connection type vertex might have multiple tail vertex but only there are one minimum tail vertex, when the merging on all tail vertex all reaches When minimum tail vertex, the in parallel of parallel vertex merges just calculation completion.Parallel connection, which merges to start from, terminates vertex Gt, amalgamation result is one BET trees containing parallel connection type node carry out traversal to the tree and the parallel connection type node to being encountered call the process in parallel merged, Ultimately generate a BET tree for being free of parallel connection type node.The run time for generating BET tree algorithms is O (VS), to output vertex Sequence run time take into account if run time be O (VSlgVS)。
After BET trees are formed, IL can be generated by carrying out simply traversing to it, although this method gives generation and meets The example of the instruction catalogue of IEC 61131-3 specifications, but the IL for meeting any specification can be generated according to similar method.Introduce one A stack architecture combines a postorder traversal to the BET trees of generation, can directly calculate the logic operation result of BET trees, from And the generating process that can skip IL tables in practical applications is directly calculated.
Figure 12:The process that BET trees corresponding to Fig. 3 are formed.(1) in before vertex~symbol is for ease of indicating the vertex It is an auxiliary function vertex, the title on practical vertex is to remove the title of tilde, so being assisted in (1) later figure The auxiliary prefix on vertex is all removed.(9) dotted line node and in (11) indicate it includes vertex be the vertex auxiliary relay, It is different from Fig. 3 but be consistent with actual conditions, vertex title do not add auxiliary suffix " ' ".Thick line node indicate it includes vertex It is function nodes.(11) original parallel connection type node is replaced using grey node by the subtree of tree root in.

Claims (3)

1. a kind of method that the ladder diagram handling function vertex is converted into instruction sequence, it is characterised in that:In this method:Scheme G =<V,E>It is combined by the collection of one group of limited vertex V and side E;If G is a figure, then V=G.V indicates the vertex in figure Collection, E=G.E indicate the side collection in figure;Any one ladder diagram is all expressed as an i.e. DAG of directed acyclic graph;It is additionally necessary Meet some constraintss, the DAG figures referred to as LDGraph that disclosure satisfy that these constraintss;
2 objects are used in LD-BET methods, one is the node for describing BET trees, another is for describing The vertex of LDGraph;Node object includes vertex, left, right, π attributes, and node set is denoted as N;Constitute the institute of BET trees There is node to constitute a node set NBET, andVertex attributes indicate the vertex that node is included, that is, indicate The node is corresponding with which vertex in figure;Left indicates that left pointer, right indicate that right pointer, π indicate parent pointer, all fingers Needle is directed toward other nodes in BET trees;The unspecial attribute of name of node object, node name is with including vertex therein The attribute of name of object indicates;Node object is created by NODE (vertex) method, makes three knots by ADD-NODE methods Point all becomes to belong to NBETNode;Vertex objects include name, Adj, Adj', buffer, buffer', root, π, d, Color, conntionType, functionType attribute;Vertex title is indicated that Adj indicates the adjoining on vertex by name attributes Table;The form of figure adjacency list describes, and a set { Adj is represented for its adjacency list of vertex v v.Adj1,Adj2,……, Adjn, wherein Adji∈ V, i=1,2 ... ..., n;The set expression has one each element from v to set v.Adj Directed edge;Each element in the adjacency list vertex1.Adj on vertex 1 be vertex 2, vertex 3, vertex 6, vertex 7,vertex 10,vertex 20,vertex 21};Adj' is a chained list, and parallel connection type vertex is injected for collecting Series branch, series branch it is in parallel merge to use it;One ordered sequence is represented for its chained list of vertex v v.Adj'< Adj'1,Adj'2,……,Adj'n>, wherein Adj'i∈NBET, i=1,2 ... ..., n;Ordered sequence indicates every from v to sequence There are the series branch of an injection v, ordering to represent the sequencing of injection between one element;Buffer, Buffer' is used to cache intermediate result when generating BET subtrees;Root indicates the root with the relevant BET subtrees in the vertex;π tables Show the father vertex on vertex;The distance that d is used to indicate vertex to initial vertax;Color is used for identifying the access state on vertex, so as to Judge whether vertex has been accessed in ergodic process;Vertex objects are created by vertex (name) method, parameter list Show the name attributes on vertex.
2. the method that a kind of ladder diagram handling function vertex according to claim 1 is converted into instruction sequence, special Sign is:Classify according to connection relation and vertex is divided into tandem type vertex and parallel connection type vertex;Tandem type vertex:In figure in-degree and Out-degree is all not more than 1 vertex, uses VSIt indicates;Parallel connection type vertex:In-degree is more than 1 or vertex of the out-degree more than 1 in figure, uses VPTable Show;VS∪VP=G.V;Connection relation is classified to be indicated by vertex attribute connectionType, corresponding value Respectively SERIAL, PARALLEL indicate tandem type vertex and parallel connection type vertex respectively.
3. the method that a kind of ladder diagram handling function vertex according to claim 1 is converted into instruction sequence, special Sign is:Vertex is divided into initial vertax according to function classification, terminates vertex, the vertex relay, the vertex coil, the tops function Point, the vertex auxiliary function, the auxiliary vertex relay and the vertex auxiliary coil;The classification is by vertex attribute functionType It indicates, corresponding value is respectively GS, GT, RELAY, COIL, FUNCTION, VSF, RELAY, VCOIL, corresponding connection relation Respectively:Parallel connection, it is in parallel, it connects, connects, connect, connect, series connection is in parallel.
CN201711488500.4A 2017-12-30 2017-12-30 Method for converting ladder diagram capable of processing function vertex into instruction sequence Active CN108595208B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711488500.4A CN108595208B (en) 2017-12-30 2017-12-30 Method for converting ladder diagram capable of processing function vertex into instruction sequence

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711488500.4A CN108595208B (en) 2017-12-30 2017-12-30 Method for converting ladder diagram capable of processing function vertex into instruction sequence

Publications (2)

Publication Number Publication Date
CN108595208A true CN108595208A (en) 2018-09-28
CN108595208B CN108595208B (en) 2021-11-26

Family

ID=63633516

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711488500.4A Active CN108595208B (en) 2017-12-30 2017-12-30 Method for converting ladder diagram capable of processing function vertex into instruction sequence

Country Status (1)

Country Link
CN (1) CN108595208B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112180817A (en) * 2019-07-02 2021-01-05 北京东土科技股份有限公司 Method, device, equipment and storage medium for transforming ladder diagram into binary tree
CN112327744A (en) * 2020-11-20 2021-02-05 深圳市海浦蒙特科技有限公司 Method for interconverting ladder diagram and instruction list for programmable logic controller

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020040286A1 (en) * 2000-10-02 2002-04-04 Akihiro Inoko PLC system construction support tool and PLC system program development support tool including the same
CN1588256A (en) * 2004-09-23 2005-03-02 艾默生网络能源有限公司 Method and system for changing ladder diagram program into instruction listing program
US20080091931A1 (en) * 2006-08-08 2008-04-17 Mcnutt Alan D Devices, systems, and methods for assigning a PLC module address
CN101369234A (en) * 2008-06-24 2009-02-18 杭州电子科技大学 Method for compiling ladder diagram language into instruction list language according to IEC61131-3 standard
CN102354144A (en) * 2011-09-06 2012-02-15 北京联合大学 Method for converting ladder diagram into PLC (Programmable Logic Controller) program command
CN102708126A (en) * 2011-02-28 2012-10-03 微软公司 Data visualization design and view systems and methods
CN102736552A (en) * 2012-07-01 2012-10-17 西北工业大学 Method for converting ladder diagram developed by programmable logic controller (PLC) into statement list
CN107193534A (en) * 2017-05-15 2017-09-22 华南理工大学 A kind of method that PLC ladder diagrams are converted into instruction catalogue and explain execution

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020040286A1 (en) * 2000-10-02 2002-04-04 Akihiro Inoko PLC system construction support tool and PLC system program development support tool including the same
CN1588256A (en) * 2004-09-23 2005-03-02 艾默生网络能源有限公司 Method and system for changing ladder diagram program into instruction listing program
US20080091931A1 (en) * 2006-08-08 2008-04-17 Mcnutt Alan D Devices, systems, and methods for assigning a PLC module address
CN101369234A (en) * 2008-06-24 2009-02-18 杭州电子科技大学 Method for compiling ladder diagram language into instruction list language according to IEC61131-3 standard
CN102708126A (en) * 2011-02-28 2012-10-03 微软公司 Data visualization design and view systems and methods
CN102354144A (en) * 2011-09-06 2012-02-15 北京联合大学 Method for converting ladder diagram into PLC (Programmable Logic Controller) program command
CN102736552A (en) * 2012-07-01 2012-10-17 西北工业大学 Method for converting ladder diagram developed by programmable logic controller (PLC) into statement list
CN107193534A (en) * 2017-05-15 2017-09-22 华南理工大学 A kind of method that PLC ladder diagrams are converted into instruction catalogue and explain execution

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
YI YANG .ETC: "Compiling Ladder Diagram into Instruction List to comply with IEC 61131-3", 《COMPUTER IN INDUSTRY》 *
傅亮等: "《基于串并联归并的PLC梯形图向指令表转换算法》", 《计算机工程与应用》 *
林懋恺等: "PLC梯形图的广义表转换", 《计算机工程》 *
秦华等: "基于IEC61131-3标准的PLC梯形图检查模块设计与实现", 《广西科学院学报》 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112180817A (en) * 2019-07-02 2021-01-05 北京东土科技股份有限公司 Method, device, equipment and storage medium for transforming ladder diagram into binary tree
CN112327744A (en) * 2020-11-20 2021-02-05 深圳市海浦蒙特科技有限公司 Method for interconverting ladder diagram and instruction list for programmable logic controller

Also Published As

Publication number Publication date
CN108595208B (en) 2021-11-26

Similar Documents

Publication Publication Date Title
US7899883B2 (en) Merging versions of documents using multiple masters
Malaguti et al. A metaheuristic approach for the vertex coloring problem
Bodlaender A partial k-arboretum of graphs with bounded treewidth
Luckman An approach to the management of design
CN103259718B (en) A kind of stream table conversion method and device
US4951225A (en) Updating pattern-matching networks
CN111027702B (en) Method and device for realizing quantum circuit replacement, storage medium and electronic device
CN109697500A (en) Data processing method, device, electronic equipment and storage medium
CN108595208A (en) A kind of method that the ladder diagram handling function vertex is converted into instruction sequence
Wouters et al. A practical walkthrough of the ontology derivation rules
CN108614515B (en) method for converting PLC ladder diagram into instruction list based on logistics production line control
Vetta Approximating the minimum strongly connected subgraph via a matching lower bound
CN105975694B (en) The method that building solves the problems, such as the cascade Bayesian network of multiple shot array
Brzozowski et al. A characterization of ternary simulation of gate networks
CN106200541B (en) Method for converting function block diagram into AOV structure
Kuwashima Followers of Harvard Study A Review of Product Development Research 1990s-2000s
Kumar et al. On oriented diameter of (n, k)-star graphs
Aldis On balance
Obraztsova et al. On swap-distance geometry of voting rules
CN110597194A (en) Cooperative activity construction method of large-scale flexibly-driven automatic manufacturing system
Iwama et al. A simpler parallel algorithm for graph connectivity
Mejía et al. A Petri Net based algorithm for minimizing total tardiness in flexible manufacturing systems
Detzner et al. PFDL: A production flow description language for an order-controlled production
Cooper et al. The travelling salesman problem in cP systems
CN110162531A (en) A kind of distribution concurrent data processing assignment decisions method

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
GR01 Patent grant
GR01 Patent grant