Skip to content

path size #2

@matheusbg8

Description

@matheusbg8

Hi phoemur,

congratulations on this amazing implementation of the Hungarian Algorithm!

I found a problem with the size of the vector path used on step 5 to track zero primes and zero stars. I believe the size must be at least twice the size of the squared matrix (original). The change should be made on the following line:

std::vector<std::vector<int>> path (sz+1, std::vector<int>(2, 0));

It should be 2*sz instead of sz+1.

You can check this problem with the following input:

tests.push_back({{100,100,100,81},
                 {100,100,100,100},
                 {100,100,100,17},
                 {100,100,100,100},
                 {100,100,100,99}});

After a few iterations you end-up on the following situation:

0' 0 0 0* 0
0 0 0* 19 0'
64 64 64 0' 64
0 0* 0' 19 0
0* 0' 0 18 0

In this situation you will added the 9 elements in bold on the path vector but its size is 5 resulting in a segmentation fault.

Cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions