PHP code example of motley / hopcroft-karp
1. Go to this page and download the library: Download motley/hopcroft-karp 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/ */
motley / hopcroft-karp example snippets
$matching = HopcroftKarp::matching([
['left1', ['right2', 'right3']],
['left2', ['right1']],
['left3', ['right2']],
['left4', ['right2']],
['left4', ['right4']],
]);
$matching->toArray(); // [['left1', 'right3'], ['left2', 'right1'], ['left3', 'right2'], ['left4', 'right4']]
$matching->getRightByLeft('left2'); // 'right1'
$matching->getRightByLeft('unmatched'); // null
$matching->getLeftByRight('right2'); // 'left3'
$matching->getAllLeft(); // ['left1', 'left2', 'left3', 'left4']
$matching->getAllRight(); // ['right3', 'right1', 'right2', 'right4']
$previousMatching = new Matching([
new Edge('left1', 'right1'),
new Edge('left2', 'right2'),
new Edge('left3', 'right4'),
new Edge('left4', 'right3'),
]);
$matching = HopcroftKarp::matching([
['left1', ['right1', 'left2', 'right3']],
['left2', ['right1', 'left2', 'right3', 'right4']],
['left3', ['left2', 'right3', 'right4']],
['left4', ['right1', 'right2', 'right3', 'right4']],
], $previousMatching);