Class tdgraph

Inheritance Relationships

Base Type

  • public rer::client< tdgraph >

Derived Type

Class Documentation

class tdgraph : public rer::client<tdgraph>

Representation of an overall task (the root task) as a tree representing the task decomposition of the root task at different granularities (i.e. tasks of different levels of complexity).

This is the main input into the task bi_tdgraph_executive, and does not do much on its own. Tasks can have any number of children.

Once you set the root node or the children of a specific node, you cannot change them. Uses boost::graph bidirectional graph, adjacency list flavor.

Ideally the graph nodes would be std::unique_ptr<T>, but that does not currently work with the boost libraries, and shared_ptr<T> is not right either, because the graph owns the tasks, so raw pointers are used instead.

Subclassed by cosm::ta::ds::bi_tdgraph

Public Types

using const_walk_cb = std::function<void(const polled_task*)>
using vertex_type = std::unique_ptr<polled_task>

We want to convey that the graph owns the vertices in it, which we do by requiring the application to pass unique_ptrs to set up the graph. HOWEVER, boost::add_vertex does not allow for move-construction only types (apparently), and so unique_ptr does not work as the underlying vertice type in the graph, and we have to use shared ptr.

using vertex_vector = std::vector<vertex_type>
using walk_cb = std::function<void(polled_task*)>

Public Functions

tdgraph(const tdgraph&) = default
tdgraph(void)
~tdgraph(void) override = default
std::vector<polled_task*> children(const polled_task *parent) const

Return the children of the specified task.

Parameters:

parent – The parent task.

Returns:

The children. Will ALWAYS be of length 2, unless the root task is passed in, in which case it will have length 3, and the self-reference to the root task will be at index 0.

polled_task *find_vertex(const std::string &task_name)
const polled_task *find_vertex(const std::string &task_name) const

Find the task vertex corresponding to the specified task name.

Returns:

The task vertex, or NULL if no such task.

polled_task *find_vertex(int id)
const polled_task *find_vertex(int id) const

Find the task vertex corresponding to the specified vertex id.

Returns:

The task vertex, or NULL if no such vertex id

inline size_t n_vertices(void) const
tdgraph &operator=(const tdgraph&) = delete
polled_task *root(void)
const polled_task *root(void) const
status_t set_children(const polled_task *parent, vertex_vector children)

Set the children for an existing node.

Parameters:
  • parent – The parent node, which MUST be a partitionable task.

  • children – The list of children (any #) to associate with the parent.

Returns:

status_t.

status_t set_children(const std::string &parent, vertex_vector children)
status_t set_root(std::unique_ptr<polled_task> v)

Set the root of the graph/tree.

This needs to be the first node added to the graph.

Parameters:

v – The root.

Returns:

status_t.

int vertex_depth(const polled_task *v) const

Return the depth of the specified task in the graph, as measured from the root (the root is depth 0).

Parameters:

v – The vertex to obtain the depth of.

Returns:

The depth of the vertex from the root, or -1 if no such vertex exists in the graph.

int vertex_id(const polled_task *v) const

Retrieve the numeric ID of the vertex.

Returns:

The vertex ID, or -1 if no such vertex in graph.

polled_task *vertex_parent(const polled_task *v) const

Get the parent of a node in the graph, given a node in the graph.

Returns:

The parent of the vertex, or NULL if vertex not in graph.

void walk(const const_walk_cb &f) const
void walk(const walk_cb &f)

Run the callback on each node in the graph, in an arbitrary order.

Parameters:

f – The callback.

Public Static Functions

static polled_task *vertex_parent(const tdgraph &graph, const polled_task *v)

Get the parent of a vertex in the graph, given the graph and vertex.

Returns:

The parent of the vertex, or NULL if vertex not in graph.