GraphTheory/GraphAttributes

 Calling Sequence SetGraphAttribute(G, attr) SetVertexAttribute(G, v, attr) SetEdgeAttribute(G, e, attr) GetGraphAttribute(G, tag) GetVertexAttribute(G, v, tag) GetEdgeAttribute(G, e, tag) DiscardGraphAttribute(G, tag) DiscardVertexAttribute(G, v, tag) DiscardEdgeAttribute(G, e, tag) ListGraphAttributes(G) ListVertexAttributes(G, v) ListEdgeAttributes(G, e)

Parameters

 G - graph v - vertex e - edge/arc attr - equation or list of equations tag - (optional) simple type or list

Description

 • SetVertexAttribute(G,v,attr) is used to store arbitrary information in the form of tag=value for vertex v in a graph G. These equations are called attributes. The argument attr can be a single attribute to be assigned to v or a list of attributes. Note that for a fixed vertex, tags must be unique. If the vertex already has an attribute with the given tag, the command reassigns the value of that tag to the new value provided by attr.
 • GetVertexAttribute(G,v,tag) is used to retrieve all or some of the attributes of vertex v.  If tag is a single tag, then the value corresponding to that tag is returned. If no attribute with the specified tag is defined for v the command returns FAIL. The argument tag can also be a list of tags in which case a list of values is returned.
 • DiscardVertexAttribute(G,v,tag) is used to discard all or some of the attributes of the vertex v in the graph G. If the optional argument tag is not present, all attributes of v are discarded. If a single tag or a list of tags is specified then the attributes corresponding to those tags are discarded. If an attribute with the given tag is not found, the command does nothing.
 • ListVertexAttributes(G,v) is used to list all attributes for vertex v in the graph G.  It outputs a list, possibly empty, of the tags used for the attributes in G.
 • SetGraphAttribute, GetGraphAttribute, DiscardGraphAttribute, ListGraphAttributes are similar to their vertex analogues and are used to manage attributes of a graph rather than a particular vertex in a graph.
 • SetEdgeAttribute, GetEdgeAttribute, DiscardEdgeAttribute, ListEdgeAttributes are similar to their vertex analogues but are used to manage attributes of the edges of a graph instead of a vertex in a graph.

Examples

 > $\mathrm{with}\left(\mathrm{GraphTheory}\right):$
 > $\mathrm{with}\left(\mathrm{SpecialGraphs}\right):$
 > $T≔\mathrm{CompleteBinaryTree}\left(3\right)$
 ${T}{≔}{\mathrm{Graph 1: an undirected unweighted graph with 15 vertices and 14 edge\left(s\right)}}$ (1)
 > $\left[\mathrm{SetVertexAttribute}\left(T,1,"label"="root"\right)\right]$
 $\left[\right]$ (2)
 > $\left[\mathrm{SetEdgeAttribute}\left(T,\left\{9,10\right\},\left["message"="i am an edge!","cost"=12.4\right]\right)\right]$
 $\left[\right]$ (3)
 > $\mathrm{GetVertexAttribute}\left(T,1,\left["label","message"\right]\right)$
 $\left[{"root"}{,}{\mathrm{FAIL}}\right]$ (4)
 > $\mathrm{GetEdgeAttribute}\left(T,\left\{9,10\right\}\right)$
 $\left[{"message"}{=}{"i am an edge!"}{,}{"cost"}{=}{12.4}\right]$ (5)
 > $\mathrm{DiscardVertexAttribute}\left(T,1\right)$
 > $\mathrm{DiscardEdgeAttribute}\left(T,\left\{9,10\right\},"message"\right)$