{"id":21615985,"url":"https://github.com/pharo-ai/graph-algorithms","last_synced_at":"2025-04-11T07:25:11.537Z","repository":{"id":44790202,"uuid":"395044936","full_name":"pharo-ai/graph-algorithms","owner":"pharo-ai","description":"A graph algorithms library implemented in Pharo","archived":false,"fork":false,"pushed_at":"2024-03-05T13:12:01.000Z","size":290,"stargazers_count":18,"open_issues_count":4,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-03-05T14:28:01.778Z","etag":null,"topics":["graph","graph-algorithms","pharo","smalltalk"],"latest_commit_sha":null,"homepage":"","language":"Smalltalk","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/pharo-ai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2021-08-11T16:01:11.000Z","updated_at":"2024-03-05T14:28:09.898Z","dependencies_parsed_at":"2023-02-01T05:46:09.933Z","dependency_job_id":"96927c85-8b86-407a-9a81-f73670f51bc4","html_url":"https://github.com/pharo-ai/graph-algorithms","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pharo-ai%2Fgraph-algorithms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pharo-ai%2Fgraph-algorithms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pharo-ai%2Fgraph-algorithms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pharo-ai%2Fgraph-algorithms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pharo-ai","download_url":"https://codeload.github.com/pharo-ai/graph-algorithms/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226238804,"owners_count":17593679,"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":["graph","graph-algorithms","pharo","smalltalk"],"created_at":"2024-11-24T22:13:18.062Z","updated_at":"2024-11-24T22:13:18.674Z","avatar_url":"https://github.com/pharo-ai.png","language":"Smalltalk","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Graph Algorithms\n\n[![Build status](https://github.com/pharo-ai/linear-models/workflows/CI/badge.svg)](https://github.com/pharo-ai/graph-algorithms/actions/workflows/CI.yml)\n[![Coverage Status](https://coveralls.io/repos/github/pharo-ai/graph-algorithms/badge.svg?branch=master)](https://coveralls.io/github/pharo-ai/graph-algorithms?branch=master)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)\n[![Pharo version](https://img.shields.io/badge/Pharo-9-%23aac9ff.svg)](https://pharo.org/download)\n[![Pharo version](https://img.shields.io/badge/Pharo-10-%23aac9ff.svg)](https://pharo.org/download)\n[![Pharo version](https://img.shields.io/badge/Pharo-11-%23aac9ff.svg)](https://pharo.org/download)\n[![Pharo version](https://img.shields.io/badge/Pharo-12-%23aac9ff.svg)](https://pharo.org/download)\n[![license-badge](https://img.shields.io/badge/license-MIT-blue.svg)](https://img.shields.io/badge/license-MIT-blue.svg)\n\nFor more information please refer to the pharo-ai wiki: https://github.com/pharo-ai/wiki/blob/master/wiki/Graphs/Graph-Algorithms.md\n\nOr also to our graphs booklet [Booklet-PharoGraphs](https://github.com/SquareBracketAssociates/Booklet-PharoGraphs)\n\n## Table of Contents\n\n- [Description](#description)\n- [How to install it](#how-to-install-it)\n- [How to depend on it](#how-to-depend-on-it)\n- [Implemented graph algorithms](#implemented-graph-algorithms)  \n- [How to use the graph algorithms](#how-to-use-the-graph-algorithms)  \n- [Graph generation algorithms](#graph-generation-algorithms)\n\n## Description\n\nThis library contains several graphs algorithms. The nodes in the graph can be any kind of object: a Character, a String, an Integer or a complex object.\n\n## How to install it\n\n```smalltalk\nEpMonitor disableDuring: [\n    Metacello new\n        repository: 'github://pharo-ai/graph-algorithms';\n        baseline: 'AIGraphAlgorithms';\n        load ]\n```\n\n## How to depend on it\n\nIf you want to add this repo to your Metacello Baselines or Configurations, copy and paste the following expression:\n```smalltalk\nspec\n    baseline: 'AIGraphAlgorithms' \n    with: [ spec repository: 'github://pharo-ai/graph-algorithms' ]\n```\n\n## Implemented graph algorithms\n\n  - Tarjan’s Algorithm: Strongly Connected Components\n  - BFS: Breath First Search\n  - Graph Reducer: Merge all strongly connected components in a graph to a single node\n  - Dijkstra: Shortest path in a weighted graph\n  - Bellman-Ford: Shortest path in negative weighted graphs\n  - Kruskal: Minimum or Maximum expanding tree in a graph\n  - HITS: Hyperlink-Induced Topic Search\n  - Topological Sort\n  - Shortest Path in DAG\n  - Longest path in DAG\n  - Longest path in any type of graph\n  - Dinic: strongly polynomial algorithm for computing the maximum flow in a flow network\n  - A* algorithm: searching algorithm for having the shortest path\n\n## How to use the graph algorithms\n\nThe below code was extracted from the Pharo Graphs booklet which is a booklet in which this library along with all the algorithms are explained. You can check it out in [Booklet-PharoGraphs](https://github.com/SquareBracketAssociates/Booklet-PharoGraphs)\n\nAll the graph algorithms of this library share a common API also. The class AIGraphAlgorithm provides the common API to add nodes, edges, searching the nodes, etc.\n\nSome of the common methods are:\n- `algorithm nodes:`\n- `algorithm nodes`\n- `algorithm edges`\n- `algorithm edges:from:to:`\n- `algorithm edges:from:to:weight:`\n- `algorithm findNode:`\n- `algorithm run`\n\n### Example 1\n\nFor using the topological sort algorithm, we can run this code snippet\n\n```st\n\"First define the nodes and the edges\"\nnodes := #( $A $B $C $D $E $F $G ).\nedges := #( #( $A $B ) #( $A $C ) #( $B $E ) #( $C $E ) #( $C $D )\n    #( $D $E ) #( $D $F ) #( $E $G ) #( $F $G ) ).\n\n\"Instantiate the graph algorithm\"\ntopSortingAlgo := AITopologicalSorting new.\n\n\"Set the nodes and edges\"    \ntopSortingAlgo nodes: nodes.\ntopSortingAlgo\n    edges: edges\n    from: [ :each | each first ]\n    to: [ :each | each second ].\n\n\"Run to obtain the result\"\ntopologicalSortedElements := topSortingAlgo run.\n```\n\n### Example 2\n\nOr if we want to find the shortest path in a weighted graph:\n\n```st\nnodes := $A to: $F.\nedges := #( #( $A $B 5 ) #( $A $C 1 ) #( $B $C 2 ) #( $B $E 20 )\n    #( $B $D 3 ) #( $C $B 3 ) #( $C $E 12 ) #( $D $C 3 )\n    #( $D $E 2 ) #( $D $F 6 ) #( $E $F 1 ) ).\n\ndijkstra := AIDijkstra new.\ndijkstra nodes: nodes.\ndijkstra\n    edges: edges\n    from: [ :each | each first ]\n    to: [ :each | each second ]\n    weight: [ :each | each third ].\n\nshortestPathAToB := dijkstra runFrom: $A to: $B.\npathDistanceAToB := (dijkstra findNode: $B) pathDistance.\n\ndijkstra end: $F.\nshortestPathAToF := dijkstra reconstructPath.\npathDistanceAToF := (dijkstra findNode: $F) pathDistance.\n\ndijkstra reset.\nshortestPathBToE := dijkstra runFrom: $B to: $E.\n```\n\n## Graph generation algorithms\n\nThis library also contains algorithms for generating regular and random graphs. This algorithms are not loaded by default. To load them, you can either load them manually using Iceberg directly from the Pharo image or load the `GraphGenerators` baseline group.\n\nThe algorithms implemented are:\n\n- Albert Barabasi Graph Generator\n- Atlas Graph Graph Generator\n- Erdos Renyi GNM Graph Generator\n- Erdos Renyi GNP Graph Generator\n- Grid 2D Graph Generator\n- Grid 3D Graph Generator\n- Hexagonal Lattice Graph Generator\n- Kleinberg Graph Generator\n- Triangular Lattice Graph Generator\n- Waltz Strogatz Graph Generator\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpharo-ai%2Fgraph-algorithms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpharo-ai%2Fgraph-algorithms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpharo-ai%2Fgraph-algorithms/lists"}