Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/camertron/simple-graph
A simple, no-frills graph implementation.
https://github.com/camertron/simple-graph
Last synced: 18 days ago
JSON representation
A simple, no-frills graph implementation.
- Host: GitHub
- URL: https://github.com/camertron/simple-graph
- Owner: camertron
- Created: 2014-06-22T20:42:48.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-06-23T04:48:59.000Z (over 10 years ago)
- Last Synced: 2024-11-04T00:42:04.271Z (2 months ago)
- Language: Ruby
- Size: 125 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: History.txt
Awesome Lists containing this project
README
## simple-graph [![Build Status](https://secure.travis-ci.org/camertron/simple-graph.png?branch=master)](http://travis-ci.org/camertron/simple-graph)
A simple, no-frills graph implementation.
## Installation
`gem install simple-graph`
## Usage
```ruby
require 'simple-graph'
```### Adding Vertices
Let's model an airline that flies to certain cities:
```ruby
graph = SimpleGraph::Graph.new
graph.add_vertex('Seattle')
graph.add_vertex('Los Angeles')
graph.add_vertex('Denver')
graph.add_vertex('New York')
graph.add_vertex('Miami')
```### Adding Edges
```ruby
graph.add_edge('Seattle', 'Los Angeles')
graph.add_edge('Seattle', 'Denver')
graph.add_edge('Los Angeles', 'Miami')
graph.add_edge('Denver', 'New York')
graph.add_edge('New York', 'Miami')
```### Shortest Path
SimpleGraph doesn't support weighted edges, so let's pretend all these cities are equidistant from each other. We could also say we're trying to find the least number of layovers:
```ruby
graph.shortest_path('Seattle', 'Miami') # ["Seattle", "Los Angeles", "Miami"]
```## Requirements
None.
## Running Tests
`bundle exec rspec`
## Authors
* Cameron C. Dutro: http://github.com/camertron