Class: BGL::Graph::Reverse

Inherits:
Object show all
Defined in:
lib/roby/graph.rb,
ext/graph/graph.cc,
ext/graph/algorithm.cc

Overview

This class is an adaptor which transforms a directed graph by swapping its edges

Instance Method Summary collapse

Constructor Details

#initialize(g) ⇒ Reverse

Create a directed graph whose edges are the ones of g, but with source and destination swapped.



87
88
89
# File 'lib/roby/graph.rb', line 87

def initialize(g)
    @__bgl_real_graph__ = g
end

Instance Method Details

#each_bfs(root, mode) {|source, dest, info, kind| ... } ⇒ Object

Enumerates edges of the graph following a breadth-first search order. mode is a filter on the kind of edge which shall be enumerated (TREE, NON_TREE and ALL) and root is the source of the search

Yields:

  • (source, dest, info, kind)


624
625
626
627
628
629
# File 'ext/graph/algorithm.cc', line 624

static VALUE graph_reverse_each_bfs(VALUE self, VALUE root, VALUE mode)
{
    VALUE real_graph = graph_view_of(self);
    RubyGraph& graph = graph_wrapped(real_graph);
    return graph_each_bfs(real_graph, make_reverse_graph(graph), root, mode);
}

#each_dfs(root, mode) {|source, dest, info, kind| ... } ⇒ Object

Enumerates edges of the graph following a depth-first search order. mode is a filter on the kind of edge which shall be enumerated (TREE, NON_TREE and ALL) and root is the source of the search

Yields:

  • (source, dest, info, kind)


469
470
471
472
473
474
# File 'ext/graph/algorithm.cc', line 469

static VALUE graph_reverse_each_dfs(VALUE self, VALUE root, VALUE mode)
{
    VALUE real_graph = graph_view_of(self);
    RubyGraph& graph = graph_wrapped(real_graph);
    return graph_each_dfs(real_graph, make_reverse_graph(graph), root, mode);
}

#generated_subgraph([v1, v2, ...]) ⇒ Object

Like Graph#generated_subgraph, but on the reverse graph of graph (where edges has been swapped)



369
370
371
372
373
# File 'ext/graph/algorithm.cc', line 369

static VALUE graph_reverse_generated_subgraphs(int argc, VALUE* argv, VALUE self)
{ 
    VALUE real_graph = rb_iv_get(self, "@__bgl_real_graph__");
    return graph_do_generated_subgraphs(argc, argv, make_reverse_graph(graph_wrapped(real_graph)), real_graph); 
}

#pruneObject

In #each_dfs, call this method to stop developing the current branch



426
427
428
429
430
431
# File 'ext/graph/algorithm.cc', line 426

static VALUE graph_prune(VALUE self)
{
    VALUE thread = rb_thread_current();
    rb_thread_local_aset(thread, rb_intern("@prune"), Qtrue);
    return Qtrue;
}