NAME Algorithm::Bertsekas - auction algorithm for the assignment problem. This is a perl implementation for the auction algorithm for the asymmetric (N<=M) assignment problem. DESCRIPTION The assignment problem in the general form can be stated as follows: "Given N jobs (or persons), M tasks (or objects) and the effectiveness of each job for each task, the problem is to assign each job to one and only one task in such a way that the measure of effectiveness is optimised (Maximised or Minimised)." "Each assignment problem has associated with a table or matrix. Generally, the rows contain the jobs (or persons) we wish to assign, and the columns comprise the tasks (or objects) we want them assigned to. The numbers in the table are the costs associated with each particular assignment." In Auction Algorithm (AA) the N persons iteratively submit the bids to M objects. The AA take cost Matrix_N×M = [aij] as an input and produce assignment as an output. In the AA persons iteratively submit the bids to the objects which are then reassigned to the bidders which offer them the best bid. Another application is to find the (nearest/more distant) neighbors. The distance between neighbors can be represented by a matrix or a weight function, for example: 1: f(i,j) = abs ($array1[i] - $array2[j]) 2: f(i,j) = ($array1[i] - $array2[j]) ** 2 SYNOPSIS use Algorithm::Bertsekas qw(auction); my @array1 = ( 22, 15, 98, 1 ); my @array2 = ( 72, 99, 29, 88, 12, 26, 41 ); my @input_matrix; for my $i ( 0 .. $#array1 ){ my @weight_function; for my $j ( 0 .. $#array2 ){ my $weight = abs ($array1[$i] - $array2[$j]); # $weight = ($array1[$i] - $array2[$j]) ** 2; # another option push @weight_function, $weight; } push @input_matrix, \@weight_function; } 72 99 29 88 12 26 41 22 [ 50 77 7 66 10 4 19 ] 15 [ 57 84 14 73 3 11 26 ] 98 [ 26 1 69 10 86 72 57 ] 1 [ 71 98 28 87 11 25 40 ] Alternatively, we can define the matrix with its elements: my @input_matrix = ( [ 50, 77, 7, 66, 10, 4, 19 ], [ 57, 84, 14, 73, 3, 11, 26 ], [ 26, 1, 69, 10, 86, 72, 57 ], [ 71, 98, 28, 87, 11, 25, 40 ] ); my ( $optimal, $assignement_ref, $output_index_ref ) = auction( matrix_ref => \@input_matrix, maximize_total_benefit => 0, verbose => 3 ); Objective: to Minimize the total benefit Number of left nodes: 4 Number of right nodes: 7 Number of edges: 28 Solution: Optimal assignment: sum of values = 30 Feasible assignment condition: stepsize = 0.2 < 1/4 = 0.25 Number of iterations: 17 Maximum index size = [ 0 1 2 3 4 5 6 ] @output_index indexes = [ 5 2 1 4 6 0 3 ] @output_index values = [ 4 14 1 11 ] original matrix 4 x 7 with solution: [ 50 77 7 66 10 4** 19 ] [ 57 84 14** 73 3 11 26 ] [ 26 1** 69 10 86 72 57 ] [ 71 98 28 87 11** 25 40 ] Pairs (in ascending order of weight function values): indexes ( 2, 1 ), weight value = 1 ; sum of values = 1 indexes ( 0, 5 ), weight value = 4 ; sum of values = 5 indexes ( 3, 4 ), weight value = 11 ; sum of values = 16 indexes ( 1, 2 ), weight value = 14 ; sum of values = 30 indexes ( 4, 6 ), weight value = ; sum of values = 30 indexes ( 5, 0 ), weight value = ; sum of values = 30 indexes ( 6, 3 ), weight value = ; sum of values = 30 Common use of the solution: foreach my $i ( sort { $a <=> $b } keys %{$assignement_ref} ){ my $j = $assignement_ref->{$i}; ... } for my $i ( 0 .. $#{$output_index_ref} ){ my $j = $output_index_ref->[$i]; ... } OPTIONS matrix_ref => \@input_matrix, reference to array: matrix N x M. maximize_total_benefit => 0, 0: minimize the total benefit ; 1: maximize the total benefit. inicial_stepsize => 1, auction algorithm terminates with a feasible assignment if the problem data are integer and stepsize < 1/min(N,M). inicial_price => 1, verbose => 3, print messages on the screen, level of verbosity, 0: quiet; 1, 2, 3, 4, 9, 10: debug information. EXPORT "auction" function by default. INPUT The input matrix should be in a two dimensional array (array of array) and the 'auction' subroutine expects a reference to this array. OUTPUT The $output_index_ref is the reference to the output_index array. The $assignement_ref is the reference to the assignement hash. The $optimal is the total benefit which can be a minimum or maximum value. SEE ALSO 1. Network Optimization: Continuous and Discrete Models (1998). Dimitri P. Bertsekas http://web.mit.edu/dimitrib/www/netbook_Full_Book.pdf 2. Towards auction algorithms for large dense assignment problems (2008). Libor Bus and Pavel Tvrdik https://pdfs.semanticscholar.org/b759/b8fb205df73c810b483b5be2b1ded62309b4.pdf 3. https://github.com/EvanOman/AuctionAlgorithmCPP/blob/master/auction.cpp This Perl algorithm started from this C++ implementation. 4. https://en.wikipedia.org/wiki/Assignment_problem 5. https://en.wikipedia.org/wiki/Auction_algorithm AUTHOR Claudio Fernandes de Souza Rodrigues March 21, 2018 Sao Paulo, Brasil claudiofsr@yahoo.com COPYRIGHT AND LICENSE Copyright (c) 2018 Claudio Fernandes de Souza Rodrigues. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.