Basic Workout

Let’s first give the libgraph package a simple workout just to kick the tires.

As previously noted, the libgraph package uses the Graph module as its base namespace. This module defines a graph data structure, which supports directed and undirected graphs, in both acyclic and cyclic forms. It also defines the API for creating, manipulating, and querying that structure.

Directed Graph

Let’s cd back to our ExGraphsBook root and open up IEx:

 $ ​​iex​​ ​​-S​​ ​​mix

Create a new directed graph:

 iex>​​ ​​g​​ ​​=​​ ​​Graph.new
 #Graph<type: directed, vertices: [], edges: []>

Note that this is of type directed by default.

We can inspect the graph with the info/1 function:

 iex>​​ ​​Graph.info(g)
 %{num_edges: 0, num_vertices: ...

Get Exploring Graphs with Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.