Bug 35826: Make copy of cost matrix when substituting inf

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Andreas Jonsson 2024-03-13 12:09:39 +01:00 committed by Katrin Fischer
parent 927c0680b9
commit b8fad11426
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834

View file

@ -556,22 +556,24 @@ RETRY:
# end. # end.
$inf = $max * $num_tasks + 1; $inf = $max * $num_tasks + 1;
my @m0 = map {[(undef) x $num_tasks]} (1..$num_agents);
for ( my $i = 0 ; $i < $num_agents ; $i++ ) { for ( my $i = 0 ; $i < $num_agents ; $i++ ) {
for ( my $j = 0 ; $j < $num_tasks ; $j++ ) { for ( my $j = 0 ; $j < $num_tasks ; $j++ ) {
if ( $m[$i][$j] < 0 ) { if ( $m[$i][$j] < 0 ) {
# Bias towards not allocating items to holds closer to # Bias towards not allocating items to holds closer to
# the end of the queue in the queue if not all holds # the end of the queue in the queue if not all holds
# can be filled by representing infinity with # can be filled by representing infinity with
# different values. # different values.
$m[$i][$j] = $inf + ( $num_tasks - $j ); $m0[$i][$j] = $inf + ( $num_tasks - $j );
} else {
$m0[$i][$j] = $m[$i][$j];
} }
} }
} }
my $res = [ (undef) x $num_agents ]; my $res = [ (undef) x $num_agents ];
Algorithm::Munkres::assign( \@m, $res ); Algorithm::Munkres::assign( \@m0, $res );
my @unallocated = (); my @unallocated = ();
@allocated = (); @allocated = ();
@ -584,7 +586,7 @@ RETRY:
# allocated to nonexisting items ($j >= 0). We just ignore these. # allocated to nonexisting items ($j >= 0). We just ignore these.
next; next;
} }
if ( $m[$i][$j] > $max ) { if ( $m0[$i][$j] > $max ) {
# No finite cost item was assigned to this hold. # No finite cost item was assigned to this hold.
push @unallocated, $j; push @unallocated, $j;