DiGraph

class DiGraph

Directed graph wrapper to create and query a lemon::SmartDigraph.

Public Functions

DiGraph(const int &num_nodes_in, const int &num_arcs_in, const int &source_id_in, const int &sink_id_in)

Constructor. Allocates memory for the number of nodes/arcs (uses LEMON allocators) and saves source/sink user ids.

Parameters
  • num_nodes_in, int.[in] Number of nodes in the graph.

  • num_arcs_in, int.[in] Number of arcs in the graph.

  • source_id_in, int.[in] User id for source node.

  • sink_id_in, int.[in] User id for sink node.

void addNodes(const std::vector<int> &user_nodes)

Add nodes to LEMON SmartDigraph.

Parameters

user_nodes, vector[in] of int. Array with user nodes

void addEdge(const int &tail, const int &head, const double &weight, const std::vector<double> &resource_consumption)

Add arcs to LEMON SmartDigraph.

Parameters
  • tail, int.[in] User id for tail node.

  • head, int.[in] User id for head node.

  • weight, double.[in] Arc weight/cost.

  • resource_consumption, vector[in] of double. Array with consumption of resources for this arc. Optional (may be empty if custom REFs are defined).

inline LemonNode head(const LemonArc &arc) const

Extract head node for a given arc.

Parameters

arc, lemon::SmartDigraph::Arc.[in]

Returns

lemon::SmartDigraph::Node with head of arc

inline LemonNode tail(const LemonArc &arc) const

Extract tail node for a given arc.

Parameters

arc, lemon::SmartDigraph::Arc.[in]

Returns

lemon::SmartDigraph::Node with tail of arc

AdjVertex getAdjVertex(const LemonArc &arc, const bool &forward) const

Get the adjacent vertex.

Parameters
  • arc, lemon::SmartDigraph::Arc.[in]

  • forward, bool.[in] Whether arc is checked forward or not (backward).

Returns

AdjVertex with arc information

inline LemonNode getLNodeFromId(const int &id) const

Extract lemon node from a given lemon id

Parameters

id, lemon::SmartDigraph::Arc.[in]

Returns

lemon::SmartDigraph::Node corresponding to the lemon id

int getNodeIdFromUserId(const int &user_id) const

For conversion between user node labels and LemonGraph internal.

Extract lemon id from a given user id

Parameters

user_id, int.[in]

Returns

int with lemon id

inline Vertex getVertexFromLNode(const LemonNode &node) const

Extract lemon id for a given node

Parameters

node, lemon::SmartDigraph::Node.[in]

Returns

Vertex corresponding to the lemon node

inline const double &getWeight(const LemonArc &arc) const

Extract arc weight from arc map

Parameters

arc, lemon::SmartDigraph::Arc.[in]

Returns

double with arc weight

inline int getId(const LemonArc &arc) const

Extract lemon id for a given arc

Parameters

arc, lemon::SmartDigraph::Arc.[in]

Returns

int with lemon id for the arc

inline int getId(const LemonNode &node) const

Extract lemon id for a given node

Parameters

node, lemon::SmartDigraph::Node.[in]

Returns

int with lemon id for then node

Public Members

int number_vertices

int. Number of nodes/vertices in the graph.

int number_edges

int. Number of arcs/edges in the graph.

Vertex source

Source and sink vertices.

std::unique_ptr<LemonGraph> lemon_graph_ptr

Pointer to lemon graph (in this case lemon::SmartDigraph)

std::unique_ptr<LemonGraph::ArcMap<double>> weight_map_ptr

Pointer to lemon map containing arc weights/costs.

std::unique_ptr<LemonGraph::ArcMap<std::vector<double>>> res_map_ptr

Pointer to lemon map containing arc resource consumptions.

std::vector<Vertex> vertices

Vector with vertices.