Skip to content

Conversation

schochastics
Copy link
Contributor

Fix #824

The PR implements the suggested additional check if a graph is simple or not.
This required a lot of adjustments in the tests given that this means that the edge order was changed. I could imagine that this might lead to issues downstream so keeping this for after the 2.2 release.

cc @szhorvat is this what you intended?

@schochastics schochastics added this to the 2.3.0 milestone Jul 15, 2025
@schochastics schochastics changed the title feat: added simple check to graph_from_literal feat: added simple check to graph_from_literal() Jul 15, 2025
@krlmlr
Copy link
Contributor

krlmlr commented Sep 7, 2025

Too risky, let's wait.

@krlmlr krlmlr marked this pull request as draft September 7, 2025 19:07
ids <- seq(along.with = v)
names(ids) <- v
res <- make_graph(unname(ids[edges]), n = length(v), directed = directed)
if (simplify) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why couldn't the check live inside simplify()?

Copy link
Contributor

Choose a reason for hiding this comment

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

i.e., could simplify() be idempotent? https://en.wikipedia.org/wiki/Idempotence

Copy link
Member

@szhorvat szhorvat Sep 10, 2025

Choose a reason for hiding this comment

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

@maelle It is not idempotent because checking if a graph is simple takes time. Simplify will perform the simplification procedure either way, and this may reorder the edges of the graph, even if the graph is simple. The solution @schochastics uses here, i.e. check whether the graph is simple first, is good, and should be kept. The point is not to mess up the edge order for no good reason, and make it easier for people to add edge attributes when constructing from a literal.

It's good to note again that igraph has a cache for basic graph properties, such as whether the graph is simple. If it was cached that the graph is simple, then: is_simple() takes O(1) times, and simplify() does nothing.

I hope this also answers why the check should not be in simplify():

  1. Because it takes time and would slow simplify() down
  2. There is already a kind of check in simplify(), but not for whether the graph is simple, but for whether the graph is already known to be simple (i.e. whether this is cached).

Copy link
Contributor

Choose a reason for hiding this comment

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

thank you!! Yes, it makes sense.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

graph_from_literal() does not preserve edge order

4 participants