commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r3793 - gnuradio/branches/developers/jcorgan/cppwrap/g


From: jcorgan
Subject: [Commit-gnuradio] r3793 - gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++
Date: Sun, 15 Oct 2006 17:11:37 -0600 (MDT)

Author: jcorgan
Date: 2006-10-15 17:11:37 -0600 (Sun, 15 Oct 2006)
New Revision: 3793

Modified:
   
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_flow_graph.cc
   
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_flow_graph.h
Log:
Work in progress.

Completed gr_flow_graph::calc_graph_partitions and sub-functions.


Modified: 
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_flow_graph.cc
===================================================================
--- 
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_flow_graph.cc
 2006-10-15 22:05:37 UTC (rev 3792)
+++ 
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_flow_graph.cc
 2006-10-15 23:11:37 UTC (rev 3793)
@@ -177,8 +177,6 @@
        // Get its detail and edges that feed into it
        gr_block_detail_sptr detail = (*block_iter)->detail();
        gr_edge_vector_t in_edges = calc_input_edges(*block_iter);
-       printf("Block %s(%li) has %i input edges.\n",
-           (*block_iter)->name().c_str(), (*block_iter)->unique_id(), 
in_edges.size());
 
        // For each edge that feeds into it
        gr_edge_vector_iterator_t edge_iter;
@@ -190,7 +188,7 @@
            gr_block_sptr src_block = edge_iter->first.first;
            gr_buffer_sptr src_buffer = src_block->detail()->output(src_port);
 
-           printf("Setting input buffer on %i:%s(%i).\n", dst_port, 
+           printf("Setting input buffer on %i:%s(%li).\n", dst_port, 
                edge_iter->second.first->name().c_str(),
                edge_iter->second.first->unique_id());
 
@@ -349,7 +347,6 @@
        assert(graph.size());
 
        result.push_back(topological_sort(graph));
-       printf("n=%i g=%i r=%i\n", nodes.size(), graph.size(), result.size());
        
        // Remove all nodes in graph from node list
        gr_block_vector_iterator_t block_iter;
@@ -357,6 +354,7 @@
            nodes.erase(find(nodes.begin(), nodes.end(), *block_iter));
     }
 
+    printf("Flow graph has %i subgraphs.\n", result.size());
     return result;
 }
 
@@ -384,18 +382,48 @@
 
 void gr_flow_graph::reachable_dfs_visit(gr_block_sptr block, 
gr_vertex_vector_t &vertices)
 {
-    printf("Check for reachability of node %s(%li)\n", block->name().c_str(), 
block->unique_id());
-
     // Find vertex corresponding to block, mark visited
+    // FIXME: pass in the vector when recursing instead of looking it up again
+    gr_vertex_t vertex;
     gr_vertex_vector_iterator_t vertex_iter;
     for (vertex_iter = vertices.begin(); vertex_iter != vertices.end(); 
vertex_iter++)
-       if (vertex_iter->first == block)
+       if (vertex_iter->first == block) {
+           vertex = *vertex_iter;
            vertex_iter->second = GR_VERTEX_BLACK;
+    }
     
     // Recurse into adjacent vertices
-    // NOP
+    gr_vertex_vector_t adjacent = calc_adjacent_vertices(vertex, vertices);
+    for (vertex_iter = adjacent.begin(); vertex_iter != adjacent.end(); 
vertex_iter++)
+       if (vertex_iter->second == GR_VERTEX_WHITE)
+           reachable_dfs_visit(vertex_iter->first, vertices);
 }
 
+gr_vertex_vector_t gr_flow_graph::calc_adjacent_vertices(gr_vertex_t vertex, 
gr_vertex_vector_t &vertices)
+{
+    gr_vertex_vector_t result;
+    
+    // Find any blocks that are inputs or outputs
+    gr_block_vector_t matches;
+    gr_edge_vector_iterator_t edge_iter;
+    for (edge_iter = d_edges.begin(); edge_iter != d_edges.end(); edge_iter++) 
{
+       if (edge_iter->first.first == vertex.first)
+           matches.push_back(edge_iter->second.first);
+       if (edge_iter->second.first == vertex.first)
+           matches.push_back(edge_iter->first.first);
+    }    
+
+    // Then collect those vertices that match those blocks
+    gr_vertex_vector_iterator_t vertex_iter;
+    for (vertex_iter = vertices.begin(); vertex_iter != vertices.end(); 
vertex_iter++) {
+       gr_block_vector_iterator_t match = find(matches.begin(), matches.end(), 
vertex_iter->first);
+       if (match != matches.end())
+           result.push_back(*vertex_iter);     
+    }
+    
+    return result;
+}
+
 gr_block_vector_t gr_flow_graph::topological_sort(gr_block_vector_t blocks)
 {
     gr_block_vector_t result;

Modified: 
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_flow_graph.h
===================================================================
--- 
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_flow_graph.h
  2006-10-15 22:05:37 UTC (rev 3792)
+++ 
gnuradio/branches/developers/jcorgan/cppwrap/gnuradio-examples/c++/gr_flow_graph.h
  2006-10-15 23:11:37 UTC (rev 3793)
@@ -81,6 +81,7 @@
     gr_edge_vector_t calc_input_edges(gr_block_sptr block);
     gr_block_vector_t calc_reachable_vertices(gr_block_sptr block, 
gr_block_vector_t &blocks);
     void reachable_dfs_visit(gr_block_sptr block, gr_vertex_vector_t 
&vertices);
+    gr_vertex_vector_t calc_adjacent_vertices(gr_vertex_t vertex, 
gr_vertex_vector_t &vertices);
     gr_block_vector_t topological_sort(gr_block_vector_t blocks);
 
     static const int s_fixed_buffer_size = GR_FIXED_BUFFER_SIZE;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]