-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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
KAFKA-15022: Detect negative cycle from one source #14696
Conversation
Will this impact the performance? If so, do we plan to add a performance comparison? |
|
||
@Override | ||
public int compare(final V o1, final V o2) { | ||
if (o1 == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we plan to have different results returned under two different null cases? If not, maybe we can do
if (o1 == null || o2 == null) {
return -1;
}
to simplify the condition.
|
||
private void removeDummySourceNode(final Graph<V> residualGraph) { | ||
if (!residualGraph.isResidualGraph) { | ||
throw new IllegalStateException("Graph should be residual graph to add dummy source node"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe 'Graph should be residual graph to remove dummy source node' ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
@ex172000 , this will improve performance. Since it's obvious that we replace the loop of number of nodes to a single iteration, I'm not planning to add comparison. |
@Override | ||
public int compare(final V o1, final V o2) { | ||
if (o1 == null || o2 == null) { | ||
return -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If one of both is null
, why is o1
considered smaller than o2
? Would it not be better to define null
as either smallest or largest globally? -- Also, should we return zero if both are null
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, if both are null
, we can return 0;
@@ -117,6 +131,8 @@ private Graph(final boolean isResidualGraph) { | |||
} | |||
|
|||
public void addEdge(final V u, final V v, final int capacity, final int cost, final int flow) { | |||
Objects.requireNonNull(u); | |||
Objects.requireNonNull(v); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need these checks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null
is a special node we introduced in graph as dummy source to detect negative cycle. So users can use it
Introduce a dummy node connected to every other node and run Bellman-ford from the dummy node once instead of from every node in the graph. Reviewers: Qichao Chu (@ex172000), Matthias J. Sax <[email protected]>
Introduce a dummy node connected to every other node and run Bellman-ford from the dummy node once instead of from every node in the graph. Reviewers: Qichao Chu (@ex172000), Matthias J. Sax <[email protected]>
Introduce a dummy node connected to every other node and run Bellman-ford from the dummy node once instead of from every node in the graph. Reviewers: Qichao Chu (@ex172000), Matthias J. Sax <[email protected]>
Introduce a dummy node connected to every other node and run Bellman-ford from the dummy node once instead of from every node in the graph. Reviewers: Qichao Chu (@ex172000), Matthias J. Sax <[email protected]>
Description
Introduce a dummy node connected to every other node and run Bellman-ford from the dummy node once instead of from every node in the graph.
Testing
Existing test
Committer Checklist (excluded from commit message)