GXL Graphs
After the theoretical explanation of the GXL-construct, it is now necessary to go through a code example, try out the single features of the definition and see their visualization in an UML object diagram. At first some general issues and basic structures will be explained, then the example will be extended for using the attribute-model of GXL, followed by an enhancement, using edges and relations in different ways. This all is completed by some more expansions drawing the ordering of incidences, hypergraphs/ n-ary relations and hierarchical graphs.
Note: The arrows below are links to the corresponding steps in gxl/from_graph_to_schema.
Step 1: The Prolog and the Root
Element
|
UML object diagram |
GXL code (xml file) |
|
no diagram |
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE gxl SYSTEM "gxl.dtd">
<gxl xmlns:xlink="www.w3.org/1999/xlink"/> |
As it can be seen, the first step is the identification of the file as an xml document and the link to the extern GXL DTD. After that, it is possible to build the GXL root element gxl, which makes the XLink namespace available (the XLink specification will be left out in the following fragments, because it is already defined in the DTD and fixed).
|
UML object diagram |
GXL code (xml file) |
|
|
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE gxl SYSTEM "gxl.dtd">
<gxl> <graph id="graph1"><type xlink:href="schema#graph_class1"/> </graph>
<graph id="graph2"> <type xlink:href="schema#graph_class2"/> </graph>
<graph id="graph3"> <type xlink:href="schema#graph_class3"/> </graph></gxl> |
As the next step, the graphs have to be defined, as it is done in the fragment above. Here three graphs are defined (their number is arbitrary) , all referencing their schema-element. There are no standard attributes changed, therefore the graphs have no special role, edges have no IDs, they are no hypergraphs and the edges are directed. Normally graphs are only built as objects (stereotyped graph) if they are carrying attributes, but this example is an exception, inserted for showing, how they are visualized.
|
UML object diagram |
GXL code (xml file) |
|
|
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE gxl SYSTEM "gxl.dtd">
<gxl> <graph id="graph1"> <type xlink:href="schema#graph_class1"/><node id="node1"> <type xlink:href="schema#node_class1"/> </node> <node id="node2"> <type xlink:href="schema#node_class2"/> </node> </graph> </gxl> |
For this example it is not necessary to work with multiple graphs, so the first one is taken and will not be show any more, because it uses the standard-attributes. Therefore the whole screen is the graph, which possesses a contains association to every element on it. But what is needed if a graph should be build up are nodes, as specified in the upper text. Here are shown two of them, owning an ID themselves and referencing their schema element again (visualized by two classes).
|
UML object diagram |
GXL code (xml file) |
|
|
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE gxl SYSTEM "gxl.dtd">
<gxl> <graph id="graph1"> <type xlink:href="schema#graph_class1"/><node id="node1"> <type xlink:href="schema#node_class1"/> <attr name="bool_attr"> <bool>true</bool> </attr> <attr name="float_attr"> <float>1.0</float> </attr> <attr name="int_attr"> <int>1</int> </attr> <attr name="string_attr"> <string>content</string> </attr> </node><node id="node2"> <type xlink:href="schema#node_class2"/> <attr name="locator_attr"> <locator xlink:type="simple" xlink:href="www.w3c.org"/> </attr> <attr name="enum_attr"> <enum>12</enum> </attr> </node> <node id="node3"> <type xlink:href="schema#node_class3"/> <attr name="bag_attr"> <bag> <string>one</string> <string>two</string> <string>one</string> </bag> </attr> <attr name="seq_attr"> <seq> <int>1</int> <int>2</int> <int>3</int> </seq> </attr> <attr name="tup_attr"> <tup> <float>1.0</float> <float>3.0</float> <float>2.0</float></tup> </attr> <attr name="set_attr"> <set> <bool>true</bool> <bool>false</bool> </set> </attr> </node> </graph></gxl> |
To add an attribute, simply the subelement named attr has to be created, it has to be given a name and one or more valid value-types have to be paste in. In the example three nodes are shown, with the four atomic value-types (bool, float, int and string) fit in the first node, a link (locator) respectively a enumeration-type (enum) within the second and the four composite types (bag, seq, tup and set), which contain atomics itselves, added to the third one (they are all visualized by attributed classes).
The schema references of the attribute elements are only optional, like in every element and are left out here. Because it is the same definition everywhere, type references are not mentioned any more.
|
UML object diagram |
GXL code (xml file) |
|
|
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE gxl SYSTEM "gxl.dtd">
<gxl> <graph id="graph1" edgeids="true" edgemode="defaultdirected"> <type xlink:href="schema#graph_class1"/> <node id="node1"> <type xlink:href="schema#node_class1"/> </node><node id="node2"> <type xlink:href="schema#node_class2"/> </node><node id="node3"> <type xlink:href="schema#node_class3"/> </node><node id="node4"> <type xlink:href="schema#node_class4"/> </node><edge from="node1" to="node2" isdirected="false"/> <edge id="edge2" from="node1" to="node2"> <type xlink:href="schema#edge_class2"/> </edge> <edge id="edge3" from="node3" to="node4 "> <type xlink:href="schema#edge_class3"/> <attr name="bool_attr"> <bool>true</bool> </attr> </edge> </graph> </gxl> |
This time four nodes are defined and connected by edges of different kinds. A look at the graph element shows, that edge IDs are demanded, but not consistently done here, and undirected edges are allowed, but not default. The first edge (node1-node2) is undirected and carries neither ID nor attributes, the second one contains the ID edge2 and is directed and the last one (edge3) is directed, too, and includes ID and attributes.
As it can be seen, these edges are produced by completely different UML constructs - the first two are "only" associations, which can be distinguished by the navigability and the name. But the third is a named, attributed and stereotyped class (needed for implementing the attributes), connected with its nodes by associations. The graph is shown as a node, stereotyped graph, again, because the standard attributes have changed.
Step 6: Ordering of Incidences
|
UML object diagram |
GXL code (xml file) |
|
|
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE gxl SYSTEM "gxl.dtd">
<gxl> <graph id="graph1" edgeids="true"> <type xlink:href="schema#graph_class1"/><node id="node1"> <type xlink:href="schema#node_class1"/> </node> <node id="node2"> <type xlink:href="schema#node_class2"/> </node> <edge id="edge1" from="node1" to="node1" fromorder="2" toorder="3"> <type xlink:href="schema#edge_class1"/> </edge>
<edge id="edge2" from="node1" to="node2" fromorder="1" toorder="3"> <type xlink:href="schema#edge_class2"/> <attr name="bool_attr"> <bool>true</bool> </attr> </edge><edge id="edge3" from="node2" to="node2" fromorder="1" toorder="2"> <type xlink:href="schema#edge_class3"/> </edge>
</graph> </gxl> |
In this graph, there are two nodes again, connected by three directed edges, which are ordered in this graph - therefore the edgemode of the graph is set to its default value again. If the first node is inspected, it can be seen that first edge2 is leaving the graph element, then the loop edge edge1 appears and reaches its element again. At the second node happens nearly the same: the loop edge edge3 starts and stops at the node and finally edge2 reaches it. The ordering information is stored in the edges itself by using their fromorder and toorder attributes. The graph is shown as above.
Note: their is currently no way to store the ordering information in the UML-diagram
|
UML object diagram |
GXL code (xml file) |
|
|
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE gxl SYSTEM "gxl.dtd">
<gxl> <graph id="graph1" edgeids="true"><type xlink:href="schema#graph_class1"/> <node id="node1"> <type xlink:href="schema#node_class1"/> </node> <node id="node2"> <type xlink:href="schema#node_class2"/> </node> <node id="node3"> <type xlink:href="schema#node_class3"/> </node><rel id="relation" isdirected="true"> <type xlink:href="schema#relation_class"/> <attr name="bool_attr"> <bool>true</bool> </attr><relend target="node1" role="from_node1_class"direction="in"/> <relend target="node2" role="to_node2_class"direction="out"/> <relend target="node3" role="first_to_node3_class" direction="out" endorder="1"/> <relend target="node3" role="second_to_node3_class"direction="out" endorder="2"/> </rel></graph> </gxl> |
To show the implementation of a relationship between some elements, the upper graph contains three nodes, and the attributed relation relation. As it can be seen in the code fragment, the relation is directed (the diagram would look the same way, except the navigability of the associations, if an undirected relation would be used) and includes one attribute of boolean type; furthermore, there are four relation-"tentacles" defined, one ingoing (from_node1) and three outgoing (to_node2, first_to_node3, second_to_node3) relation ends, whereas the relends, pointing at node3, are ordered by their approach. It has to be notified, that the "tentacles" have no IDs, but roles, by which their names are given in this example.
The relation itself is always visualized as a stereotyped class (even if no ID or attributes are used - therefore different to edge), and the relends are normal associations, carrying the role of the tentacle as name.
Note: there is currently no way to store the ordering information in the UML diagram
|
UML object diagram |
GXL code (xml file) |
|
no diagram |
no code |
A description of hierarchical graphs will follow in this step. Due to the ongoing discussion about their implementation in GXL it is not possible at the moment to introduce those here.