Meanwhile, in 18th-century Königsberg, both Graph and DiGraph fall short. Several of the bridges of Königsberg (discussed in Chapter 1, What is a Network?) connected the same two landmasses. In order to represent the bridges as a network, the nodes representing the land masses need to have multiple parallel edges, but the Graph class only allows one edge between a pair of nodes. For situations like this, NetworkX provides the MultiGraph and MultiDiGraph classes. For many applications, parallel edges can be combined into a single weighted edge, but when they can't, these classes can be used.
These MultiGraph and MultiDigraph classes work very much like Graph and DiGraph, but allow parallel edges. Any number of edges can be added between the same two endpoints. The following example reconstructs the Königsberg...