Skip to content

Adjust find_negative_cycle Implementation #723

@paulatsydney

Description

@paulatsydney

Hi guys, appreciate if you have any idea how to implement this:

In the source code of bellman_ford.rs -> fn find_negative_cycle, I want to adjust two parts (of course I copied it out to my own crate):

  1. If the sum value is less than -0.1 (rather than 0), treat it as a negative cycle
    I found the below source code, want to change the IF condition, idea is to change it to "if distance[ix(i)] + w + 0.1 < distance[ix(j)]", but the compiling error doesn't allow me to add f64 to FloatMeasure, how can I achieve it?

// Step 2: Check for negative weight cycle
'outer: for i in g.node_identifiers() {
for edge in g.edges(i) {
let j = edge.target();
let w = *edge.weight();
if distance[ix(i)] + w < distance[ix(j)] {
// Step 3: negative cycle found

  1. Although source node is passed into this function, but in some case, it will return the negative cycle that doesn't contain the source node. How to avoid that?

Thank you so much even you just provide some thoughts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions