Code Monkey home page Code Monkey logo

disconnectedgraphs's Introduction

Find the connected components of a graph (that's represened as a .dot file)

digraph G {

        x0 -> y0;
        x0 -> z0;
    
        x1 -> y1;
        x1 -> z1;
    
        x2 -> y2;
        x2 -> z2;

}

The graph has three connected components: Output of: dot -Tpng eg1.dot -o eg1.png

Try it out:

  1. Clone or download this tiny repo
  2. python3 -m venv venv
  3. source venv/bin/activate
  4. pip install requirements.txt
  5. python print_connected_components.py

output

(venv) Matts-Mac-mini:DisconnectedGraphs mpayne$ python print_connected_components.py
Component 1: {'y0', 'z0', 'x0'}
Component 2: {'x1', 'z1', 'y1'}
Component 3: {'z2', 'x2', 'y2'}
(venv) Matts-Mac-mini:DisconnectedGraphs mpayne$

References (thanks to Justin R from the awesome community at Recurse.com)

  1. To read a graphviz .dot file https://networkx.org/documentation/stable/reference/drawing.html?highlight=nx_pydot#module-networkx.drawing.nx_pydot
  2. To find the connect components of a graph https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.components.connected_components.html#networkx.algorithms.components.connected_components

disconnectedgraphs's People

Contributors

payne avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  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.