Skip to content

transitive_closure(reflexive => 0) omits isolated vertices #40

@michro6ok

Description

@michro6ok

When computing the non-reflexive transitive closure of a directed graph, isolated vertices are missing from the result.

Test case:

#!/usr/bin/perl
use strict;
use warnings;
use Graph;

my $g = Graph->new(directed => 1);
$g->add_edge('A', 'B');
$g->add_edge('B', 'C');
$g->add_vertex('d'); # <- isolated
$g->add_vertex('e'); # <- isolated

print "graph:" . $g->stringify . "\n";
print "transitive closure:" . $g->transitive_closure(reflexive => 0)->stringify . "\n";

Output:

graph:A-B,B-C,d,e
transitive closure:A-B,A-C,B-C

Expected behavior:

graph:A-B,B-C,d,e
transitive closure:A-B,A-C,B-C,d,e

The transitive closure should include all vertices from the original graph, including isolated ones (e, f). These are currently omitted in the closure result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions