Skip to main content

Python Simple Directed Acyclic Graph whith Cicle Detector and TopoloGical sorter utilities.

Project description

The Python Simple Directed Graph whith Cicle Detector and TopoloGical sorter utilities.

Project Home Page

This project was be hosted on Github.

Authors

Install

Install it using the Python PIP Project.

pip install sdag2

Scripts

tsort.py

Sources from Standard Input:

echo -e 'C A\nA B\nB D\nC D' | tsort.py

Sources from another file:

echo -e 'C A\nA B\nB D\nC D' > verticies.txt
tsort.py verticies.txt

More Options:

tsort.py --help
Usage: tsort.py [options] [FILE [OUT_FILE]]

Options:
  -h, --help            show this help message and exit
  -f FILE, --file=FILE  With no FILE, or when FILE is -, read standard input.
  -o OUT_FILE, --out-file=OUT_FILE
                        Write result to OUT_FILE, default is standard output.
  -s SEP, --separator=SEP
                        Items separator, default is \s regex.
  -q QUIT_SEQ, --quit-sequence=QUIT_SEQ
                        Stop read FILE where line equals QUIT_SEQ, default is
                        :quit.

Tests

import unittest
from sdag2 import DAG, CycleDetectedException

class DAGTest(unittest.TestCase):
    def test_simple(self):
        '''
        Tests the verticles order in:

        C --> A --> B --> D
        '''

        dag = DAG()
        a = dag.add("A")
        b = dag.add("B")
        c = dag.add("C")
        d = dag.add("D")

        dag.add_edge(c, a)
        dag.add_edge(a, b)
        dag.add_edge(b, d)
        dag.add_edge(c, d)

        rs = dag.topologicaly()

        self.assertTrue(rs.index("C") < rs.index("A"))
        self.assertTrue(rs.index("A") < rs.index("B"))
        self.assertTrue(rs.index("B") < rs.index("D"))
        self.assertTrue(rs.index("C") < rs.index("D"))

    def test_cicle_detect(self):
        '''
        Tests the verticles order in:

        C --> A --> B --> D -> C
        '''

        dag = DAG()
        a = dag.add("A")
        b = dag.add("B")
        c = dag.add("C")
        d = dag.add("D")

        dag.add_edge(c, a)
        dag.add_edge(a, b)
        dag.add_edge(b, d)
        dag.add_edge(c, d)

        try:
            # add cicle at A --> C --> A
            dag.add_edge(a, c)
            raise Exception("Cycle not detected")
        except CycleDetectedException: pass

def main():
    unittest.main()

if __name__ == "__main__":
    main()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sdag2-1.0.4.tar.gz (7.1 kB view details)

Uploaded Source

Built Distributions

sdag2-1.0.4-py3.4.egg (15.2 kB view details)

Uploaded Source

sdag2-1.0.4-py2.7.egg (14.6 kB view details)

Uploaded Source

File details

Details for the file sdag2-1.0.4.tar.gz.

File metadata

  • Download URL: sdag2-1.0.4.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sdag2-1.0.4.tar.gz
Algorithm Hash digest
SHA256 4f07a836931d20af91686d84243d35900e3e51768d3a78fbd2d201d354b6b5d1
MD5 8155e89afb6fdc64b01231856b77a14a
BLAKE2b-256 3608ed2af129493606ec15df891860f76b3a139edc9522c816b7861e797d7363

See more details on using hashes here.

File details

Details for the file sdag2-1.0.4-py3.4.egg.

File metadata

  • Download URL: sdag2-1.0.4-py3.4.egg
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sdag2-1.0.4-py3.4.egg
Algorithm Hash digest
SHA256 1b7065108485a269e2362172369bc23386e2b334ccef05c28fcbd76cb67f96a6
MD5 135cfa11163c8d720041c07a255d1ebe
BLAKE2b-256 7fb4ee7bba78b25bc17a157ff856567b26691d4668744b1f30b7e4cf79f1c332

See more details on using hashes here.

File details

Details for the file sdag2-1.0.4-py2.7.egg.

File metadata

  • Download URL: sdag2-1.0.4-py2.7.egg
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sdag2-1.0.4-py2.7.egg
Algorithm Hash digest
SHA256 39c1cae94eb7e0fdb723394d9c26236547eb804747c250eec58cdfc97e31726f
MD5 dfe4e0c46eeff4eef9539a8f49cbbd7c
BLAKE2b-256 5c3be76d3f0ac6aa47307beeb52e2fac20fa6e8f1b0b7adbc6159736ecf5d837

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page