Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any JavaScript libraries for graph operations and algorithms?

What I need is a JavaScript implementation of pure mathematical graphs. To be clear I DON'T mean graph visualization libraries like sigma.js or d3.js.

The library I'm looking for would implement following features:

  • creation of directed and undirected graph objects
  • creation of weighted and unweighted graps objects
  • adding/removing vertices and edges to/from the graph
  • adding labels to vertices and edges (i.e. additional meta data)
  • implementation of basic graph search and traversal algorithms like depth-first-search, breadth-first search, Dijkstra's algorithm, A* and others.

Does anyone know if one already exists?

like image 310
Akseli Palén Avatar asked Jan 23 '13 15:01

Akseli Palén


People also ask

Does Java have a graph library?

JGraphT is a free Java graph library that provides mathematical graph-theory objects and algorithms. JGraphT supports various types of graphs including: * directed and undirected graphs. * graphs with weighted / unweighted / labeled or any user-defined edges.

What is a graph library?

A graph is a mathematical concept consisting of nodes and edges. Graphs are used throughout computer science and especially machine learning. The Infer.Net graph library provides data structures for representing graphs and algorithms for operating on graphs.

What are graphs in JS?

A graph is a data structure where a node can have zero or more adjacent elements. The connection between two nodes is called edge. Nodes can also be called vertices. The degree is the number of edges connected to a vertex.


2 Answers

Now there is a library: graphlib

Graphlib is a JavaScript library that provides data structures for undirected and directed multi-graphs along with algorithms that can be used with them.

Implements:

  • directed and undirected graphs (does A -> B imply B -> A)
  • multigraphs (multiple distinct named edges from A -> B)
  • compound graphs (nodes can have children that form a "subgraph")
  • Dijkstra algorithm (shortest path)
  • Floyd-Warshall algorithm (shortest path supporting negative weights)
  • Prim's algorithm (minimum spanning tree)
  • Tarjan's algorithm (strongly connected components)
  • Topological sorting (dependency sort for directed acyclic graphs)
  • Pre- and postorder traversal (callback on every node)
  • Finding all cycles and testing if a graph is acyclic
  • Finding all connected components

NPM, Bower and browser supported, MIT license.

like image 86
Nakedible Avatar answered Sep 21 '22 17:09

Nakedible


Before few months I created a repository with implementations of different CS algorithms in JavaScript. There are also few algorithms with graphs. I plan to extend it (spanning trees, heuristic algorithms probably chromatic graphs) but since then I think that there are still few algorithms which could help you.

like image 41
Minko Gechev Avatar answered Sep 19 '22 17:09

Minko Gechev