Skip Menu |

This queue is for tickets about the Graph CPAN distribution.

Report information
The Basics
Id: 120611
Status: resolved
Priority: 0/
Queue: Graph

People
Owner: Nobody in particular
Requestors: user42_kevin [...] yahoo.com.au
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: docs of average_path_length($u,$v)
Date: Tue, 14 Mar 2017 10:58:40 +1100
To: bug-Graph [...] rt.cpan.org
From: Kevin Ryde <user42_kevin [...] yahoo.com.au>
In Graph.pm 0.9704, the pod for average_path_length($u,$v) says "between two vertices". That suggested to me the single (shortest) path $u to $v, which would be the same as path_length($u,$v). I see the code is average of all paths which either start at $u, or end at $v, or something like that. Eg. use strict; use Graph; my $graph = Graph->new(undirected=>1); $graph->add_path(1,2,3); print $graph->average_path_length(1,2),"\n"; prints 1.333, being average of 1--2, 1--3, 3--2. Perhaps the docs could be massaged for clarity. I wondered actually if giving both a start and end would be slightly unusual, but then thought in a directed graph $u==$v could be paths both to and from that vertex or some such which might be interesting.
On Mon Mar 13 19:58:32 2017, user42_kevin@yahoo.com.au wrote: Show quoted text
> In Graph.pm 0.9704, the pod for average_path_length($u,$v) says "between > two vertices". That suggested to me the single (shortest) path $u to > $v, which would be the same as path_length($u,$v). > > I see the code is average of all paths which either start at $u, or end > at $v, or something like that. Eg. > > use strict; > use Graph; > my $graph = Graph->new(undirected=>1); > $graph->add_path(1,2,3); > print $graph->average_path_length(1,2),"\n"; > > prints 1.333, being average of 1--2, 1--3, 3--2.
I have tweaked the docs, but they are fairly clear. In fact, your suggested reasoning is not why it gives 4/3; the logic in average_path_length is matching on 3--2, 1--3, and 1--2. This is not what the docs say ("From $u to $v"). This is what happens when logic is complicated! It is now much simpler. Thanks for the report! Fixed in https://github.com/neilb/Graph/commit/b30f526c236e0e6d1b4939dd83a544b2e7e6b0d2