Skip to content

Getting Started

barry is a header-only C++ library: include barry.hpp (or the headers under include/barry/) and compile with a C++17 compiler. OpenMP is optional; when available, some computations run in parallel.

Examples

Counting statistics in a graph

In the following code we create an array of size 5x5 of class Network (available in the namespace netcounters), add/remove ties, print the graph, and count common statistics used in ERGMs:

#include <iostream>
#include <ostream>
#include "../include/barry.hpp"

typedef std::vector< unsigned int > vuint;

int main() {
  // Creating network of size six with five ties
  netcounters::Network net(
      6, 6,
      {0, 0, 4, 4, 2, 0, 1},
      {1, 2, 0, 2, 4, 0, 1}
  );

  // How does this looks like?
  net.print("Current view");

  // Adding extra ties
  net += {1, 0};
  net(2, 0) = true;

  // And removing a couple
  net(0, 0) = false;
  net -= {1, 1};

  net.print("New view");

  // Initializing the data. The program deals with freing the memory
  net.set_data(new netcounters::NetworkData, true);

  // Creating counter object for the network and adding stats to count
  netcounters::NetStatsCounter counter(&net);
  netcounters::counter_edges(counter.get_counters());
  netcounters::counter_ttriads(counter.get_counters());
  netcounters::counter_isolates(counter.get_counters());
  netcounters::counter_ctriads(counter.get_counters());
  netcounters::counter_mutual(counter.get_counters());

  // Counting and printing the results
  std::vector< double > counts = counter.count_all();

  std::cout <<
    "Edges             : " << counts[0] << std::endl <<
    "Transitive triads : " << counts[1] << std::endl <<
    "Isolates          : " << counts[2] << std::endl <<
    "C triads          : " << counts[3] << std::endl <<
    "Mutuals           : " << counts[4] << std::endl;

  return 0;
}

Compiling this program using g++

g++ -std=c++11 -Wall -pedantic 08-counts.cpp -o counts && ./counts

Yields the following output:

Current view
[  0,]  1  1  1  .  .  . 
[  1,]  .  1  .  .  .  . 
[  2,]  .  .  .  .  1  . 
[  3,]  .  .  .  .  .  . 
[  4,]  1  .  1  .  .  . 
[  5,]  .  .  .  .  .  . 
New view
[  0,]  .  1  1  .  .  . 
[  1,]  1  .  .  .  .  . 
[  2,]  1  .  .  .  1  . 
[  3,]  .  .  .  .  .  . 
[  4,]  1  .  1  .  .  . 
[  5,]  .  .  .  .  .  . 
Edges             : 7
Transitive triads : 3
Isolates          : 2
C triads          : 1
Mutuals           : 3

More examples are in the examples/ directory of the repository.

Building and testing

The project includes a Makefile with various build targets. To see all available options, run:

make help

This will display all available targets including: - tests - Build and run tests with OpenMP - test-portable - Build and run tests without OpenMP (cross-platform) - coverage - Run tests with coverage analysis - docs - Generate documentation

The default target is help, so running make without arguments will show the available options.