Rust library for of graph ensembles


Rust library for random graph ensembles

Crate Rust unit tests - master Docs

Minimal Rust version: 1.55.0

Implements simple sampling and monte carlo (or rather markov-) steps, that can be used to create a markov chain.

This is intended to be used for various different use cases. As such, you can easily define additional data that should be stored at each vertex.


Add this to your Cargo.toml:

net_ensembles = "0.5"
# for feature "serde_support" (enabled by default) also use
serde = { version = "1.0", features = ["derive"] }

If you do not need serde support, add this instead:

net_ensembles = { version = "0.5", default-features = false  }

Release Notes

See changelog. Note that savestates (created with serde) of v0.4 are incompatible with savestates generated by older versions and vise versa. Braking changes may or may not affect the loading of save states, you have to test that out yourself

currently implemented graph ensembles

  • Erdős-Rényi (x2)
  • small-world

work in progress

  • Barabási-Albert
  • Configuration Model
  • spacial networks


On a 64 bit system drawing an usize consumes more randomness than on a 32 bit system, therefore ensembles drawn etc. are affected by the size of usize.


  • you can always visualize the current graph by creating a .dot file from it. There are different options for that, choose which one fits you best.

Implements measurable quantities

  • average degree
  • connected components
  • diameter
  • is_connected
  • leaf count
  • q_core
  • transitivity
  • biconnected component
  • vertex_load (closely related, often equal to betweeness)


  • depth first search from index
  • breadth first search from index
  • over additional data

For each vertex

methods and more

  • degree
  • check adjacency with other nodes
  • access additional data


  • iterate over indices stored in adjacency list



No warranties whatsoever, but since I am writing this library for my own scientific simulations, I do my best to avoid errors.

You can learn more about me and my research on my homepage.

If you notice any bugs, or want to request new features: do not hesitate to open a new issue on the repository.


  • The number of vertices has to be decided when creating a graph and cannot be changed later - at least for now.
  • I might add a method to add vertices if requested or I need it myself.

Due to implementation details, where I prioritize fast access of vertices, it is unlikely, that I will implement the option to remove vertices. If I do, it will likely be a relatively costly operation, so keep that in mind.

  • I might move the sampling module into a different crate in the future. If I do, everything will likely be reexported at the same position as currently


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

You might also like...
The library provides basic functions to work with Graphviz dot lang from rust code.

Description The library provides the basic access to the graphs in graphviz format with ability to import into or export from it. Base examples: Parse

Generic framebuffer implementation in Rust for use with embedded-graphics library

Fraramebuffer implementation for Rust's Embedded-graphics Framebuffer approach helps to deal with display flickering when you update multiple parts of

An SVG rendering library.

resvg resvg is an SVG rendering library. Purpose resvg can be used as a Rust library, a C library and as a CLI application to render SVG files based o

Library for Rubik's cube applications.

Rubik Master Do you like to solve Rubik's cube? I do. As a cuber and programmer, I want to build a toolset to build applications like S

Sub-pixel precision light spot rendering library for astronomy and video tracking applications.

Planetarium Sub-pixel precision light spot rendering library for astronomy and video tracking applications. Example usage use planetarium::{Canvas, Sp

Small, lightweight and fast library for rendering text with wgpu.

wgpu-text wgpu-text is a wrapper over glyph-brush for fast and easy text rendering in wgpu. This project was inspired by and is similar to wgpu_glyph,

Python library for embedding large graphs in 2D space, using force-directed layouts.

Graph Force A python/rust library for embedding graphs in 2D space, using force-directed layouts. Installation pip install graph_force Usage The first

A toy ray tracer in Rust
A toy ray tracer in Rust

tray_rust - A Toy Ray Tracer in Rust tray_rust is a toy physically based ray tracer built off of the techniques discussed in Physically Based Renderin

A low-overhead Vulkan-like GPU API for Rust.
A low-overhead Vulkan-like GPU API for Rust.

Getting Started | Documentation | Blog gfx-rs gfx-rs is a low-level, cross-platform graphics and compute abstraction library in Rust. It consists of t

  • IntelliSense shows all the methods

    IntelliSense shows all the methods

    The Issue was that VSCodes Intellisense does not recognize e.g. .vertex_count() if you use it directly on e.g. SwEnsemble.vertex_count() but only shows the function if you use it like this SwEnsemble.graph().vertex_count(), although both work and give the same output.

    So I think the issue is, that when you use SwEnsemble.vertex_count() it uses the function from net_ensemble\traits\graph_trait -> trait MeasurableGraphQuantities. And in the end of the graph_trait file those Quantities gets implemented for all Ensembles like this impl<T, A, E> MeasurableGraphQuantities<GenericGraph<T, A>> for E

    But it does not get directly implemented for SwEnsemble, but only on a "passive" way for all E. So the only solution is to implement MeasurableGraphQuantities in the net_ensemble\ file and for SwEnsemble directly. Then VSCode can look first for all the implemented traits on SwEnsemble in and finds the .vertex_count defintion.

    I did this implementation for all the Ensembles. You do not have to merge this, but I wanted to show you my results when I dug into the code.

    Maybe it is a good way to impl it directly in these files so everyone can see that SwEnsemble has these methods. But on the otherhand it is duplicated code because we get the same result with a .graph().vertex_count() call already and both function calls lead to the exact same underlying structure. The .graph().vertex_count() call refers to the GenericGraph struct and that struct already implements all the functions the trait MeasurableGraphQuantities does too.

    Just wanted to share this :D

    Here some code to try the IntelliSense out.

    use net_ensembles::{
        rand::SeedableRng, BAensemble, EmptyNode, ErEnsembleC, ErEnsembleM, SwEnsemble,
    use rand_pcg::Pcg64;
    fn main() {
        let rng = Pcg64::seed_from_u64(75676525);
        let sw_ensemble = SwEnsemble::<EmptyNode, Pcg64>::new(5, 0.1, rng);
        println!("{}", sw_ensemble.vertex_count());
        println!("{}", sw_ensemble.graph().vertex_count());
        let rng = Pcg64::seed_from_u64(75676525);
        let er_ensemblec = ErEnsembleC::<EmptyNode, Pcg64>::new(5, 0.1, rng);
        println!("{}", er_ensemblec.vertex_count());
        println!("{}", er_ensemblec.graph().vertex_count());
        let rng = Pcg64::seed_from_u64(75676525);
        let er_ensemblem = ErEnsembleM::<EmptyNode, Pcg64>::new(5, 5, rng);
        println!("{}", er_ensemblem.vertex_count());
        println!("{}", er_ensemblem.graph().vertex_count());
        let rng = Pcg64::seed_from_u64(75676525);
        let ba_ensemble = BAensemble::<EmptyNode, Pcg64>::new(5, rng, 5, 5);
        println!("{}", ba_ensemble.vertex_count());
        println!("{}", ba_ensemble.graph().vertex_count());
    opened by T1mors 0
Yannick Feld
I am working on my PhD in computational physics
Yannick Feld
A graph library for Rust.

Gamma A graph library for Rust. Gamma provides primitives and traversals for working with graphs. It is based on ideas presented in A Minimal Graph AP

Metamolecular, LLC 122 Dec 29, 2022
Simple but powerful graph library for Rust

Graphlib Graphlib is a simple and powerful Rust graph library. This library attempts to provide a generic api for building, mutating and iterating ove

Purple Protocol 177 Nov 22, 2022
🦀 Rust Graph Routing runtime for Apollo Federation 🚀

Apollo Router The Apollo Router is a configurable, high-performance graph router for a federated graph. Getting started Follow the quickstart tutorial

Apollo GraphQL 502 Jan 8, 2023
Graph API client writen in Rust

graph-rs Now available on stable Rust at graph-rs-sdk = "0.1.0" 0.1.0 and above use stable Rust. Anything before 0.1.0 uses nightly Rust. M

Sean Reeise 56 Jan 3, 2023
A Graph implemented using nothing but `Vec`s in rust

VecGraph A Graph implemented using nothing but Vecs in rust. Details The graph is implemented using two Vecs: nodes and edges. nodes stores "nodes". w

null 1 Jan 27, 2022
GraphScope: A One-Stop Large-Scale Graph Computing System from Alibaba

A One-Stop Large-Scale Graph Computing System from Alibaba GraphScope is a unified distributed graph computing platform that provides a one-stop envir

Alibaba 2.2k Jan 1, 2023
A simple and elegant, pipewire graph editor

pw-viz A simple and elegant, pipewire graph editor This is still a WIP, node layouting is kinda jank at the moment. Installation A compiled binary is

null 180 Dec 27, 2022
A graph crate with simplicity in mind

A graph crate with simplicity in mind. Prepona aims to be simple to use (for users of the crate) and develop further (for contributors). Nearly every

Mohamad Amin Rayej 80 Dec 15, 2022
Simple, performant graph generator for Feynman diagrams* ⚛️

Feynman diagram generator ⚛️ A simple generator of "Feynman diagram" permutations (as defined by problem 781). Incrementally builds isomorphically uni

eugene huang 3 Jan 1, 2023
Theorem relational dependencies automatic extraction and visualization as a graph for Lean4.

Lean Graph Interactive visualization of dependencies for any theorem/definitions in your Lean project. How to use In your browser: Or r

Patrik Číhal 8 Jan 3, 2024