fqqdk/igraph (0.24.0)
Installation
{
"repositories": [{
"type": "composer",
"url": " "
}
]
}composer require fqqdk/igraph:0.24.0About this package
The igraph graph-algorithms C library as a PHP extension. Exposes is_dag, topological_sort, is_connected, connected_components, degree, is_simple, is_tree, diameter, shortest_path_length, pagerank, betweenness, closeness eigenvector_centrality transitivity, girth, edge_connectivity minimum_spanning_tree articulation_points coreness vertex_connectivity reciprocity assortativity_degree community_multilevel and harmonic_centrality over an (int $n, array $edges) graph (plus igraph_version()); the API surface grows one function per minor release.
igraph
The igraph graph-algorithms C library packaged as a PHP extension — a sibling
to planarity, built to the same recipe: a tiny, audited wrapper (igraph.c,
the only code we author) over a vendored C library, with a .phpt suite, a reproducible
Docker build, Forgejo CI, and a Composer php-ext package.
API
igraph_is_dag(int $n, array $edges): bool
// $n — vertex count; vertices are 0 .. n-1.
// $edges — list of [u, v] integer pairs, each a DIRECTED edge u -> v (0-based). Multigraphs are
// accepted: parallel edges are fine; a self-loop (u -> u) or an anti-parallel pair
// (u -> v and v -> u) forms a cycle. Nothing is dropped.
// → bool — true iff the directed graph is acyclic (a DAG: no directed cycle). The empty and any
// edgeless graph are DAGs.
// throws ValueError on malformed input (endpoint out of range, n out of range, bad edge shape).
igraph_topological_sort(int $n, array $edges): array
// $n, $edges — same shape as above; edges are DIRECTED (u -> v).
// → list<int> — a topological ordering of the vertices: every vertex appears before all vertices
// it points to. The empty graph yields []. One valid ordering is returned.
// throws ValueError on malformed input, or if the graph is not acyclic (no order exists).
igraph_is_connected(int $n, array $edges, bool $strong = false): bool
// $n, $edges — same shape; edges are DIRECTED (u -> v).
// $strong — false (default): WEAK connectivity (edge direction ignored — is the graph in one
// piece?). true: STRONG connectivity (every vertex reachable from every other).
// → bool. Per igraph: the 1-vertex graph is connected; the null graph (n=0) is not.
// throws ValueError on malformed input.
igraph_connected_components(int $n, array $edges, bool $strong = false): array
// $n, $edges — same shape; edges are DIRECTED (u -> v).
// $strong — false (default): WEAK components; true: STRONG components.
// → list<int> of length $n — membership[v] is the 0-based id of v's component (ids contiguous
// [0, k)). Group vertices by id to recover the components. Null graph (n=0) → [].
// throws ValueError on malformed input.
igraph_degree(int $n, array $edges, string $mode = 'all'): array
// $n, $edges — same shape; edges are DIRECTED (u -> v).
// $mode — 'all' (default) total degree, 'in' in-degree, or 'out' out-degree.
// → list<int> of length $n — the degree of each vertex. Self-loops count twice for 'all',
// once each for 'in'/'out'. Null graph (n=0) → [].
// throws ValueError on malformed input or an unknown $mode.
igraph_is_simple(int $n, array $edges): bool
// $n, $edges — same shape; edges are DIRECTED (u -> v).
// → bool — true iff no self-loops and no duplicate DIRECTED edges. Directions are considered,
// so an anti-parallel pair (u->v and v->u) is simple; a repeated pair or self-loop is
// not. This is the function that distinguishes multigraph input the others tolerate.
// throws ValueError on malformed input.
igraph_is_tree(int $n, array $edges, string $mode = 'all'): bool
// $n, $edges — same shape; edges are DIRECTED (u -> v).
// $mode — 'all' (default): the undirected graph is a tree (connected, n-1 edges, acyclic);
// 'out': a directed out-tree (edges point away from one root); 'in': an in-tree.
// → bool. The single-vertex graph is a tree; the null graph (n=0) is not.
// throws ValueError on malformed input or an unknown $mode.
igraph_diameter(int $n, array $edges, bool $directed = true): int
// $n, $edges — same shape; edges are DIRECTED (u -> v).
// $directed — true (default): follow edge directions; false: ignore them.
// → int — the diameter (longest shortest path, in edges), unweighted. For a disconnected graph
// the longest FINITE shortest path is returned. A graph with < 2 vertices → 0.
// throws ValueError on malformed input.
igraph_shortest_path_length(int $n, array $edges, int $from, int $to, bool $directed = true): int
// $n, $edges — same shape; edges are DIRECTED (u -> v).
// $from,$to — source/target vertex ids (0-based, each in [0, n)).
// $directed — true (default): follow edge directions; false: ignore them.
// → int — number of edges on a shortest $from→$to path (0 if equal), or -1 if unreachable.
// throws ValueError on malformed input or out-of-range $from/$to.
igraph_pagerank(int $n, array $edges, float $damping = 0.85, bool $directed = true): array
// $n, $edges — same shape; edges are DIRECTED (u -> v).
// $damping — damping factor in [0, 1] (default 0.85). $directed — follow directions (default true).
// → list<float> of length $n — the PageRank score of each vertex (scores sum to ~1). Unweighted.
// throws ValueError on malformed input or a $damping outside [0, 1].
igraph_betweenness(int $n, array $edges, bool $directed = true, bool $normalized = false): array
// $n, $edges — same shape; edges are DIRECTED (u -> v).
// $directed — follow directions (default true). $normalized — divide by the pair count → [0,1].
// → list<float> of length $n — the betweenness centrality of each vertex. Unweighted.
// throws ValueError on malformed input.
igraph_closeness(int $n, array $edges, string $mode = 'out', bool $normalized = true): array
// $n, $edges — same shape; edges are DIRECTED (u -> v).
// $mode — 'out' (default) / 'in' / 'all' distance direction. $normalized — mean inverse
// distance (default) vs inverse summed distance.
// → list<float> of length $n — closeness centrality. A vertex that can reach no other is NAN
// (isolated vertices, sinks in 'out' mode, the single-vertex graph). Unweighted.
// throws ValueError on malformed input or an unknown $mode.
igraph_eigenvector_centrality(int $n, array $edges, bool $directed = false): array
// $n, $edges — same shape; edges are DIRECTED (u -> v).
// $directed — false (default): treat as undirected; true: follow out-edges.
// → list<float> of length $n — eigenvector centrality, scaled so the maximum is 1. Unweighted.
// throws ValueError on malformed input.
igraph_transitivity(int $n, array $edges): float
// $n, $edges — same shape; the graph is read as UNDIRECTED (direction ignored).
// → float — global transitivity / clustering coefficient (closed triples / all connected
// triples) in [0, 1]. A graph with no connected triple returns 0.
// throws ValueError on malformed input.
igraph_girth(int $n, array $edges): int
// $n, $edges — same shape; read as UNDIRECTED (self-loops and multi-edges ignored).
// → int — length of the shortest cycle, or -1 if the graph is acyclic (a forest).
// throws ValueError on malformed input.
igraph_edge_connectivity(int $n, array $edges, bool $directed = true): int
// $n, $edges — same shape; edges are DIRECTED (u -> v).
// $directed — true (default): directed edge connectivity (0 unless strongly connected);
// false: undirected edge connectivity.
// → int — minimum number of edges whose removal disconnects the graph (0 if already
// disconnected, or < 2 vertices).
// throws ValueError on malformed input.
igraph_minimum_spanning_tree(int $n, array $edges): array
// $n, $edges — same shape; the graph is read as UNDIRECTED and unweighted.
// → list<[int,int]> — the MST edges as [u,v] pairs. Unweighted, so it's any spanning tree
// (n-1 edges when connected) or a spanning FOREST (n - #components edges) otherwise.
// throws ValueError on malformed input.
igraph_articulation_points(int $n, array $edges): array
// $n, $edges — same shape; the graph is read as UNDIRECTED.
// → list<int> — the cut vertices (whose removal increases the component count). Order is
// igraph's; sort for a canonical list.
// throws ValueError on malformed input.
igraph_coreness(int $n, array $edges, string $mode = 'all'): array
// $n, $edges — same shape; edges are DIRECTED (u -> v).
// $mode — 'all' (default) ignore direction; 'in'/'out' use in-/out-degree.
// → list<int> of length $n — each vertex's coreness (largest k with the vertex in the k-core).
// throws ValueError on malformed input or an unknown $mode.
igraph_vertex_connectivity(int $n, array $edges, bool $directed = true): int
// $n, $edges — same shape; edges are DIRECTED (u -> v).
// $directed — true (default): directed; false: undirected.
// → int — minimum number of vertices whose removal disconnects the graph. 0 for a disconnected
// graph (or, directed, one not strongly connected) and for < 2 vertices.
// throws ValueError on malformed input.
igraph_reciprocity(int $n, array $edges): float
// $n, $edges — same shape; edges are DIRECTED (u -> v).
// → float — fraction of directed edges that are reciprocated (u->v with v->u), in [0, 1].
// Self-loops ignored. A graph with no edges returns NAN (undefined).
// throws ValueError on malformed input.
igraph_assortativity_degree(int $n, array $edges, bool $directed = true): float
// $n, $edges — same shape; edges are DIRECTED (u -> v).
// $directed — true (default): out-degree vs in-degree; false: undirected.
// → float — degree assortativity coefficient in [-1, 1] (Pearson correlation of endpoint
// degrees). NAN when undefined (all degrees equal, or too few edges).
// throws ValueError on malformed input.
igraph_community_multilevel(int $n, array $edges, float $resolution = 1.0): array
// $n, $edges — same shape; the graph is read as UNDIRECTED.
// $resolution — resolution parameter (default 1.0); higher → more, smaller communities.
// → list<int> of length $n — community id per vertex (modularity-maximizing Louvain partition,
// ids contiguous [0, k)). Randomized tie-breaking, so ids/ordering
Dependencies
Dependencies
| ID | Version |
|---|---|
| php | >=8.1 |
Keywords
igraph
graph
network
algorithms
php-extension
Details
2026-07-06 23:34:40 +00:00
Assets (1)
Versions (24)
View all
Composer
1
fqqdk
GPL-2.0-or-later
5.6 MiB
fqqdk-igraph.0.24.0.zip
5.6 MiB