Validate link as if it's already added

Is there a way in the linkValidation function I can traverse the graph as if the link has already been added and then reject its creation if certain conditions aren’t met?

I’m using findNodesConnected and findNodesOutOf functions to discover if this newly created link causes any node to be unreachable. So I want to traverse the graph as if the link is already there.

Technically, I guess I can listen to model changes and immediately remove the link after it’s been added but I prefer to do it at the validation phase.

If I understand you correctly, no, I don’t think there’s a general way for the built-in traversal methods to ignore some nodes or links.

However some traversal methods such as the tree-traversing methods ignore Links that are not Link.isTreeLink.

But I’m curious how adding a Link could cause a Node to become unreachable if it had been reachable before.

Think about it this way. In this picture I only care about the graph starting from S. So C and D are kinda like an island I don’t care for now. But as soon as the red link is added, suddenly C and D are unreachable because the link is in the opposite direction and now I have a graph with unreachable nodes.

Does that make sense? It’s not a tree. It’s a DAG.

To me, I would think that “D” is unreachable from “S” both before and after creating the new link. But my opinion doesn’t really matter.

I assume you have figured out a way to implement what you want.

Just a suggestion but it would be great for findNodesConnected and findNodesOutOf and other similar methods to accept a flag or something to consider this temp link or not. Like:

findNodesOutOf(pid, considerTempLinkWhenTraversing = false) {
  // ...
}

Or if link validation had a post-insertion phase as well:

LinkingBaseTool:
 isValidLinkBefore()
 isValidLinkAfter()

That sounds just like the LinkingBaseTool.isValidCycle method which takes an optional “ignore” Link argument.

That would have been great if it had a consider: Link argument as well. With ignore it opts out of an existing link but I want to opt-in to consider a temp link.

Anyway, I think you have your answer. Sorry.

Thanks for your prompt responses. I’ll figure something out.