Skip to main content

Graphs and Dijkstra's algorithm by Charawi Detphumi

Project description

ShabiiNetwork is a Python library for dealing with Graphs and Dijkstra’s algorithm.

Installation

Use the package manager pip to install ShabiiNetwork.

pip install ShabiiNetwork

Usage

from ShabiiNetwork import Digraph,Dijkstra

graph2 = Digraph()

    #To check add_edge and add_edges functions
    graph2.add_edges([('A','B',0.3),('A','C',0.5),
                     ('B','A',0.3),('B','C',0.9),
                     ('C','A',0.5),('C','D',1.2),
                     ('D','C',1.2)])
    print(graph2.Edict)

    graph2.add_edges([('A','D',45),('A','E',23)])
    print(graph2.Edict)

    #To check remove_edge and remove_edges functions
    graph2.remove_edges([('A','D'),('A','E')])
    print(graph2.Edict)

    #To check add_vertex and add_vertices functions
    graph2.add_vertices(['I','J','K'])
    print(graph2.Edict)

    #To check remove_vertex and remove_vertices functions
    graph2.remove_vertices(['I','J','K'])
    print(graph2.Edict)

    #To check Dijkstra class and its functions
    dijkstra = Dijkstra(graph2, start_vertex='A')
    dijkstra.dijkstra()
    dijkstra.print_result()

    """
    Output:

    {'A': {'B': 0.3, 'C': 0.5}, 'B': {'A': 0.3, 'C': 0.9}, 'C': {'A': 0.5, 'D': 1.2}, 'D': {'C': 1.2}}
    {'A': {'B': 0.3, 'C': 0.5, 'D': 45, 'E': 23}, 'B': {'A': 0.3, 'C': 0.9}, 'C': {'A': 0.5, 'D': 1.2}, 'D': {'C': 1.2}}
    {'A': {'B': 0.3, 'C': 0.5}, 'B': {'A': 0.3, 'C': 0.9}, 'C': {'A': 0.5, 'D': 1.2}, 'D': {'C': 1.2}}
    {'A': {'B': 0.3, 'C': 0.5}, 'B': {'A': 0.3, 'C': 0.9}, 'C': {'A': 0.5, 'D': 1.2}, 'D': {'C': 1.2}, 'I': {}, 'J': {}, 'K': {}}
    {'A': {'B': 0.3, 'C': 0.5}, 'B': {'A': 0.3, 'C': 0.9}, 'C': {'A': 0.5, 'D': 1.2}, 'D': {'C': 1.2}}
    A -> A: ['A'] distance: 0
    A -> B: ['A', 'B'] distance: 0.3
    A -> C: ['A', 'C'] distance: 0.5
    A -> D: ['A', 'C', 'D'] distance: 1.7
    """

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Author

Charawi Detphumi

License

MIT

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

ShabiiNetwork-0.0.1.tar.gz (4.3 kB view hashes)

Uploaded Source

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