Node tablenode ID node Name Connection table connec tionID node ID edge ID source OrSink Figure 3.32 Connection directed graph: Populated tables.. 3.4.5 ExampleThe connection template is
Trang 1Node table
node
ID
node
Name
Connection table connec
tionID
node ID
edge ID
source OrSink
Figure 3.32 Connection directed graph: Populated tables
Edge table edge
ID
edge Name
51 c
52 d
53 e
54 f
55 g
56 h
57 i
Connection table (cont) connec
tionID
node ID
edge ID
source OrSink
B c
d
e
F
A
f
g
Figure 3.33 Connection directed graph: Populated tables
Node table
node
ID
node
Name
Connection table connec
tionID
node ID
edge ID
source OrSink
Edge table
edge
ID
edge Name
61 r
62 s
63 t
Connection table (cont) connec
tionID
node ID
edge ID
source OrSink
Y X
r s t
Trang 23.4.5 Example
The connection template is sometimes helpful for representing directed graphs as Figure 3.34 illustrates A manufacturing plant can have a variety of equipment that is connected by piping Nozzles connect piping to equipment and have a direction of normal fluid flow
3.5 Simple DG Changing over Time Template
There are two templates for directed graphs that can change over time The first (this section)
is based on the simple directed graph The second (next section) is based on the node and edge directed graph It is also possible to extend the connection template for variations over time, but I have never seen it used in practice
3.5.1 UML Template
The template for simple directed graphs that change over time (Figure 3.35) is similar to the tree template in Section 2.5 Figure 3.35 separates an entity from its directed graph position (node) because the timeline for an entity can differ from that of its involvement in a graph
A DG (directed graph) is a set of nodes and a set of directed edges that connect nodes.
(Note: in a directed graph all the nodes do not have to be connected.) You need not show DG
2
Figure 3.34 Connection directed graph: Equipment and piping model
Nozzle
sourceOrSink
ManufacturingPlant
1
*
Figure 3.35 Simple directed graph changing over time: UML template
Use when edges are unimportant and history must be recorded
root
{Each node has at least one parent except for root nodes.}
0 1
<Node>
effectiveDate expirationDate
<Binding>
effectiveDate expirationDate
<DG>
<Entity>
effectiveDate expirationDate
<NodeLink>
effectiveDate expirationDate
*
*
1 1 parent child
*
{There cannot be any cycles.}
Trang 3in a use of the template A Node is a position within a directed graph The distinction
be-tween parent and child causes the sense of direction that effects directed edges.
Figure 3.35 adds the constraint that each node has at least one parent except for root nodes (The template itself is more permissive and lacks this constraint.) In general, a
direct-ed graph may have cycles but this template disallows them (A cycle starts at a node and after traversing a series of edges reaches the starting node.) Since this template is based on a tree template, it doesn’t make sense to permit cycles
This template is already complex, so it is best to handle node names in a simple manner Each node has a globally unique name and there is no provision to vary node name by
con-text The effective and expiration dates permit Node and Entity data to vary over time.
3.5.2 IDEF1X Template
Figure 3.36 restates Figure 3.35 with the IDEF1X notation The following are foreign keys:
dgID references DG, nodeID references Node, entityID references Entity, parentNodeID ref-erences Node, and childNodeID refref-erences Node.
In Figure 3.36 the node name can change over time (three part candidate key—node-Name + effectiveDate + expirationDate), but the node name could also be invariant over time (candidate key of nodeName alone) Note that the handling of time reflects a limitation of
relational DBMSs It would be better to use time intervals but most relational DBMSs only support points in time
3.5.3 SQL Queries
Figure 3.37 and Figure 3.38 show SQL queries for common traversals of the template The colon prefix denotes variable values that must be provided for each query
bindingID
Binding
effectiveDate expirationDate nodeID (FK) entityID (FK)
nodeID
Node
nodeName (AK1.1) effectiveDate (AK1.2) expirationDate (AK1.3)
entityID
Entity
effectiveDate expirationDate
nodeLinkID
NodeLink
effectiveDate expirationDate parentNodeID (FK) childNodeID (FK)
Figure 3.36 Simple directed graph changing over time: IDEF1X template
dgID (FK) dgID
DG
Trang 4Figure 3.37 Simple directed graph changing over time: SQL query
Find the parents for a child node
SELECT Parent.nodeID AS parentNodeID,
Parent.nodeName AS parentNodeName
FROM Node AS Child
INNER JOIN NodeLink AS NL ON Child.nodeID = NL.childNodeID INNER JOIN Node AS Parent ON NL.parentNodeID = Parent.nodeID WHERE Child.nodeID = :aChildNodeID AND
(Child.effectiveDate IS NULL OR
:aDate >= Child.effectiveDate) AND
(Child.expirationDate IS NULL OR
:aDate <= Child.expirationDate) AND
(NL.effectiveDate IS NULL OR
:aDate >= NL.effectiveDate) AND
(NL.expirationDate IS NULL OR
:aDate <= NL.expirationDate) AND
(Parent.effectiveDate IS NULL OR
:aDate >= Parent.effectiveDate) AND
(Parent.expirationDate IS NULL OR
:aDate <= Parent.expirationDate)
ORDER BY Parent.nodeName;
Figure 3.38 Simple directed graph changing over time: SQL query
Find the children for a parent node
SELECT Child.nodeID AS childNodeID,
Child.nodeName AS childNodeName
FROM Node AS Child
INNER JOIN NodeLink AS NL ON Child.nodeID = NL.childNodeID INNER JOIN Node AS Parent ON NL.parentNodeID = Parent.nodeID WHERE Parent.nodeID = :aParentNodeID AND
(Child.effectiveDate IS NULL OR
:aDate >= Child.effectiveDate) AND
(Child.expirationDate IS NULL OR
:aDate <= Child.expirationDate) AND
(NL.effectiveDate IS NULL OR
:aDate >= NL.effectiveDate) AND
(NL.expirationDate IS NULL OR
:aDate <= NL.expirationDate) AND
(Parent.effectiveDate IS NULL OR
:aDate >= Parent.effectiveDate) AND
(Parent.expirationDate IS NULL OR
:aDate <= Parent.expirationDate)
ORDER BY Child.nodeName;
Trang 53.5.4 Sample Populated Tables
Figure 3.39 shows tables populated with data for the simple directed graph changing over
time The values of the IDs are arbitrary, but internally consistent A null effectiveDate means that a Node applies indefinitely from the past A null expirationDate means that a Node applies indefinitely into the future In accordance with the template, there are no
ex-plicit edges and edges are represented via the coupling between nodes
As in Section 3.1, the template cannot express directed graphs with multiple edges
be-tween a pair of nodes For brevity, the Node table omits the dgID column This simple ex-ample does not populate Binding and Entity.
3.5.5 Example
Figure 3.40 revisits the example from Section 2.5 The management structure can be a ma-trix, instead of a simple hierarchy; then a person can report to more than one manager at the
Directed graph, 1 July 2000 0100
Node table
node
ID
node
Name
effective
Date
expiration Date
2000 0100
2000 0300
Directed graph, 1 July 2000 0300
NodeLink table node
link ID
effective Date
expiration Date
parent Node ID
child Node ID
2000 0100
7 1 July
2000 0300
Figure 3.39 Simple directed graph changing over time: Populated tables
N M
L K
J
L K
J
X