# Conversion Functions

Conversion functions do not preserve a graph’s support and vertex/edge decorations. That is, the resulting graph has standard support and no vertex/edge decorations. A slight exception to this rule occurs when the resulting graph is a network (of type `GrphNet`) and is described in detail in [`UnderlyingNetwork`](#function-multigraph-underlyingnetwork).

## Orientated Graphs

The rules followed in building an orientated graph from an undirected graph are the same as those described for simple graphs (see Section [Converting between Graphs and Digraphs](../Graphs/conversion-graph-digraph.md#graph-sec-convert)).

### `OrientatedGraph(G): GrphMultUnd -> GrphMultDir`

Given a multigraph $G$, produce a multidigraph $D$ whose vertex-set is the same as that of $G$ and whose edge-set consists of the edges of $G$, each given a direction. The edges of $D$ are always directed from the lower numbered vertex to the higher numbered vertex. Thus, if $G$ contains the edge $\{ u, v\rbrace$, then $D$ will have the edge $[u,v]$ if $u < v$, otherwise the edge $[u,v]$. If $G$ has a loop at $u$, then $D$ will have a directed loop at $u$.

## Converse

### `Converse(G): GrphMultDir -> GrphMultDir`

Given a multidigraph $G$ with edge-set $E$, produce a multidigraph $D$ whose vertex-set is the same as that of $G$ and whose edge-set is $\{ [u, v] : [v, u] \in E \}$.

## Converting between Simple Graphs and Multigraphs

Any simple (di)graph can be converted into a multi(di)graph and any multi(di)graph can be converted into a simple (di)graph. The resulting graph has standard support and neither vertex labels nor edge decorations, unless it is a network, in which case all the edges in the resulting graph are assigned a capacity of 1 (0 if loops).

Let $G$ be a graph and $e$ an edge of $G$ from $u$ to $v$ and let $H$ be the graph resulting from the conversion. If $G$ and $H$ are both undirected or both directed then $e$ is also an edge of $H$. If $G$ is undirected while $H$ is undirected then both edges $[u, v]$ and $[v, u]$ are edges of $H$. If $G$ is directed while $H$ is directed then the edge $\{u, v\}$ is an edge of $H$.

Since these conversion functions do not retain the original graph’s support and vertex/edge decorations, they may also be used when requiring a copy of a graph $G$ without $G$’s support and vertex/edge decorations.

### `UnderlyingGraph(G): GrphMult -> GrphUnd, GrphVertSet, GrphEdgeSet`

### `UnderlyingGraph(G): Grph -> GrphUnd, GrphVertSet, GrphEdgeSet`

The underlying simple graph of the graph $G$. The support and vertex/edge decorations of $G$ are not retained.

### `UnderlyingDigraph(G): GrphMult -> GrphDir, GrphVertSet, GrphEdgeSet`

### `UnderlyingDigraph(G): Grph -> GrphDir, GrphVertSet, GrphEdgeSet`

The underlying simple digraph of the graph $G$. The support and vertex/edge decorations of $G$ are not retained.

### `UnderlyingMultiGraph(G): Grph -> GrphMultUnd, GrphVertSet, GrphEdgeSet`

### `UnderlyingMultiGraph(G): GrphMult -> GrphMultUnd, GrphVertSet, GrphEdgeSet`

The underlying multigraph of the graph $G$. The support and vertex/edge decorations of $G$ are not retained.

### `UnderlyingMultiDigraph(G): Grph -> GrphMultDir, GrphVertSet, GrphEdgeSet`

### `UnderlyingMultiDigraph(G): GrphMult -> GrphMultDir, GrphVertSet, GrphEdgeSet`

The underlying multidigraph of the graph $G$. The support and vertex/edge decorations of $G$ are not retained.

### `UnderlyingNetwork(G): Grph -> GrphNet, GrphVertSet, GrphEdgeSet`

### `UnderlyingNetwork(G): GrphMult -> GrphNet, GrphVertSet, GrphEdgeSet`

The underlying network of the graph $G$. The support and vertex/edge decorations of $G$ are not retained except when $G$ is a network in which case only the edge capacities are retained. If $G$ is not a network, then all the edge capacities are set to 1 (0 for loops).
