2017 © Pedro Peláez
 

library graph

A very simple implementation of a Graph data structure.

image

rhodri-m/graph

A very simple implementation of a Graph data structure.

  • Monday, July 30, 2018
  • by RhodriM
  • Repository
  • 1 Watchers
  • 0 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 16 Versions
  • 200 % Grown

The README.md

rhodri-m/graph

A very simple implementation of a Graph data structure., (*1)

Installation

Composer

It is highly recommended that you use composer to install this library., (*2)

Get Composer, (*3)

Simply run composer require rhodri-m/graph and use composer's supplied autoloader (usually by adding require __DIR__ . '/vendor/autoload.php'; at the top of your script)., (*4)

Basic Usage

The Node and Edge classes are designed to be extended by your own if required, so you can use your own entities as nodes or edges within a graph structure. eg:, (*5)

class Person extends \Graph\Node
{
    [...]
}

GraphContainer is the recommended way of storing, adding, removing nodes and edges to ensure consistency., (*6)

Example

$maintainAdjacencyMatrix = true;
$directed = true;
$weighted = false;

$graphCon = new \Graph\GraphContainer(
    $maintainAdjacencyMatrix,
    $directed,
    $weighted
);

$node1 = new \Graph\Node();
$graphCon->addNode($node1);
$node2 = new \Graph\Node();
$graphCon->addNode($node2);
$node3 = new \Graph\Node();
$graphCon->addNode($node3);

// add Edges by Node references
$graphCon->addEdge($node2, $node3);
$graphCon->addEdge($node3, $node1);
$graphCon->addEdge($node2, $node1);

// add Edge from node1 to node2 by (zero-indexed) ids
$graphCon->addEdgeByIds(0, 1);

echo "\nNumber of Nodes: " . count($graphCon->getNodes());
echo "\nNumber of Edges: " . count($graphCon->getEdges());
echo "\nAdjacency Matrix:\n";
print_r($adjacencyMatrix = $graphCon->getAdjacencyMatrix());

will output:, (*7)

Number of Nodes: 3
Number of Edges: 4
Adjacency Matrix:
Array
(
    [0] => Array
        (
            [0] => 
            [1] => 1
            [2] => 
        )

    [1] => Array
        (
            [0] => 1
            [1] => 
            [2] => 1
        )

    [2] => Array
        (
            [0] => 1
            [1] => 
            [2] => 
        )

)

Outputting to graph file formats for use by other applications

We can export our graphs to data formats such as GML for use by other applications, such as Gephi:, (*8)

$gmlOutput = new \Graph\Output\Gml();
$gmlOutput->writeToFile('testGraph.gml', $graphCon);

Exporting the very basic graph example above to Gephi gives:, (*9)

alt text, (*10)

It is also possible to assign labels and colours to nodes for use in external viewers:, (*11)

$node1->name = "Node 1";
$node1->colour = 'FF8888';

alt text, (*12)

The Versions

30/07 2018

dev-master

9999999-dev

A very simple implementation of a Graph data structure.

  Sources   Download

MIT

The Requires

  • php >=5.6.30

 

The Development Requires

graph node network edge gml

30/07 2018

dev-input

dev-input

A very simple implementation of a Graph data structure.

  Sources   Download

MIT

The Requires

  • php >=5.6.30

 

The Development Requires

graph node network edge gml

30/07 2018

1.4.2

1.4.2.0

A very simple implementation of a Graph data structure.

  Sources   Download

MIT

The Requires

  • php >=5.6.30

 

The Development Requires

graph node network edge gml

30/07 2018

1.4.0-rc2

1.4.0.0-RC2

A very simple implementation of a Graph data structure.

  Sources   Download

MIT

The Requires

  • php >=5.6.30

 

The Development Requires

graph node network edge gml

30/07 2018

1.4.1-rc1

1.4.1.0-RC1

A very simple implementation of a Graph data structure.

  Sources   Download

MIT

The Requires

  • php >=5.6.30

 

The Development Requires

graph node network edge gml

26/07 2018

1.4.0-rc1

1.4.0.0-RC1

A very simple implementation of a Graph data structure.

  Sources   Download

MIT

The Requires

  • php >=5.6.30

 

The Development Requires

graph node network edge gml

11/07 2018

1.3.0

1.3.0.0

A very simple implementation of a Graph data structure.

  Sources   Download

MIT

The Requires

  • php >=5.6.30

 

The Development Requires

graph node network edge gml

10/07 2018

1.2.0

1.2.0.0

A very simple implementation of a Graph data structure.

  Sources   Download

MIT

The Requires

  • php >=5.6.30

 

The Development Requires

graph node network edge gml

10/07 2018

dev-dijkstra

dev-dijkstra

A very simple implementation of a Graph data structure.

  Sources   Download

MIT

The Requires

  • php >=5.6.30

 

The Development Requires

graph node network edge gml

22/05 2018

1.1.0

1.1.0.0

A very simple implementation of a Graph data structure.

  Sources   Download

MIT

The Requires

  • php >=5.6.30

 

The Development Requires

graph node network edge gml

22/05 2018

dev-bfs

dev-bfs

A very simple implementation of a Graph data structure.

  Sources   Download

MIT

The Requires

  • php >=5.6.30

 

The Development Requires

graph node network edge gml

19/02 2018

1.0.0

1.0.0.0

A very simple implementation of a Graph data structure.

  Sources   Download

MIT

The Requires

  • php >=5.6.30

 

The Development Requires

graph node network edge gml