{"id":31120880,"url":"https://github.com/rhodrim/graph","last_synced_at":"2026-05-15T08:04:41.676Z","repository":{"id":62535387,"uuid":"122078034","full_name":"RhodriM/graph","owner":"RhodriM","description":"A very simple extendable implementation of a Graph data structure which can be outputted to graph data formats eg gml.","archived":false,"fork":false,"pushed_at":"2020-03-12T21:28:46.000Z","size":91,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-12T11:38:30.724Z","etag":null,"topics":["edge","gml","graph","graph-theory","gxl","network-analysis","network-graph","node","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RhodriM.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-19T14:58:19.000Z","updated_at":"2020-03-12T21:28:25.000Z","dependencies_parsed_at":"2022-11-02T15:15:18.460Z","dependency_job_id":null,"html_url":"https://github.com/RhodriM/graph","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/RhodriM/graph","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RhodriM%2Fgraph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RhodriM%2Fgraph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RhodriM%2Fgraph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RhodriM%2Fgraph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RhodriM","download_url":"https://codeload.github.com/RhodriM/graph/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RhodriM%2Fgraph/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275615246,"owners_count":25496811,"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","status":"online","status_checked_at":"2025-09-17T02:00:09.119Z","response_time":84,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["edge","gml","graph","graph-theory","gxl","network-analysis","network-graph","node","php"],"created_at":"2025-09-17T15:05:01.522Z","updated_at":"2025-09-17T15:05:03.829Z","avatar_url":"https://github.com/RhodriM.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rhodri-m/graph\nA very simple implementation of a Graph data structure.\n\n## Installation\n\n### Composer\n\nIt is highly recommended that you use composer to install this library.\n\n[Get Composer](https://getcomposer.org/doc/00-intro.md)\n\nSimply run ```composer require rhodri-m/graph``` and use composer's supplied autoloader\n(usually by adding\n```require __DIR__ . '/vendor/autoload.php';```\nat the top of your script).\n\n## Basic Usage\n\nThe ```Node``` and ```Edge``` classes are designed to be extended by your own if required, so you can use your own entities as nodes or edges within a graph structure. eg:\n\n```php\nclass Person extends \\Graph\\Node\n{\n    [...]\n}\n```\n\n```GraphContainer``` is the recommended way of storing, adding, removing nodes and edges to ensure consistency.\n\n### Example\n\n```php\n$maintainAdjacencyMatrix = true;\n$directed = true;\n$weighted = false;\n\n$graphCon = new \\Graph\\GraphContainer(\n    $maintainAdjacencyMatrix,\n    $directed,\n    $weighted\n);\n\n$node1 = new \\Graph\\Node();\n$graphCon-\u003eaddNode($node1);\n$node2 = new \\Graph\\Node();\n$graphCon-\u003eaddNode($node2);\n$node3 = new \\Graph\\Node();\n$graphCon-\u003eaddNode($node3);\n\n// add Edges by Node references\n$graphCon-\u003eaddEdge($node2, $node3);\n$graphCon-\u003eaddEdge($node3, $node1);\n$graphCon-\u003eaddEdge($node2, $node1);\n\n// add Edge from node1 to node2 by (zero-indexed) ids\n$graphCon-\u003eaddEdgeByIds(0, 1);\n\necho \"\\nNumber of Nodes: \" . count($graphCon-\u003egetNodes());\necho \"\\nNumber of Edges: \" . count($graphCon-\u003egetEdges());\necho \"\\nAdjacency Matrix:\\n\";\nprint_r($adjacencyMatrix = $graphCon-\u003egetAdjacencyMatrix());\n```\nwill output:\n\n```\nNumber of Nodes: 3\nNumber of Edges: 4\nAdjacency Matrix:\nArray\n(\n    [0] =\u003e Array\n        (\n            [0] =\u003e \n            [1] =\u003e 1\n            [2] =\u003e \n        )\n\n    [1] =\u003e Array\n        (\n            [0] =\u003e 1\n            [1] =\u003e \n            [2] =\u003e 1\n        )\n\n    [2] =\u003e Array\n        (\n            [0] =\u003e 1\n            [1] =\u003e \n            [2] =\u003e \n        )\n\n)\n```\n\n### Outputting to graph file formats for use by other applications\n\nWe can export our graphs to data formats such as GML for use by other applications, such as Gephi:\n\n```php\n$gmlOutput = new \\Graph\\Output\\Gml();\n$gmlOutput-\u003ewriteToFile('testGraph.gml', $graphCon);\n```\nExporting the very basic graph example above to Gephi gives:\n\n![alt text](http://rhodrimorris.co.uk/basic-graph.png \"basic graph\")\n\nIt is also possible to assign labels and colours to nodes for use in external viewers:\n\n```php\n$node1-\u003ename = \"Node 1\";\n$node1-\u003ecolour = 'FF8888';\n```\n\n![alt text](http://rhodrimorris.co.uk/basic-graph2.png \"basic graph\")\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhodrim%2Fgraph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frhodrim%2Fgraph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhodrim%2Fgraph/lists"}