Git Product home page Git Product logo

grapho's Introduction

grapho Build Status GoDoc

grapho is a Go implementation of Graph Theory data structures and algorithms. The full documentation can be found here

Graphs

Graphs, both directed and undirected, are created with the Graph struct:

graph := grapho.NewGraph(false) // true for directed Graphs, false for undirected

Nodes (vertices) and Edges contain a set of attributes Attr, whose key is a string, and the value can be anything (type interface{}). Attr is in essence a map[string]interface{}, and its values are set/get with the regular map syntax:

attr := grapho.NewAttr()
attr["name"] = "Bob"
attr["x"] = 1

Nodes, uniquely identified by a uint64 id, can be added explicitly to the Graph:

graph.AddNode(1, attr)

or implicitly, if adding an Edge references a non-existing Node:

graph.AddEdge(1, 2, nil) // Node '2' will be automatically created

To check all the available methods to manipulate a Graph, see the GoDoc.

Algorithms

  • Dijkstra (uniform cost search)
  • A* (best-first search with heuristic)
  • Breadth-first search
  • Depth-first search

For the shortest path implementation, a generic Search function is provided, which takes the desired SearchAlgorithm to be used as a parameter:

path, err := grapho.Search(graph, 1, 8, grapho.Dijkstra, nil)
path, err := grapho.Search(graph, 1, 9, grapho.BreadthFirstSearch, nil)
...

If successful, a uint64 slice will be returned, with the node ids that form the shortest path between the specified nodes. Check out the second return value, for any possible error (i.e. no path found).

Minimum Spanning Tree:

  • Prim
  • TODO: Kruskal

Given a connected, undirected graph, MinimumSpanningTree calculates the minimum cost subgraph that connects all the vertices together:

mst, err := grapho.MinimumSpanningTree(graph, grapho.Prim)

TODO:

  • Multigraph
  • Minimum Cut
  • Topological short
  • Coloring algorithms
  • Strongly Connected Components
  • Eulerian path/circuit
  • Flow Networks
  • ...

Contributing

I have no priority in mind for future algorithms to implement, so if you want to contribute with any Graph Theory algorithm (whether or not in the list above), don't hesitate in opening an issue or sending a pull request!

License

This library is distributed under the BSD-style license found in the LICENSE file.

grapho's People

Contributors

ichinaski avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.