Giter Club home page Giter Club logo

graph-theory-plus-plus's Introduction

GraphTheory++

A library of C++ code that implements graph theoretical algorithms to be used by projects that require some form of graph structured data.

How to use it.

This example shows how to create a directed graph.

  // Include the Algorithm to be used.
  #include "Algorithms/DijkstrasDistanceAlgorithm.h";
  #include "Utils/Graph.h"
  #include <iostream>

Algorithms supported in Graph-Theory++

1. Dijkstra's Algorithm - Returns the length of the shortest path from a source vertex to every other vertex in the graph.  

Add to your client function:

  // Create an empty directed graph A.
  Graph G('A', 'D');
 
  // Add vertices and edges to the directed graph G.
  G.add_edge('b', 'a', 15);
  G.add_edge('b', 'c', 10);
  G.add_edge('d', 'c', 10);
  G.add_edge('d', 'g', 1);
  G.add_edge('g', 'f', 2);
  G.add_edge('f', 'e', 1);
  G.add_edge('d', 'e', 8);
  G.add_edge('b', 'd', 2);
  G.add_edge('b', 'g', 6);
  G.add_edge('g', 'a', 4);
  G.add_edge('f', 'a', 7);
  G.add_edge('e', 'c', 2);

The following graph is created:

image

  // Compute the distance from vertex b to every other vertex in G.
  map<char, int> distances_map = dijkstras_distances('b', G);

The result is the length of the shortest path between b and any other vertex in the graph.

L(a) = 7
L(b) = 0
L(c) = 8
L(d) = 2
L(e) = 6
L(f) = 5
L(g) = 3

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.