in reply to Path computation for SQL generation

This sounds like a graph problem (as in edges-and-nodes graphs, not x-vs-y graphs), so I'd imagine that some of the Graph modules would help. There are some that are core modules, so that's a bonus.

thor

  • Comment on Re: Path computation for SQL generation

Replies are listed 'Best First'.
Re: Re: Path computation for SQL generation
by bean (Monk) on Jan 26, 2004 at 20:01 UTC
    Graph::BFS (breadth-first search) looks like exactly what you need. Tables are vertices, foreign keys are edges (unfortunately, at a quick glance it does not look like you can name edges). Look at its superclass Graph::Traversal for the documentation, which is sparse even there. You'll need to create the graph using Graph::Undirected (again, look at the documentation in the superclass Graph::Base). Here's the Graph package.
      I'm reading through the source (not that I understand much) for Graph. How on earth do I ask the following question:

      Is there a path from X to Y and, if there is, give me the elements I traverse.

      Update: After playing around a bunch, I found the following:

      my $SSSP = $graph->SSSP_Dijkstra($start); my %attrs = $graph->get_attributes($end); my $path = $attrs{path}; die "No path found\n" if !defined $path; print "Path: @$path\n";

      ------
      We are the carpenters and bricklayers of the Information Age.

      Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.