Skip to content

Implementation of DigraphInsertEdge and DigraphReduceEdge#899

Open
linuskuehnle wants to merge 3 commits intodigraphs:mainfrom
linuskuehnle:main
Open

Implementation of DigraphInsertEdge and DigraphReduceEdge#899
linuskuehnle wants to merge 3 commits intodigraphs:mainfrom
linuskuehnle:main

Conversation

@linuskuehnle
Copy link

Implemented DigraphInsertEdge and DigraphReduceEdge.
These functions already exist in the Simplicial Surfaces package, which I am currently working on with Meike Weiß at RWTH Aachen University.
For reference, the corresponding functions there are implemented as EdgeInsertion and EdgeReduction.

Both DigraphInsertEdge and DigraphReduceEdge check whether the given digraph D is symmetric, and modifications to D preserve this symmetry.
Should D therefore retain the symmetric tag by explicitly calling SetIsSymmetricDigraph after modification?
If so, is an additional call to SetDigraphSymmetricClosureAttr required?

@james-d-mitchell
Copy link
Member

Thanks for the contribution @linuskuehnle ! I'll try to review your PR and answer your questions early next week.

Copy link
Member

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

Choose a reason for hiding this comment

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

Generally this looks pretty good, thanks for the contribution @linuskuehnle ! If you could please address the comments, then I'll be happy to merge this.

then then this operation inserts a new edge between <A>edge1</A> and
<A>edge2</A>.
<A>edge1</A> and <A>edge2</A> are split up into two new edges each, which are
all adjacent to the inserted edge. Hence, the vertices of the inserted edge both
Copy link
Member

Choose a reason for hiding this comment

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

What does it mean for an edge to be adjacent to an edge?

<Returns>A digraph.</Returns>
<Description>
If <A>edge1</A> and <A>edge2</A> are distinct pairs of vertices of <A>digraph</A>,
then then this operation inserts a new edge between <A>edge1</A> and
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
then then this operation inserts a new edge between <A>edge1</A> and
then this operation inserts a new edge between <A>edge1</A> and

<A>edge2</A>.
<A>edge1</A> and <A>edge2</A> are split up into two new edges each, which are
all adjacent to the inserted edge. Hence, the vertices of the inserted edge both
have a degree of 3.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
have a degree of 3.
have a degree of 3.<P/>

all adjacent to the inserted edge. Hence, the vertices of the inserted edge both
have a degree of 3.

The opposite operation is <Ref Oper="DigraphReduceEdge"/>.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The opposite operation is <Ref Oper="DigraphReduceEdge"/>.
The opposite operation is <Ref Oper="DigraphReduceEdge"/>.<P/>

A new digraph constructed from <A>digraph</A> is returned,
unless <A>digraph</A> belongs to <Ref Filt="IsMutableDigraph"/>;
in this case changes are made directly to <A>digraph</A>, which is then returned.
The <A>digraph</A> must not belong to <Ref Filt="IsMultiDigraph"/>. <P/>
Copy link
Member

Choose a reason for hiding this comment

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

Maybe say that an error is thrown if IsMultiDigraph is true?


DIGRAPHS_CheckInsertEdgeDigraph(D, edge1, edge2);

numVertices := Maximum(DigraphVertices(D));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
numVertices := Maximum(DigraphVertices(D));
numVertices := DigraphNrVertices(D);

return MakeImmutable(D);
end);

DIGRAPHS_CheckReduceEdgeDigraph := function(D, edge)
Copy link
Member

Choose a reason for hiding this comment

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

Same two comments for this function:

  1. It doesn't need to exist;
  2. it can be shortened a little by combining multiple if statements with elif

function(D, edge1, edge2)
D := DigraphInsertEdge(DigraphMutableCopy(D), edge1, edge2);

return MakeImmutable(D);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return MakeImmutable(D);
{D, edge1, edge2} -> MakeImmutable(DigraphInsertEdge(DigraphMutableCopy(D), edge1, edge2)));


leftVertexOutNeighbours := OutNeighboursOfVertex(D, edge[1]);
rightVertexOutNeighbours := OutNeighboursOfVertex(D, edge[2]);
allVertexOutNeighbours := Union(leftVertexOutNeighbours,
Copy link
Member

Choose a reason for hiding this comment

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

I'd move this down after the checks in 713, to avoid computing this in case an error is already given.

InstallMethod(DigraphReduceEdge,
"for a symmetric digraph and a dense list",
[IsImmutableDigraph, IsDenseList],
function(D, edge)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
function(D, edge)
{D, edge} -> MakeImmutable(DigraphReduceEdge(DigraphMutableCopy(D), edge)));

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

Successfully merging this pull request may close these issues.

2 participants