Skip to content

Add DigraphByEdges variant for list of arbitrary vertex labels and list of edges - #957

Open
William-Kenyon wants to merge 10 commits into
digraphs:mainfrom
William-Kenyon:fix-issue-778
Open

William-Kenyon wants to merge 10 commits into
digraphs:mainfrom
William-Kenyon:fix-issue-778

Conversation

@William-Kenyon

Copy link
Copy Markdown
Collaborator

Fixes #778, for adding a way of constructing a Digraph with two lists: vertex_labels, and edges, where vertex labels can be more than just integers. This is basically the same as the existing 3-argument constructor (vertices, source, range), except source and range are zipped together.

Based on @wilfwilson's code snippet.

@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.45%. Comparing base (f4fc1ac) to head (0b50b4e).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
gap/digraph.gi 88.88% 4 Missing ⚠️

❌ Your patch check has failed because the patch coverage (90.00%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #957      +/-   ##
==========================================
- Coverage   97.47%   97.45%   -0.03%     
==========================================
  Files          51       53       +2     
  Lines       21301    21446     +145     
  Branches      639      639              
==========================================
+ Hits        20763    20900     +137     
- Misses        473      481       +8     
  Partials       65       65              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@William-Kenyon William-Kenyon added the VIP Pull requests done by participants of the VIP programme. label Oct 15, 2026

@james-d-mitchell james-d-mitchell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @William-Kenyon. I think what you've implemented should be a method for DigraphByEdges and not an overload of Digraph though. Can you please update it so that it is this, and address the other comments too? Thanks!

Comment thread gap/digraph.gi Outdated
Comment on lines +489 to +490
fi;
if not (IsSubset(vertex_labels, Union(edges))) then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fi;
if not (IsSubset(vertex_labels, Union(edges))) then
elif not IsSubset(vertex_labels, Union(edges)) then

save one line, and the brackets are superfluous, so please remove.

Comment thread gap/digraph.gi Outdated
ErrorNoReturn("<vertex_labels> contains duplicate labels,");
fi;
if not (IsSubset(vertex_labels, Union(edges))) then
ErrorNoReturn("<edges> references a label that isn't in <vertex_labels>,");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's be useful if this line could include some details of which label is bad (position, and value), and the value of vertex_labels maybe too?

@William-Kenyon William-Kenyon changed the title Add variant of Digraph constructor for list of vertex labels and list of edges Add DigraphByEdges variant for list of arbitrary vertex labels and list of edges Oct 16, 2026
Comment thread gap/digraph.gi Outdated
duplicates := List(Filtered(label_counts, x -> x[2] > 1), x -> x[1]);
if not IsEmpty(duplicates) then
ErrorNoReturn("<vertex_labels> contains duplicate labels: ",
duplicates, ",");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
duplicates, ",");
duplicates);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To explain at some point in the distant past GAP errors were hard to parse, and we inserted a comma at the end of every error to delineate our comments from the general error handling in GAP. I don't think this is any longer necessary, so we don't need the commas any more. I will try to open a PR just now to remove the remaining instances.

@james-d-mitchell james-d-mitchell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. There are a few minor things to update in the error messages. This might be a separate issue but what if I want to do: DigraphByEdges(IsMutableDigraph, ...) maybe this doesn't exist already, if not, then we should add an issue to implement this (so not part of the current PR).

Comment thread gap/digraph.gi Outdated

label_counts := Collected(vertex_labels);
duplicates := List(Filtered(label_counts, x -> x[2] > 1), x -> x[1]);
if not IsEmpty(duplicates) then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be tempted to just call IsDuplicateFreeList here (i.e. if not IsDuplicateFreeList(vertex_labels) then) and only then do the Collected line and duplicates if this fails. This way we'll avoid the overhead, unless something goes wrong, in which case we don't care about the overhead anymore.

Comment thread gap/digraph.gi Outdated
duplicates := List(Filtered(label_counts, x -> x[2] > 1), x -> x[1]);
if not IsEmpty(duplicates) then
ErrorNoReturn("<vertex_labels> contains duplicate labels: ",
duplicates, ",");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To explain at some point in the distant past GAP errors were hard to parse, and we inserted a comma at the end of every error to delineate our comments from the general error handling in GAP. I don't think this is any longer necessary, so we don't need the commas any more. I will try to open a PR just now to remove the remaining instances.

Comment thread gap/digraph.gi Outdated
badpos := PositionProperty(edges, e -> not IsList(e) or Length(e) <> 2);
if badpos <> fail then
ErrorNoReturn("invalid edge ", edges[badpos], " in position ", badpos,
" in <edges>; edges must be pairs of elements,");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
" in <edges>; edges must be pairs of elements,");
" in <edges>; edges must be lists of length 2,");

Comment thread gap/digraph.gi Outdated
e -> not (e[1] in labels and e[2] in labels));
if badpos <> fail then
ErrorNoReturn("invalid edge ", edges[badpos], " in <edges> at position ",
badpos, "; edges must reference vertices from ",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
badpos, "; edges must reference vertices from ",
badpos, "; edges must only contain items from <vertex_labels> (= ",

Comment thread gap/digraph.gi Outdated
fi;

nrverts := Length(vertex_labels);
D := DigraphByEdges(List(edges,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably this should be the method for DigraphByEdgesNC(vertex_labels, edges)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

VIP Pull requests done by participants of the VIP programme.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add new variant/sibling of DigraphByEdges that can accept edges defined in terms of labelled vertices

2 participants