https://github.com/iitis/labelledgraphs.jl
Graphs with vertices labelled with arbitrary objects
https://github.com/iitis/labelledgraphs.jl
Last synced: 12 months ago
JSON representation
Graphs with vertices labelled with arbitrary objects
- Host: GitHub
- URL: https://github.com/iitis/labelledgraphs.jl
- Owner: iitis
- License: apache-2.0
- Created: 2021-03-04T12:56:13.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-02-01T13:45:52.000Z (over 2 years ago)
- Last Synced: 2025-06-18T14:55:49.151Z (12 months ago)
- Language: Julia
- Homepage:
- Size: 37.1 KB
- Stars: 3
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://coveralls.io/github/iitis/LabelledGraphs.jl?branch=kj/initial-implementation)
# LabelledGraphs.jl
Graphs with vertices labelled with arbitrary objects.
## Motivation
Graphs from `LightGraphs` use vertices labelled with contiuous integer range starting from 1.
This poses a problem if one wants to handle graphs whose vertices are labelled either by more general integer ranges or other objects (e.g. strings).
`LabelledGraphs` extend `LightGraphs` by allowing more flexible labelling of verices.
## Usage
Labelled graph can be created by providing a sequence of labels, i.e.:
```julia
using LabelledGraphs
lg = LabelledGraph(["a", "b", "c"]) # Undirected graph with vertices a, b, c
ldg = LabelledDiGraph([4, 5, 10]) # Directed graph with vertices 4, 5, 10
```
One can also create labelled graph backed by a simple graph from `LightGraphs`.
```julia
using LabelledGraphs
using LightGraphs
g = path_graph(5)
lg = LabelledGraph(["a", "b", "c", "d", "e"], g)
```
Once the graph is created, it can be used mostly like other graphs rom `LightGraph`.
All method operate on labels given during graph's construction, for instance:
```julia
using LabelledGraphs
using LightGraphs
g = path_digraph(5)
lg = LabelledGraph(["a", "b", "c", "d", "e"], g)
println(vertices(lg)) # prints ["a", "b", "c", "d", "e"]
println(edges(lg)) # prints edges "a" -> "b", "b" -> "c" etc.
add_edge!(lg, "e", "b")
println(inneighbors(lg, "b")) # prints ["a", "e"]
```
Additionally, one can add new vertices to the `LabelledGraph`, either by using `add_vertex!` or `add_vertices!`.
```julia
add_vertex!(lg, "f")
add_vertices!(lg, ["u", "v", "w"])
```