PHP code example of sensasi-delight / eigenvector-centrality-php

1. Go to this page and download the library: Download sensasi-delight/eigenvector-centrality-php 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/ */

    

sensasi-delight / eigenvector-centrality-php example snippets


    use SensasiDelight\Graph;

    $g = new Graph;
    

    $g->add_node('v1');
    $g->add_node('v2');
    $g->add_node('v3');
    $g->add_node('v4');
    $g->add_node('v5');
    

    $g->add_nodes_from([
        'v1',
        'v2',
        'v3',
        'v4',
        'v5',
    ]);
    

    $g->add_edge('v1', 'v2');
    $g->add_edge('v1', 'v4');
    $g->add_edge('v2', 'v3');
    $g->add_edge('v2', 'v4');
    $g->add_edge('v2', 'v5');
    $g->add_edge('v3', 'v4');
    

    $g->add_edges_from([
        ['v1', 'v2'],
        ['v1', 'v4'],
        ['v2', 'v3'],
        ['v2', 'v4'],
        ['v2', 'v5'],
        ['v3', 'v4']
    ]);
    

    $result = $g->get_eigenvector_centrality();
    print_r($result);
    

    Array
    (
        [v1] => 0.4119172769405
        [v2] => 0.58253899962505
        [v3] => 0.4119172769405
        [v4] => 0.52368294422478
        [v5] => 0.21691657788138
    )