Syntax
Graphs are defined via facts using predicates node
, edge
,
graph
and attr
.
Note
A custom prefix for the predicate names can be defined to avoid clashes with other existing predicates.
Nodes
A node is defined using predicate node
where the argument is an
identifier.
Example 1
node(john).
node(jane).
Edges
An edge from A
to B
is defined using predicate edge
where the argument is a tuple (A,B)
. The edges will be directed
when creating a digraph
and not directed one created a graph
.
Example 1 (continuation)
edge((john,jane)).
Graphs
A graph is defined using predicate graph/1
.
Example
graph(family).
Multiple graphs
Multiple graphs can defined within the same set of facts. Each of them will generate a different graph. In order to assign a node or edge to an specific graph we add the identifier of the graph in the second argument.
Warning
All nodes and edges defined with a
single argument are assigned to the default graph called
default
. A different graph can be defined as the default as an option.
Example 2
graph(toms_family).
graph(bills_family).
node(tom, toms_family).
node(max, toms_family).
edge((tom, max), toms_family).
node(bill, bills_family).
node(jen, bills_family).
edge((bill, jen), bills_family).
Note
The creation of multiple graphs is specially useful for representing a dynamic domain where we need a different visualization for each time step
Subgraphs
Subgraphs can be defined by adding a parent graph as a second
argument to the graph
predicate. Then, nodes and edges can be assigned to a subgraph or a graph in the same way.
Example 3
graph(house).
graph(bathroom, house).
graph(bedroom, house).
node(toilet,bathroom).
node(bed,bedroom).
node(desk,bedroom).
edge((toilet,bed),house).
Attributes
The attributes of an element (graph, node or edge) are defined using
predicate attr
. This predicate will add any attributes accepted
by graphviz (see here)
specified by name-value pairs to the element.
attr(ELEMENT_TYPE, ELEMENT_ID, ATTR_NAME, ATTR_VALUE).
ELEMENT_TYPE
: The type of element: can begraph
,node
oredge
. Additionally, the element typesgraph_nodes
andgraph_edges
assign an attribute to all nodes/edges of a graph identified withELEMENT_ID
.ELEMENT_ID
: The identifier of the elementATTR_NAME
: The name of the graphviz attributeATTR_VALUE
: The value of the graphviz attribute
Example 3 (continuation)
attr(graph, house, label, "Tom's House").
attr(graph, bathroom, style, dotted).
attr(graph, bathroom, label, "Bathroom").
attr(graph, bedroom, style, dotted).
attr(graph, bedroom, label, "Bedroom").
attr(graph_nodes, house, style, filled).
attr(graph_nodes, house, color, cyan).
attr(node, toilet, shape, circle).
attr(node, bed, shape, square).
attr(node, desk, shape, square).
attr(edge, (toilet,bed), color, red).
Note
To edit the attributes of the default graph one must use the default name as element id.
Example 1 (continuation)
attr(graph, default, label, "Does' family").
attr(graph_nodes, default, style, filled).
attr(node, john, label, "John Doe").
attr(node, jane, label, "Jane Doe").
Multi-attribute
If multiple occurrences of the same attribute name for a specific
element are present, then the values will be concatenated in no
specific order. To define an order the attribute name can be a tuple
where the second value is the position where the value will be
considered. Furthermore, if the position is
sep
the value will be considered as the separator of the strings
in the concatenation.
Example 4
node(mike).
attr(node, mike, (label,0), "Michel").
attr(node, mike, (label,1), "Scott").
node(toby).
edge((mike,toby)).
attr(edge, (mike,toby)), label, "enemy").
attr(edge, (mike,toby)), label, "hate").
attr(edge, (mike,toby)), label, "boss").
attr(edge, (mike,toby)), (label,sep), "-").