X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=src%2Fgenealgorithms.cpp;h=3fb2aaac0c7f180bd73edde5918731c7bcc8c8e0;hb=a45ea752862a45a0868940280aeb837af270cf22;hp=174c6f7b0414277b006b562f2736a83077db9fb7;hpb=dcd966c5fca7dca53ca1f605f70f13f019d29771;p=germs.git diff --git a/src/genealgorithms.cpp b/src/genealgorithms.cpp index 174c6f7..3fb2aaa 100644 --- a/src/genealgorithms.cpp +++ b/src/genealgorithms.cpp @@ -94,9 +94,20 @@ size_t countCycles(const GeneOrder& go){ } size_t inversionDistance(const GeneOrder& go){ - size_t cycles = countCycles(go); + size_t distance = go.size() - 1; + distance -= countCycles(go); + + ComponentTree t(findComponents(go)); + t.makeUnoriented(); + size_t leaves = t.countLeaves(); + distance += leaves; + if (leaves % 2 != 0){ + size_t sb = t.shortBranches(); + if (sb == 0) + distance += 1; + } - return go.size() - 1 - cycles; + return distance; } int sign(Gene g){