Code Monkey home page Code Monkey logo

percolation_on_graph's Introduction

Percolation on graph

The edgelist_perco_t class offers many methods to perform and analyze bond percolation on simple unweighted undirected graphs without self-loops.

The class can be imported directly and is available under the namepace pgl.

// Importing the class
#include "src/edgelist_perco_t.hpp"

The currently available methods can be distinguished into three categories

Note that further examples on how to use edgelist_perco_t can be found in a notebook (and related scripts) used to validate the class.

Importing a graph from an edgelist file

A graph can be imported from a file containing its edgelist (one edge per line). The edgelist file consists in a simple text file with the following convention

# lines beginning with "#" are ignored (comments).
# note that vertices' name must be separated by at least one white space.
# there may be white space at the beginning of a line.
[name of vertex1]  [name of vertex2]  [remaining information will be ignored]
[name of vertex2]  [name of vertex3]  [remaining information will be ignored]
[name of vertex4]  [name of vertex5]  [remaining information will be ignored]
# comments can be inserted between edges
[name of vertex5]  [name of vertex6]  [remaining information will be ignored]
[name of vertex7]  [name of vertex6]  [remaining information will be ignored]
...

Note that the vertices' name will be imported as std::string and can therefore be virtually anything as long as they do not include white spaces (i.e., there is not need for the vertices to be identified by contiguous integers).

IMPORTANT: this class only considers simple unweighted undirected graphs without self-loops. Any multiple edges or self-loops in the edgelist file will be ignored.

// The graph is loaded at the initialization of the class
pgl::edgelist_perco_t g("<path-to-edgelist-file>");

Generating one instance of a bond percolated edgelist

This method creates a provisional edgelist in which each edge has been kept with the probability passed as an argument. The connected components are then identified using a weighted union-find with path compression algorithm.

// Generates an instance of the original graph in which each edge has been
//   removed with probability 1 - 0.6.
int number_of_remaining_edges = g.bond_percolate(0.6);
// and returns the number of edges that have not been removed.

Properties of the percolated edgelist

Once a percolated instance has been generated, various information about its components can be extracted

// Size of the connected component to which vertex "v" belongs.
int component_size = g.get_component_size(v);

// Number of connected components.
int nb_components = g.get_nb_components();

// Number of vertices in the graph.
int nb_vertices = g.get_nb_vertices();

// Returns the numerical ID of a randomly chosen vertex.
int v = g.get_random_vertex();

// Size of the largest connected component.
int size_largest_perco_component = g.get_size_largest_perco_component();

// Size of the component to which a random vertex belongs.
int size_random_perco_component = g.get_size_random_perco_component();

// Size of the second largest connected component.
int size_second_largest_perco_component = g.get_size_second_largest_perco_component();

percolation_on_graph's People

Contributors

antoineallard avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.