Using COST = 1./PROFIT doesn't seem to give the same results as with COST = -PROFIT. Try out the code below. In some cases the solutions result with different profits.
%%
clc
clear
for i = 1:100
m = ceil(rand*20)+1;
n = ceil(rand*20)+1;
a = rand(m,n)+eps;
[assign1 cost1] = munkres(-a);
[assign2 cost2] = munkres(1./a);
if ~all(assign1 == assign2)
disp('Different assignments');
if ~all(sort(assign1) == sort(assign2))
disp('Assignment vectors do not agree on permutations');
disp([assign1;assign2]);
end
assign1=assign1(assign1~=0);m1 = length(assign1);
assign2=assign2(assign2~=0);m2 = length(assign2);
if m1 ~= m2
disp('Assignment Vecs not compatible');
continue;
end
cost1 = sum(sum((a.*accumarray([(1:m1)' assign1'],ones(m1,1),[m n]))));
cost2 = sum(sum((a.*accumarray([(1:m1)' assign2'],ones(m1,1),[m n]))));
disp(sprintf('Cost difference = %f',abs(cost1 - cost2)/cost1));
end
end
Will this work if I want to solve the maximum weight matching? That is, if we have a profit matrix rather than a cost, and we want to maximize the profit rather than minimize the cost. I assume that negating the cost matrix should work but was wondering if you could confirm this.
BTW, this is really fast!