#include <dai/graph.h>
Public Member Functions | |
Neighbor () | |
Default constructor. | |
Neighbor (size_t iter, size_t node, size_t dual) | |
Constructor that sets the Neighbor members according to the parameters. | |
operator size_t () const | |
Cast to size_t returns node member. | |
Public Attributes | |
size_t | iter |
Corresponds to the index of this Neighbor entry in the vector of neighbors. | |
size_t | node |
Contains the number of the neighboring node. | |
size_t | dual |
Contains the "dual" iter. |
Sometimes we want to do an action, such as sending a message, for all edges in a graph. However, most graphs will be sparse, so we need some way of storing a set of the neighbors of a node, which is both fast and memory-efficient. We also need to be able to go between viewing node a as a neighbor of node b, and node b as a neighbor of node a. The Neighbor struct solves both of these problems. Each node has a list of neighbors, stored as a std::vector<Neighbor>, and extra information is included in the Neighbor struct which allows us to access a node as a neighbor of its neighbor (the dual
member).
By convention, variable identifiers naming indices into a vector of neighbors are prefixed with an underscore ("_"). The neighbor list which they point into is then understood from context. For example:
Here, i is the "absolute" index of node i, but _j is understood as a "relative" index, giving node j 's entry in nb(i)
. The corresponding Neighbor structure can be accessed as nb(i,_j)
or nb(i)[_j]
. The absolute index of _j, which would be called j, can be recovered from the node
member: nb(i,_j).node
. The iter
member gives the relative index _j, and the dual
member gives the "dual" relative index, i.e., the index of i in j 's neighbor list.
There is no easy way to transform a pair of absolute node indices i and j into a Neighbor structure relative to one of the nodes. Such a feature has never yet been found to be necessary. Iteration over edges can always be accomplished using the Neighbor lists, and by writing functions that accept relative indices:
dai::GraphAL::Neighbor::Neighbor | ( | ) | [inline] |
Default constructor.
dai::GraphAL::Neighbor::Neighbor | ( | size_t | iter, | |
size_t | node, | |||
size_t | dual | |||
) | [inline] |
Constructor that sets the Neighbor members according to the parameters.
dai::GraphAL::Neighbor::operator size_t | ( | ) | const [inline] |
Cast to size_t
returns node
member.
size_t dai::GraphAL::Neighbor::iter |
Corresponds to the index of this Neighbor entry in the vector of neighbors.
size_t dai::GraphAL::Neighbor::node |
Contains the number of the neighboring node.
size_t dai::GraphAL::Neighbor::dual |
Contains the "dual" iter.