Base BGL topology#

New in version 2.11.

#include <pagmo/topologies/base_bgl_topology.hpp>

class base_bgl_topology#

This class provides the basic building blocks to implement user-defined topologies (UDTs) based on the Boost Graph Library (BGL).

Note that, by itself, this class does not satisfy all the requirements of a UDT. Specifically, this class is missing the mandatory push_back() member function, which has to be implemented in a derived class (see is_udt for the full list of requirements a UDT must satisfy).

This class provides a strong thread safety guarantee: any member function can be invoked concurrently with any other member function.

base_bgl_topology()#

Default constructor.

The default constructor will initialize an empty graph with no vertices and no edges.

base_bgl_topology(const base_bgl_topology&)#
base_bgl_topology(base_bgl_topology&&) noexcept#
base_bgl_topology &operator=(const base_bgl_topology&)#
base_bgl_topology &operator=(base_bgl_topology&&) noexcept#

base_bgl_topology is copy/move constructible, and copy/move assignable. Copy construction/assignment will perform deep copies, move operations will leave the moved-from object in an unspecified but valid state.

Throws

unspecified – when performing copy operations, any exception raised by the copy of the underlying graph object.

std::size_t num_vertices() const#
Returns

the number of vertices in the topology.

bool are_adjacent(std::size_t i, std::size_t j) const#

Check if two vertices are adjacent.

Two vertices i and j are adjacent if there is a directed edge connecting i to j.

Parameters
  • i – the first vertex index.

  • j – the second vertex index.

Returns

true if i and j are adjacent, false otherwise.

Throws
  • std::invalid_argument – if i or j are not smaller than the number of vertices.

  • unspecified – any exception thrown by the public BGL API.

std::pair<std::vector<std::size_t>, vector_double> get_connections(std::size_t i) const#

Fetch the edges connecting to i.

This function will return a pair of vectors of equal size, containing:

  • the list of all vertices connecting to i,

  • the weights of the edges.

Parameters

i – the vertex index.

Returns

the list of connections to i.

Throws
  • std::invalid_argument – if i is not smaller than the number of vertices.

  • unspecified – any exception thrown by the public BGL API.

double get_edge_weight(std::size_t i, std::size_t j) const#

New in version 2.15.

Fetch the weight of the edge connecting i to j.

Parameters
  • i – the source vertex index.

  • j – the destination vertex index.

Returns

the weight of the edge connecting i to j.

Throws
  • std::invalid_argument

    if either:

    • i or j are not smaller than the number of vertices,

    • i and j are not adjacent.

  • unspecified – any exception thrown by the public BGL API.

void add_vertex()#

Add a vertex.

This function will add a new vertex to the topology. The newly-added vertex will be disjoint from any other vertex in the topology (i.e., there are no connections to/from the new vertex).

Throws

unspecified – any exception thrown by the public BGL API.

void add_edge(std::size_t i, std::size_t j, double w = 1)#

Add a new edge.

This function will add a new edge of weight w connecting i to j.

Parameters
  • i – the first vertex index.

  • j – the second vertex index.

  • w – the edge’s weight.

Throws
  • std::invalid_argument

    if either:

    • i or j are not smaller than the number of vertices,

    • i and j are already adjacent,

    • w is not in the \(\left[0, 1\right]\) range.

  • unspecified – any exception thrown by the public BGL API.

void remove_edge(std::size_t i, std::size_t j)#

Remove an existing edge.

This function will remove the edge connecting i to j.

Parameters
  • i – the first vertex index.

  • j – the second vertex index.

Throws
  • std::invalid_argument

    if either:

    • i or j are not smaller than the number of vertices,

    • i and j are not adjacent.

  • unspecified – any exception thrown by the public BGL API.

void set_weight(std::size_t i, std::size_t j, double w)#

Set the weight of an edge.

This function will set to w the weight of the edge connecting i to j.

Parameters
  • i – the first vertex index.

  • j – the second vertex index.

  • w – the desired weight.

Throws
  • std::invalid_argument

    if either:

    • i or j are not smaller than the number of vertices,

    • i and j are not adjacent,

    • w is not in the \(\left[0, 1\right]\) range.

  • unspecified – any exception thrown by the public BGL API.

void set_all_weights(double w)#

This function will set the weights of all edges in the topology to w.

Parameters

w – the edges’ weight.

Throws
  • std::invalid_argument – if w is not in the \(\left[0, 1\right]\) range.

  • unspecified – any exception thrown by the public BGL API.

std::string get_extra_info() const#
Returns

a string containing human-readable information about the topology.

Throws

unspecified – any exception thrown by the public BGL API.

bgl_graph_t to_bgl() const#

New in version 2.15.

Convert to a BGL graph.

Returns

a copy of the internal graph object used to represent the topology.

Throws

unspecified – any exception thrown by the public BGL API.