PHP code example of arthurkushman / hungarian

1. Go to this page and download the library: Download arthurkushman/hungarian library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arthurkushman / hungarian example snippets



use Hungarian\Hungarian;
// Define the score matrix as n arrays consisting of n numerical values
$matrix = [
    [1, 2, 3, 0, 1],
    [0, 3, 12, 1, 1],
    [3, 0, 1, 13, 1],
    [3, 1, 1, 12, 0],
    [3, 1, 1, 12, 0],
];

// Create a new Hungarian problem using the score matrix as input
$hungarian  = new Hungarian($matrix);

// Solve the problem using the Hungarian algorithm and get the solution as an array with the row and column as key and value, respectively
$allocation = $hungarian->solveMin();