{"id":19325436,"url":"https://github.com/krypt0nn/graph","last_synced_at":"2025-09-25T23:05:01.749Z","repository":{"id":144045204,"uuid":"187374362","full_name":"krypt0nn/Graph","owner":"krypt0nn","description":"Граф для PHP 7+","archived":false,"fork":false,"pushed_at":"2020-01-04T14:02:27.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-06T06:43:36.463Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/krypt0nn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-18T15:28:53.000Z","updated_at":"2020-01-04T14:18:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"31c38878-b469-4da2-abb8-f041959a5894","html_url":"https://github.com/krypt0nn/Graph","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krypt0nn%2FGraph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krypt0nn%2FGraph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krypt0nn%2FGraph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krypt0nn%2FGraph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krypt0nn","download_url":"https://codeload.github.com/krypt0nn/Graph/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240427326,"owners_count":19799471,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T02:10:02.883Z","updated_at":"2025-09-25T23:05:01.684Z","avatar_url":"https://github.com/krypt0nn.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Graph\n\n**Graph** - структура данных [граф](https://ru.wikipedia.org/wiki/Граф_(математика)) для **PHP** 7+\n\nДля создания графа можно использовать матрицу смежности, список векторов связанных вершин или список готовых вершин графа. Рассмотрим их на примере этого графа\n\n\u003cimg src=\"https://i.ibb.co/9YnjxSd/Graph.png\" alt=\"Пример графа из кода ниже\"\u003e\n\n**buildByAdjacencyMatrix**\n\n```php\n\u003c?php\n\nuse Graph\\Graph;\n\n$graph = (new Graph)-\u003ebuildByAdjacencyMatrix ([\n    'A' =\u003e ['A' =\u003e null, 'B' =\u003e 1, 'C' =\u003e 1, 'D' =\u003e 3],\n    'B' =\u003e ['A' =\u003e 1, 'B' =\u003e null, 'C' =\u003e null, 'D' =\u003e 2],\n    'C' =\u003e ['A' =\u003e 1, 'B' =\u003e null, 'C' =\u003e null, 'D' =\u003e 2],\n    'D' =\u003e ['A' =\u003e 3, 'B' =\u003e 2, 'C' =\u003e 2, 'D' =\u003e null]\n]);\n```\n\n**buildByVectorsList**\n\n```php\n\u003c?php\n\nuse Graph\\Graph;\n\n$graph = (new Graph)-\u003ebuildByVectorsList ([\n    'A' =\u003e ['B' =\u003e 1, 'C' =\u003e 1, 'D' =\u003e 3],\n    'B' =\u003e ['A' =\u003e 1, 'D' =\u003e 2],\n    'C' =\u003e ['A' =\u003e 1, 'D' =\u003e 2],\n    'D' =\u003e ['A' =\u003e 3, 'B' =\u003e 2, 'C' =\u003e 2]\n]);\n```\n\n**buildByNodesList**\n\n```php\n\u003c?php\n\nuse Graph\\Graph;\n\n$nodes = [\n    new Node ('A', 0),\n    new Node ('B', 1),\n    new Node ('C', 2),\n    new Node ('D', 3)\n];\n\n$graph = (new Graph)-\u003ebuildByNodesList ([\n    $nodes[0]-\u003elink ($nodes[1], 1)-\u003elink ($nodes[2], 1)-\u003elink ($nodes[3], 3),\n    $nodes[1]-\u003elink ($nodes[0], 1)-\u003elink ($nodes[3], 2),\n    $nodes[2]-\u003elink ($nodes[0], 1)-\u003elink ($nodes[3], 2),\n    $nodes[3]-\u003elink ($nodes[0], 3)-\u003elink ($nodes[1], 2)-\u003elink ($nodes[2], 2)\n]);\n```\n\nДля графов доступны:\n\n* просчёт кратчайших дистанций между вершинами\n* поиск клик\n* поиск циклов\n* проход по графу *(**DFS**)*\n* конвертация в различные способы представления\n\nДистанции между вершинами:\n\n```php\n\u003c?php\n\n// true - использовать ли для подсчёта веса соединений\n// Выведет объект Graph - граф дистанций между вершинами\nprint_r ($graph-\u003ecountHipsDistances (true));\n```\n\nКлики:\n\n```php\n\u003c?php\n\n// Выведет список подграфов-клик\nprint_r ($graph-\u003efindCliques ());\n```\n\nЦиклы:\n\n```php\n\u003c?php\n\n$graph = (new Graph)-\u003ebuildByVectorsList ([\n    'A' =\u003e ['B' =\u003e 1],\n    'B' =\u003e ['C' =\u003e 1],\n    'C' =\u003e ['D' =\u003e 1],\n    'D' =\u003e ['B' =\u003e 1]\n]);\n\n// Выведет список подграфов-циклов:\n// B -\u003e C -\u003e D -\u003e B\n// C -\u003e D -\u003e B -\u003e C\n// D -\u003e B -\u003e C -\u003e D\n\nprint_r ($graph-\u003efindCycles ());\n```\n\n\u003e Граф из примера выше:\n\u003cimg src=\"https://i.ibb.co/qgH2TKY/Graph-2.png\" alt=\"Граф из примера выше\"\u003e\n\nНу, как-то так\n\nАвтор: [Подвирный Никита](https://vk.com/technomindlp). Специально для [Enfesto Studio Group](http://vk.com/hphp_convertation)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrypt0nn%2Fgraph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrypt0nn%2Fgraph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrypt0nn%2Fgraph/lists"}