clue/graph
Composer 安装命令:
composer require clue/graph
包简介
GraPHP is the mathematical graph/network library written in PHP.
README 文档
README
GraPHP is the mathematical graph/network library written in PHP.
Development version: This branch contains the code for the upcoming 1.0 release. For the code of the current stable 0.9 release, check out the
0.9.xbranch.The upcoming 1.0 release will be the way forward for this package. However, we will still actively support 0.9.x for those not yet on the latest version. See also installation instructions for more details.
Table of contents
Quickstart examples
Once installed, let's initialize a sample graph:
<?php require __DIR__ . '/vendor/autoload.php'; $graph = new Graphp\Graph\Graph(); // create some cities $rome = $graph->createVertex(array('name' => 'Rome')); $madrid = $graph->createVertex(array('name' => 'Madrid')); $cologne = $graph->createVertex(array('name' => 'Cologne')); // build some roads $graph->createEdgeDirected($cologne, $madrid); $graph->createEdgeDirected($madrid, $rome); // create loop $graph->createEdgeDirected($rome, $rome);
Let's see which city (Vertex) has a road (i.e. an edge pointing) to Rome:
foreach ($rome->getVerticesEdgeFrom() as $vertex) { echo $vertex->getAttribute('name') . ' leads to Rome' . PHP_EOL; // result: Madrid and Rome itself lead to Rome }
Features
This library is built around the concept of mathematical graph theory (i.e. it is not a charting library for drawing a graph of a function). In essence, a graph is a set of nodes with any number of connections in between. In graph theory, vertices (plural of vertex) are an abstract representation of these nodes, while connections are represented as edges. Edges may be either undirected ("two-way") or directed ("one-way", aka di-edges, arcs).
Depending on how the edges are constructed, the whole graph can either be undirected, can be a directed graph (aka digraph) or be a mixed graph. Edges are also allowed to form loops (i.e. an edge from vertex A pointing to vertex A again). Also, multiple edges from vertex A to vertex B are supported as well (aka parallel edges), effectively forming a multigraph (aka pseudograph). And of course, any combination thereof is supported as well. While many authors try to differentiate between these core concepts, this library tries hard to not impose any artificial limitations or assumptions on your graphs.
Components
This library provides the core data structures for working with graphs, its vertices, edges and attributes.
There are several official components built on top of these structures to provide commonly needed functionality. This architecture allows these components to be used independently and on demand only.
Following is a list of some highlighted components. A list of all official components can be found in the graphp project.
Graph drawing
This library is built to support visualizing graph images, including them into webpages, opening up images from within CLI applications and exporting them as PNG, JPEG or SVG file formats (among many others). Because graph drawing is a complex area on its own, the actual layouting of the graph is left up to the excellent GraphViz "Graph Visualization Software" and we merely provide some convenient APIs to interface with GraphViz.
See graphp/graphviz for more details.
Common algorithms
Besides graph drawing, one of the most common things to do with graphs is running algorithms to solve common graph problems. Therefore this library is being used as the basis for implementations for a number of commonly used graph algorithms:
- Search
- Deep first (DFS)
- Breadth first search (BFS)
- Shortest path
- Dijkstra
- Moore-Bellman-Ford (MBF)
- Counting number of hops (simple BFS)
- Minimum spanning tree (MST)
- Kruskal
- Prim
- Traveling salesman problem (TSP)
- Bruteforce algorithm
- Minimum spanning tree heuristic (TSP MST heuristic)
- Nearest neighbor heuristic (NN heuristic)
- Maximum flow
- Minimum cost flow (MCF)
- Cycle canceling
- Successive shortest path
- Maximum matching
- Flow algorithm
See graphp/algorithms for more details.
Install
The recommended way to install this library is through Composer. New to Composer?
Once released, this project will follow SemVer. At the moment, this will install the latest development version:
composer require graphp/graph:^1@dev
See also the CHANGELOG for details about version upgrades.
This project aims to run on any platform and thus does not require any PHP extensions and supports running on legacy PHP 5.3 through current PHP 8+. It's highly recommended to use the latest supported PHP version for this project.
You may also want to install some of the additional components. A list of all official components can be found in the graphp project.
Tests
This library uses PHPUnit for its extensive test suite. To run the test suite, you first need to clone this repo and then install all dependencies through Composer:
composer install
To run the test suite, go to the project root and run:
vendor/bin/phpunit
Contributing
This library comes with an extensive test suite and is regularly tested and used in the real world. Despite this, this library is still considered beta software and its API is subject to change. The changelog lists all relevant information for updates between releases.
If you encounter any issues, please don't hesitate to drop us a line, file a bug report or even best provide us with a patch / pull request and/or unit test to reproduce your problem.
Besides directly working with the code, any additional documentation, additions to our readme or even fixing simple typos are appreciated just as well.
Any feedback and/or contribution is welcome!
Check out #graphp on irc.freenode.net.
License
This project is released under the permissive MIT license.
Did you know that I offer custom development services and issuing invoices for sponsorships of releases and for contributions? Contact me (@clue) for details.
clue/graph 适用场景与选型建议
clue/graph 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.49M 次下载、GitHub Stars 达 714, 最近一次更新时间为 2012 年 10 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「network」 「graph」 「mathematical」 「vertex」 「edge」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 clue/graph 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 clue/graph 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 clue/graph 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
GraPHP is the mathematical graph/network library written in PHP.
Netgen Open Graph Bundle is an Ibexa Platform bundle that allows simple integration with Open Graph protocol.
LinkedIn API PHP SDK with OAuth 2.0 & CSRF support. Can be used for social sign in or sharing on LinkedIn. Examples. Documentation.
A tool for scraping URL resources (oEmbed, OpenGraph, Twitter cards, JSON-LD)
LinkedIn API PHP SDK with OAuth 2.0 & CSRF support. Can be used for social sign in or sharing on LinkedIn. Examples. Documentation.
PHP SDK for Bands In Town API
统计信息
- 总下载量: 4.49M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 724
- 点击次数: 34
- 依赖项目数: 46
- 推荐数: 3
其他信息
- 授权协议: MIT
- 更新时间: 2012-10-28