PHP code example of relaxedws / lca
1. Go to this page and download the library: Download relaxedws/lca 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/ */
relaxedws / lca example snippets
haculty\Graph\Graph;
use Relaxed\LCA\LowestCommonAncestor;
$graph = new Graph();
for ($i=1; $i<=6 ; $i++){
$vertices['node_'.$i] = $graph->createVertex('node_'.$i);
}
$vertices['node_1']->createEdgeTo($vertices['node_2']);
$vertices['node_1']->createEdgeTo($vertices['node_5']);
$vertices['node_2']->createEdgeTo($vertices['node_3']);
$vertices['node_2']->createEdgeTo($vertices['node_4']);
$vertices['node_5']->createEdgeTo($vertices['node_6']);
$instance = new LowestCommonAncestor($graph);
$lca = $instance->find($vertices['node_3'], $vertices['node_4']);
$base = $lca->getId();