Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

random_graph: edges empty inside random_edge subroutine (changed behaviour of module) #32

Open
kester-habermann opened this issue Nov 13, 2024 · 0 comments

Comments

@kester-habermann
Copy link

I have some old code that used to work in 0.96 and no longer works in the current version. Either this got broken or I misundertand how this is supposed to work and it only worked for me by accident in the past.

#!/usr/bin/perl

use Graph;

sub d($$$$) {
    my ($g, $u, $v, $p) = @_;

    print("edges: ", scalar $g->edges(), "\n");
    my $result = 1;

    $result = 0 if $g->out_degree($u) > 0;
    $result = 0 if $g->in_degree($v) > 0;

    return $result;
}

my @verts = qw/A B C D E/;

my $g = Graph->random_graph(vertices => \@verts,
    random_edge => \&d,
    edges => scalar @verts,
    random_seed => 1234);

print "$g\n";

Inside of the code passed to random_edge, the graph has no edges. This breaks the checks that follow. The code is supposed to generate a random graph with each node having exactly one incoming and one outgoing edge.

Result using version: 0.9732:

edges: 0
edges: 0
edges: 0
edges: 0
edges: 0
C-A,C-B,C-D,C-E,E-C

C has four outgoing edges. The last version this worked as expected was version: 0.9716:

edges: 0
edges: 1
edges: 1
edges: 1
edges: 1
edges: 2
edges: 2
edges: 2
edges: 2
edges: 2
edges: 2
edges: 3
edges: 3
edges: 3
edges: 3
edges: 4
edges: 4
edges: 4
edges: 4
edges: 4
A-B,B-A,C-D,D-E,E-C

Each vertex has exactly one outgoing and one incoming edge and we see that edges inside the subroutine is not empty. Version 0.9717 shows the same behaviour as the latest version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant