2017 © Pedro Peláez
 

library gliph

A graph library for PHP.

image

sdboyer/gliph

A graph library for PHP.

  • Friday, September 5, 2014
  • by sdboyer
  • Repository
  • 8 Watchers
  • 157 Stars
  • 17,664 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 8 Forks
  • 7 Open issues
  • 18 Versions
  • 3 % Grown

The README.md

Gliph

Build Status Latest Stable Version Coverage Status, (*1)

Gliph is a graph library for PHP. It provides graph building blocks and datastructures for use by other PHP applications. It is designed for use with in-memory graphs, not for interaction with a graph database like Cayley or Neo4J (though it could be used to facilitate such connection)., (*2)

Gliph aims for both sane interfaces and as performant an implementation as userspace PHP allows., (*3)

This does require knowing enough about graphs to know what type is appropriate for your use case, but we are aiming to provide helpers that simplify those choices., (*4)

Quickstart

Working with gliph is easy: pick a graph implementation, then add edges and vertices as needed. ()Note that gliph currently supports only object vertices, though this limitation may be loosened in future releases), (*5)

<?php

use Gliph\Graph\DirectedAdjacencyList;

class Vertex {
    public $val;

    public function __construct($val) {
        $this->val = $val;
    }
}

$vertices = array(
    'a' => new Vertex('a'),
    'b' => new Vertex('b'),
    'c' => new Vertex('c'),
    'd' => new Vertex('d'),
    'e' => new Vertex('e'),
    'f' => new Vertex('f'),
);

$g = new DirectedAdjacencyList();

foreach ($vertices as $vertex) {
    $g->ensureVertex($vertex);
}

$g->ensureArc($vertices['a'], $vertices['b']);
$g->ensureArc($vertices['b'], $vertices['c']);
$g->ensureArc($vertices['a'], $vertices['c']);
$g->ensureArc($vertices['d'], $vertices['a']);
$g->ensureArc($vertices['d'], $vertices['e']);

This would create the following directed graph:, (*6)

Base digraph, (*7)

Once your graph is created, gliph provides a number of Traversable mechanisms for doing work on the graph. These mechanisms are important to understand and are explored in greater detail in the wiki, but for those familiar with graph theory, the method naming is intended to be self-explanatory:, (*8)

For directed and undirected graphs:, (*9)

  • Graph::vertices()
  • Graph::edges()
  • Graph::adjacentTo($vertex)
  • Graph::incidentTo($vertex)

And for directed graphs only:, (*10)

  • Digraph::successorsOf($vertex)
  • Digraph::predecessorsOf($vertex)
  • Digraph::arcsFrom($vertex)
  • Digraph::arcsTo($vertex)

Core Concepts

Gliph has several conceptual components that work together to create a coherent library: graph implementations, algorithms, and visitors., (*11)

Gliph has several components that work together: graph classes, algorithms, and visitors. Generally speaking, Gliph is patterned after the C++ Boost Graph Library; reading their documentation can yield a lot of insight into how Gliph is intended to work., (*12)

Graphs

Gliph’s most important baseline export is its assorted graph interfaces. The other components (algorithms and visitors) rely strictly on the interfaces, never on concrete implementations. Consequently, users of gliph can craft case-specific implementations with the assurance that they will work with the algorithms. To assist towards that end, gliph provides phpunit testing traits that make it easy to ensure your custom graph implementations conform to both the letter and the spirit of gliph’s interfaces., (*13)

Gliph’s own implementations are designed to be as performant as possible for the general case. Current implementations include only adjacency lists, in both directed and undirected flavors., (*14)

Algorithms

Gliph provides various algorithms that can be run on graph objects. These algorithms interact with the graph by making calls to methods, primarily the iterators, defined in the assorted Graph interfaces. If a graph implements the interface type-hinted by a particular algorithm, then the algorithm can run on that graph. But the efficiency of the algorithm will be largely determined by how efficiently that graph implementation can meet the requirements of the interface. Adjacency lists, for example, are not terribly efficient at providing a list of all edges in a graph, but are very good at single-vertex-centric operations., (*15)

Gliph's algorithms are typically implemented quite sparsely (especially traversers) - they seek to implement the simplest, most generic version of an algorithm. They also may not return any output, as that work is left to Visitors., (*16)

Visitors

Most algorithms require a visitor object to be provided. The visitor conforms to an interface specified by the algorithm, and the algorithm will call the visitor at certain choice points during its execution. This allows the algorithms to stay highly generic, while visitors can be tailored to a more specific purpose., (*17)

For example, a DepthFirst visitor might be used to calculate vertex reach, or generate a topologically sorted list. Each of these are things that a depth-first graph traversal can do. But the work of doing so is left to the visitor so that only one traversal algorithm is needed, and that algorithm is as cheap (memory and cycles) as possible., (*18)

Acknowledgements

This library draws inspiration from the C++ Boost Graph Library, though has diverged in some significant design philosophies. Gliph generally follows the same patterns as gogl, though the concepts are more rigorously applied there., (*19)

License

MIT, (*20)

The Versions

05/09 2014

dev-master

9999999-dev http://github.com/sdboyer/gliph

A graph library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Sam Boyer

php library graph spl gliph

03/09 2014

0.7.0

0.7.0.0 http://github.com/sdboyer/gliph

A graph library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Sam Boyer

php library graph spl gliph

03/09 2014

dev-new-generator

dev-new-generator http://github.com/sdboyer/gliph

A graph library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Sam Boyer

php library graph spl gliph

03/08 2014

dev-php53

dev-php53 http://github.com/sdboyer/gliph

A graph library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Sam Boyer

php library graph spl gliph

03/08 2014

0.1.8

0.1.8.0 http://github.com/sdboyer/gliph

A graph library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Sam Boyer

php library graph spl gliph

03/08 2014

0.6.3

0.6.3.0 http://github.com/sdboyer/gliph

A graph library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Sam Boyer

php library graph spl gliph

31/07 2014

0.1.7

0.1.7.0 http://github.com/sdboyer/gliph

A graph library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Sam Boyer

php library graph spl gliph

31/07 2014

0.6.2

0.6.2.0 http://github.com/sdboyer/gliph

A graph library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Sam Boyer

php library graph spl gliph

31/07 2014

dev-nested

dev-nested http://github.com/sdboyer/gliph

A graph library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Sam Boyer

php library graph spl gliph

19/02 2014

0.1.6

0.1.6.0 http://github.com/sdboyer/gliph

A graph library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Sam Boyer

php library graph spl gliph

19/02 2014

0.6.1

0.6.1.0 http://github.com/sdboyer/gliph

A graph library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Sam Boyer

php library graph spl gliph

03/11 2013

0.6.0

0.6.0.0 http://github.com/sdboyer/gliph

A graph library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Sam Boyer

php library graph spl gliph

03/11 2013

0.1.5

0.1.5.0 http://github.com/sdboyer/gliph

A graph library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Sam Boyer

php library graph spl gliph

27/09 2013

0.1.4

0.1.4.0 http://github.com/sdboyer/gliph

A graph library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Sam Boyer

php library graph spl gliph

22/09 2013

0.1.3

0.1.3.0 http://github.com/sdboyer/gliph

A graph library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Sam Boyer

php library graph spl gliph

20/09 2013

0.1.2

0.1.2.0 http://github.com/sdboyer/gliph

A graph library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Sam Boyer

php library graph spl gliph

14/09 2013

0.1.1

0.1.1.0 http://github.com/sdboyer/gliph

A graph library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Sam Boyer

php library graph spl gliph

20/08 2013

0.1.0

0.1.0.0 http://github.com/sdboyer/gliph

A graph library for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Sam Boyer

php library graph spl gliph