Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I just ran into this problem. Using the <a href="http://rgl.rubyforge.org/rgl/classes/RGL/Graph.html#M000035" rel="nofollow">reverse method</a> might work, though it might not be the most elegant approach:</p> <pre><code>require 'rgl/adjacency' require 'rgl/bidirectional' class RGL::DirectedAdjacencyGraph def in_degree(v) rdg = self.reverse rdg.adjacent_vertices(v).size end def out_degree(v) self.adjacent_vertices(v).size end end dg=RGL::DirectedAdjacencyGraph[1,2 ,2,3 ,2,4, 4,5, 6,4, 1,6] p dg.in_degree(2) #=&gt; 2 p dg.out_degree(2) #=&gt; 1 p dg.in_degree(1) #=&gt; 0 p dg.out_degree(3) #=&gt; 0 </code></pre> <p>The longer answer is that it doesn't appear to be implemented yet.</p> <p>The way it's supposed to work is by including the RGL::Bidirectional module with with your directed graph class, this will give you the all important each_in_neighbor method. So something like this should work (but doesn't): </p> <pre><code>require 'rgl/adjacency' require 'rgl/bidirectional' class RGL::DirectedAdjacencyGraph include RGL::BidirectionalGraph end dg=RGL::DirectedAdjacencyGraph[1,2 ,2,3 ,2,4, 4,5, 6,4, 1,6] dg.vertices #=&gt; [5, 6, 1, 2, 3, 4] p dg.adjacent_vertices(2) #=&gt; [3, 4] p dg.each_in_neighbor(2) #=&gt; NotImplementedError :( #=&gt; Should be: [1] </code></pre> <p>I haven't dug into the code to see how much work this would be, but that might be a better option depending upon your needs.</p> <p>Edit: I forgot to mention that the source and target attributes are not accessible to an in-degree node. But an alternate approach could be to collect all the edges of interest from the graph and compare them to see if any of them have your node of interest as a target. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload