Download the PHP package dbeurive/graph without Composer

On this page you can find all versions of the php package dbeurive/graph. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package graph

Introduction

This repository contains the implementations of various algorithms for graphs.

License

This code is published under the following license:

Creative Common Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)

See the file LICENSE.TXT

Installation

From the command line:

composer require dbeurive/graph

Or, from within the file composer.json:

"require": {
    "dbeurive/graph": "*"
}

Graphs' types

Graphs may be:

A given graph may be:

Type of graph Class
Directed and unweighted \dbeurive\Graph\lists\DirectedUnweighted
Directed and weighted \dbeurive\Graph\lists\DirectedWeighted
Undirected and unweighted \dbeurive\Graph\lists\UndirectedUnweighted
Undirected and weighted \dbeurive\Graph\lists\UndirectedWeighted

Graphs' representations

Many formalisms may be used to represent a graph. For example:

This document presents various ways used to represent graphs:

https://fr.khanacademy.org/computing/computer-science/algorithms/graph-representation/a/representing-graphs

This PHP module uses the formalism known as "Adjacency lists".

Directed graphs

Vertices have successors (and predecessors).

We can choose to describe the graph through its lists of successors or through its lists of predecessors.

Directed and unweighted

Let's consider the following directed unweighted graph:

The agency lists can be represented by the associative array below:

Or by a CSV file:

vertex1 vertex2 vertex5
vertex5 vertex6 vertex7
vertex2 vertex3
vertex3 vertex4
vertex4 vertex2

See this example.

Directed and weighted

Let's consider the following directed weighted graph:

The agency lists can be represented by the associative array below:

Or by a CSV file:

vertex1 vertex2:1 vertex5:2
vertex5 vertex6:3 vertex7:4
vertex2 vertex3:5
vertex3 vertex4:6
vertex4 vertex2:7

See this example.

Undirected graphs

Vertices have neighbours.

Undirected and unweighted

Let's consider the following undirected unweighted graph:

The agency lists can be represented by the associative array below:

Or by the CV file:

vertex1 vertex2 vertex5
vertex5 vertex6 vertex7
vertex2 vertex3
vertex3 vertex4
vertex4 vertex2

See this example.

Undirected and weighted

Let's consider the following undirected weighted graph:

The agency lists can be represented by the associative array below:

Or by the CSV file:

vertex1 vertex2:1 vertex5:2
vertex5 vertex6:3 vertex7:4
vertex2 vertex3:5
vertex3 vertex4:6
vertex4 vertex2:7

See this example.

Graphs' API

Introduction

The graph's API allows the following actions:

Instead of presenting an-in depth description of the API, we will show examples of uses.

Detailed API description can be generated using phpDocumentor. Just go to the root directory of this package and issue the following command: phpdoc. The documentation will be generated within the directory doc/api.

Loading a graph from a CSV file

Loading CSV with the default loader

Synopsis:

By default:

Examples of standard CSV files:

vertex1
vertex2 vertex1 vertex4
vertex5 vertex1
vertex6 vertex5
vertex7 vertex5
vertex3 vertex2
vertex4 vertex3

or:

vertex1
vertex2 vertex1:1 vertex4:7
vertex5 vertex1:2
vertex6 vertex5:3
vertex7 vertex5:4
vertex3 vertex2:5
vertex4 vertex3:6

See example from-csv-directed-unweighted.php.

See example from-csv-directed-weighted.php.

See example from-csv-undirected-unweighted.php.

See example from-csv-undirected-weighted.php.

Loading CSV with a customized loader

Synopsis:

While loading CSV files, it is possible to specify non-standard attributes:

It is also possible to specify actions applied to the following data:

Actions are specified via a "callable" (see this explanation).

In the following examples:

See example from-csv-directed-unweighted-non-standard.php.

See example from-csv-directed-weighted-non-standard.php.

Dumping a graph into a CSV file

Dumping into CSV with the default dumper

Synopsis:

See example to-csv-directed-unweighted.php.

See example to-csv-directed-weighted.php.

See example to-csv-undirected-unweighted.php.

See example to-csv-undirected-weighted.php.

Dumping into CSV with a customized dumper

Synopsis:

While dumping CSV files, it is possible to specify non-standard attributes:

It is also possible to specify actions applied to the following data:

Actions are specified via a "callable" (see this explanation).

See example to-csv-directed-unweighted-non-standard.php.

See example to-csv-directed-weighted-non-standard.php.

See example to-csv-undirected-unweighted-non-standard.php.

See example to-csv-undirected-weighted-non-standard.php.

Dumping a graph into its GraphViz representation

Synopsis:

Please note that the generated GraphViz representation is highly customisable. The methods dumpSuccessorsToGraphviz, dumpPredecessorsToGraphviz and dumpNeighboursToGraphviz take parameters. These parameters allow you to customise the appearances of the vertices and of the edges.

See example to-graphviz-directed-unweighted.php.

See example to-graphviz-directed-weighted.php.

See example to-graphviz-undirected-unweighted.php.

See example to-graphviz-undirected-weighted.php.

Using the algorithms

The "Breadth First Search" algorithm

See the description here.

Synopsis

Please note that this algorithm works for directed and undirected graphs.

Please note that the returned value of the callback function ($callback) determines the behaviour of the method run().

  • If the callback function returns the value true, then the method run() continues the traversal of the graph.
  • If the callback function returns the value false, then the method run() stops the traversal of the graph.

See example breadth-first-search-directed.php.

See example breadth-first-search-undirected.php.

The "Depth First Search" algorithm

See the description here.

Synopsis

Please note that this algorithm works for directed and undirected graphs.

Please note that the returned value of the callback function ($callback) determines the behaviour of the method run().

  • If the callback function returns the value true, then the method run() continues the traversal of the graph.
  • If the callback function returns the value false, then the method run() stops the traversal of the graph.

See example depth-first-search-directed.php.

See example depth-first-search-undirected.php.

The Dijkstra's algorithm

See the description here.

Synopsis

See example dijkstra-directed.php.

See example dijkstra-undirected.php.

Illustration

Given the graph below, let's find the shortest paths from the vertex "1" to all other vertices.

After running the algorithm, we get:

Shortest paths are printed in red.

The Tarjan's algorithm

See the description here.

Synopsis

See example tarjan.php.

Illustration

Given the graph below, let's find all the cycles:

After running the algorithm, we get:

Please note that this algorithm does not return the list of cycles within the graph. It returns the list of strongly connected components. However, cycle detection is an application of this algorithm. Here, we choose to show the result of the method getCycles().


All versions of graph with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package dbeurive/graph contains the following files

Loading the files please wait ....