Skip Menu |

This queue is for tickets about the Graph CPAN distribution.

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

People
Owner: Nobody in particular
Requestors: Esraa_Swillam [...] mentor.com
Cc:
AdminCc:

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



Subject: longest path is not calculated correctly in this case
Date: Thu, 16 Jan 2014 13:02:44 +0000
To: "bug-Graph [...] rt.cpan.org" <bug-Graph [...] rt.cpan.org>
From: "Swillam, Esraa" <Esraa_Swillam [...] mentor.com>
Hi there, I have a weighted directed acyclic graph and I wan tto calculate its longest path length If my graph looks like below, longest path or diameter is not calculated correctly it gets confused between last 2 branches and pick the one with smaller weight instead [cid:image001.png@01CF12CC.017E5A80] my $g = Graph::Directed->new; my $edge_list = [ { u=>"a", v=>"b", l=>2, w=>4.25, }, { u=>"b", v=>"c", l=>2, w=>2, }, { u=>"c", v=>"d", l=>2, w=>2, }, { u=>"d", v=>"e", l=>2, w=>2, }, { u=>"d", v=>"f", l=>2, w=>2, }, { u=>"e", v=>"g", l=>6, w=>2, }, { u=>"f", v=>"g", l=>4, w=>2, }, ]; foreach my $edge (@$edge_list) { message ("$edge->{u}:$edge->{v}:$edge->{l}:$edge->{w}"); $g->add_weighted_edge ($edge->{u},$edge->{v},$edge->{l}); } print "The graph is $g\n"; my $check_DAG= $g->is_directed_acyclic_graph; my $gd = $g->diameter; my @lp = $g->longest_path; my $lp = $g->longest_path; my $edge_check = $g->has_edge("1,2", "3,4"); message ("This Graph is DAG $check_DAG"); message ("Graph diameter is $gd"); message ("Graph longest shortest path length is $lp"); message ("Graph longest shortest path length is @lp"); output: The graph is a-b,b-c,c-d,d-e,d-f,e-g,f-g This Graph is DAG 1 Graph diameter is 12 Graph longest shortest path length is 12 Graph longest shortest path length is a b c d f g Thanks for providing fast feedback Thanks -Regards Esraa

Message body is not shown because it is too large.

Download image001.png
image/png 19.7k
image001.png
I think the result is correct. The longest shortest is NOT the same thing as the longest path. Yes, it is very confusing. (1) the shortest paths are the paths with the shortest lengths over all the vertex pairs. (2) then the longest shortest path is the longest of all of the shortest paths. As for the longest path (or a longest path, in case there are multiple of equal length)... in the general case, that is NP-hard, I think. For DAGs, one should be able to find it in, I think, O(V + E). But there's no interface in Graph for that.