List of topologies#

Topologies exposed from C++#

class pygmo.unconnected#

Unconnected topology.

This user-defined topology (UDT) represents an unconnected graph. This is the default UDT used by pygmo.topology.

See also the docs of the C++ class pagmo::unconnected.


class pygmo.ring(n=0, w=1.)#

Ring topology.

This user-defined topology (UDT) represents a bidirectional ring (that is, a ring in which each node connects to both the previous and the following nodes).

See also the docs of the C++ class pagmo::ring.

Parameters
  • n (int) – the desired number of vertices

  • w (float) – the weight of the edges

Raises
  • TypeError – if n is negative or too large

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

add_edge(i, j, w=1.)#

Add a new edge.

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

Parameters
  • i (int) – the first vertex index

  • j (int) – the second vertex index

  • w (float) – the edge’s weight

Raises
  • TypeError – if i or j are negative or too large

  • ValueError – if i or j are not smaller than the number of vertices, i and j are already adjacent, or if w is not in the \(\left[0, 1\right]\) range

add_vertex()#

Add a vertex.

This method 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).

are_adjacent(i, j)#

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 (int) – the first vertex index

  • j (int) – the second vertex index

Returns

True if i and j are adjacent, False otherwise

Return type

bool

Raises
  • TypeError – if i or j are negative or too large

  • ValueError – if i or j are not smaller than the number of vertices

get_edge_weight(i, j)#

New in version 2.15.

Fetch the weight of the edge connecting i to j.

Parameters
  • i (int) – the source vertex index

  • j (int) – the destination vertex index

Returns

the weight of the edge connecting i to j

Return type

float

Raises
  • TypeError – if i or j are negative or too large

  • ValueError – if either i or j are not smaller than the number of vertices, or i and j are not adjacent

get_weight()#
Returns

the weight w used in the construction of this topology

Return type

float

num_vertices()#
Returns

the number of vertices in the topology

Return type

int

remove_edge(i, j)#

Remove an existing edge.

This method will remove the edge connecting i to j.

Parameters
  • i (int) – the first vertex index

  • j (int) – the second vertex index

Raises
  • TypeError – if i or j are negative or too large

  • ValueError – if i or j are not smaller than the number of vertices, or i and j are not adjacent

set_all_weights(w)#

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

Parameters

w (float) – the edges’ weight

Raises

ValueError – if w is not in the \(\left[0, 1\right]\) range

set_weight(i, j, w)#

Set the weight of an edge.

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

Parameters
  • i (int) – the first vertex index

  • j (int) – the second vertex index

  • w (float) – the desired weight

Raises
  • TypeError – if i or j are negative or too large

  • ValueError – if i or j are not smaller than the number of vertices, i and j are not adjacent, or if w is not in the \(\left[0, 1\right]\) range


class pygmo.fully_connected(n=0, w=1.)#

Fully connected topology.

This user-defined topology (UDT) represents a complete graph (that is, a topology in which all vertices connect to all other vertices). The edge weight is configurable at construction, and it will be the same for all the edges in the topology.

See also the docs of the C++ class pagmo::fully_connected.

Parameters
  • n (int) – the desired number of vertices

  • w (float) – the weight of the edges

Raises
  • TypeError – if n is negative or too large

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

get_weight()#
Returns

the weight w used in the construction of this topology

Return type

float

num_vertices()#
Returns

the number of vertices in the topology

Return type

int


class pygmo.free_form(t=None)#

Free-form topology.

This user-defined topology (UDT) represents a graph in which vertices and edges can be manipulated freely. Instances of this class can be constructed from either:

Construction from None will initialise a topology without vertices or edges.

Construction from a networkx.DiGraph will initialise a topology whose vertices and edges are described by the input graph. All the edges of the input graph must have a float attribute called weight whose value is in the \(\left[0 , 1\right]\) range.

When t is a topology or a UDT, the constructor will attempt to fetch the NetworkX representation of the input object via the pygmo.topology.to_networkx() method, and will then proceed in the same manner explained in the previous paragraph.

See also the docs of the C++ class pagmo::free_form.

Parameters

t – the object that will be used for construction

Raises
add_edge(i, j, w=1.)#

Add a new edge.

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

Parameters
  • i (int) – the first vertex index

  • j (int) – the second vertex index

  • w (float) – the edge’s weight

Raises
  • TypeError – if i or j are negative or too large

  • ValueError – if i or j are not smaller than the number of vertices, i and j are already adjacent, or if w is not in the \(\left[0, 1\right]\) range

add_vertex()#

Add a vertex.

This method 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).

are_adjacent(i, j)#

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 (int) – the first vertex index

  • j (int) – the second vertex index

Returns

True if i and j are adjacent, False otherwise

Return type

bool

Raises
  • TypeError – if i or j are negative or too large

  • ValueError – if i or j are not smaller than the number of vertices

get_edge_weight(i, j)#

New in version 2.15.

Fetch the weight of the edge connecting i to j.

Parameters
  • i (int) – the source vertex index

  • j (int) – the destination vertex index

Returns

the weight of the edge connecting i to j

Return type

float

Raises
  • TypeError – if i or j are negative or too large

  • ValueError – if either i or j are not smaller than the number of vertices, or i and j are not adjacent

num_vertices()#
Returns

the number of vertices in the topology

Return type

int

remove_edge(i, j)#

Remove an existing edge.

This method will remove the edge connecting i to j.

Parameters
  • i (int) – the first vertex index

  • j (int) – the second vertex index

Raises
  • TypeError – if i or j are negative or too large

  • ValueError – if i or j are not smaller than the number of vertices, or i and j are not adjacent

set_all_weights(w)#

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

Parameters

w (float) – the edges’ weight

Raises

ValueError – if w is not in the \(\left[0, 1\right]\) range

set_weight(i, j, w)#

Set the weight of an edge.

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

Parameters
  • i (int) – the first vertex index

  • j (int) – the second vertex index

  • w (float) – the desired weight

Raises
  • TypeError – if i or j are negative or too large

  • ValueError – if i or j are not smaller than the number of vertices, i and j are not adjacent, or if w is not in the \(\left[0, 1\right]\) range