Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: results from pairs combination

by JadeNB (Chaplain)
on Oct 01, 2008 at 22:34 UTC ( [id://714913]=note: print w/replies, xml ) Need Help??


in reply to Re: results from pairs combination
in thread results from pairs combination

An equivalent way of looking at this is that the poster wants the transitive closure of a relation (or graph). Thus, Graph::TransitiveClosure (which is a submodule of Graph—if that terminology makes sense—and is probably what it calls to find (weakly) connected components anyway) or Algorithms::Graphs::TransitiveClosure are also suitable, and may suggest more directly what's going on.

(Of course, having to call weakly_connected_components instead of the probably more natural connected_components is an artifact of working with directed graphs, which could be avoided by getting a new Graph::Undirected instead.)

UPDATE: Directed graphs, not graphics.

Replies are listed 'Best First'.
Re^3: results from pairs combination
by jdporter (Paladin) on Oct 01, 2008 at 22:46 UTC
    a submodule of Graph—if that terminology makes sense

    In some languages, but [un]fortunately not in Perl.

    an artifact of working with directed graphics

    One method name is as good as another. I originally sought to solve this using undirected graphs, but switched because it looks (lacking any other information) that the input graph is directed. If you treat the graph as undirected, then you might have b,a in the output when the input edge was a,b, and I'd rather have not made the assumption that that would be valid.

    What lacks in both methods is a way to get the result in terms of edges rather than vertices. This forced me to do a bit more work to retrieve the relevant original edges from the vertices returned.

    Between the mind which plans and the hands which build, there must be a mediator... and this mediator must be the heart.
      I think that it is a little misleading to say that one method name is as good as another. Certainly your point about the differences in results is an important one that I hadn't considered; but, absent such peculiarities, I think it's good practice to use a name that's very suggestive to the maintenance programmer of what's going on—no one would name a constructor destroy, even though it could be done; and I think that weakly_connected_components would make a maintainer scratch his or her head over the meaning of 'weakly'. (This is not to say that my suggestion of Algorithms::Graphs::TransitiveClosure, which has one call floyd_warshall to achieve the desired goal, is any better.)
        it's good practice to use a name that's very suggestive to the maintenance programmer of what's going on

        Right. But, imho, there is no difference between ajskdl and jaksld — they're both meaningless. When composing this code, there's no way I could have predicted either method name; I had to read the man page to get them. I don't believe that the situation would be significantly different for a maintenance programmer; she would still have to familiarize herself with the documentation of either method to know what it's about. As it was, I had to grok the documentation of dozens of methods from Graph before I had any confidence which one(s) might best suit the need here. It's essentially a question of information content, and that is very much in the mind of the consumer. For someone (such as myself) who doesn't know what "weakly" means in this context, weakly_connected_components means precisely as much as ajskdl_connected_components, which means as much as connected_components. Even an argument about "extra typing" is spurious, since I copy-and-pasted the names.

        Between the mind which plans and the hands which build, there must be a mediator... and this mediator must be the heart.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://714913]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-03-28 20:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found