Skip to content
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

do this code return the minimum assignment or the max one? #30

Open
zhuzy-2018 opened this issue Jul 30, 2021 · 1 comment
Open

do this code return the minimum assignment or the max one? #30

zhuzy-2018 opened this issue Jul 30, 2021 · 1 comment

Comments

@zhuzy-2018
Copy link

sometimes i get the max return:
d2: -0.851823 -0.0848411 0.997337
0.519324 0.752464 0.05258
0.971547 0.304817 -0.311632
dd: -1 -1 0
-1 0 -1
0 -1 -1
pair 0 is :0,2
pair 1 is :1,1
pair 2 is :2,0

sometimes i get the min one:
d2: 0.0511896 -0.0754626 -0.831758
0.541599 0.0293286 -0.483856
0.436718 -0.553582 0.285733
dd: -1 -1 0
0 -1 -1
-1 0 -1
pair 0 is :0,2
pair 1 is :1,0
pair 2 is :2,1

why is that? and how can i fix that?

@Gluttton
Copy link
Contributor

Hello @zhuzy-2018,

-0.851823 -0.0848411 0.997337
0.519324 0.752464 0.05258
0.971547 0.304817 -0.311632

Please note that the algorithm requires as input parameters a nonnegative cost matrix (https://en.wikipedia.org/wiki/Hungarian_algorithm#The_problem).

and how can i fix that?

I would suggest preparing a cost matrix with negative values in the following way:

  1. Find the minimal negative value in the original input matrix. In your matrix, it is -0.851823.
  2. Add a modulo of this value 0.851823 to all matrix elements.
  3. Pass the modified nonnegative matrix into the algorithm.
0         0.7669819  1.84916
1.371147  1.604287   0.904403
1.82337   1.15664    0.540191

The solution will be:

 0    -1    -1
-1    -1     0
-1     0    -1

That means that for the original matrix cost -0.851823 + 0.05258 + 0.304817 = -0.494426 is minimal one.

Please don't hesitate to ask additional questions if it doesn't help.

Gluttton added a commit to Gluttton/munkres-cpp that referenced this issue Nov 5, 2022
Test: build (with and without Qt).
Issue: saebyn#30
Signed-off-by: Gluttton <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants