pygraph-tool is a module to create and manipulate graphs.
Project description
pygraph-tool
pygraph-tool is a module to create and manipulate graphs. Nodes can be all objects who you want and edges are oriented and valued at 1 by default. If you wish one graph not oriented, edges must be declared in one direction and then in the other.
Getting started
# import module
from pygraph_tool.graph import Graph
# Create function for display graph
def displayGraph(graph: Graph) -> None:
# retrieve the list graph's nodes and edges
nodes = graph.nodes
edges = graph.edges
# display the graph's nodes
for node in nodes:
print(f"{node.node_id}: {node.node_content}")
# display the graph's edges
for edge in edges:
message: str = (
f"{edge.node_start.node_id} "
f"--- {edge.edge_id} = {edge.weight} ---> "
f"{edge.node_end.node_id}"
)
print(message)
# create a new graph
graph: Graph = Graph()
# create n1, n2 and n3, three nodes of graph
graph.add_node("I'm n1", "n1")
graph.add_node("I'm n2", "n2")
graph.add_node("I'm n3", "n3")
"""
create edge e1 such as n1->n2 with weight = 1.5,
edge e2 such as n3->n2 with weight by default = 1
and edge e3 such as n1->n3 with weight by default = 1
"""
graph.add_unidirectional_edge("n1", "n2", "e1", 1.5)
graph.add_unidirectional_edge("n3", "n2", "e2")
graph.add_unidirectional_edge("n1", "n3", "e3")
# Display graph
displayGraph(graph)
print()
# remove the node n2 and all edges binded to node n2
graph.remove_node("n2")
# Display graph
displayGraph(graph)
print()
# remove the edge e3
graph.remove_edge("e3")
# Display graph
displayGraph(graph)
Author
If you have any questions or suggestions, please don't hesitate to contact me : belaich.david@outlook.fr .
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pygraph-tool-0.0.0.tar.gz
(4.6 kB
view details)
Built Distribution
File details
Details for the file pygraph-tool-0.0.0.tar.gz
.
File metadata
- Download URL: pygraph-tool-0.0.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 625be3845cb8a6896101c4473091ffc3f143629d6382417065f3163b6c533434 |
|
MD5 | 3ba088b6f2caf7b44a00e9ed80411972 |
|
BLAKE2b-256 | 5214f7e5619b4678518dfbf85b7ecb2f94a09834d8e081d185cb20ff0d006f7b |
File details
Details for the file pygraph_tool-0.0.0-py3-none-any.whl
.
File metadata
- Download URL: pygraph_tool-0.0.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47becc130fa81585f0dc5c1c7cd54983d76f4c98cc28a0f92e30eab1718c103b |
|
MD5 | bd46c042ab09df3f0b48c5b7d508c546 |
|
BLAKE2b-256 | 16512301a638e8782d2caa774ae0227b75d018143456faf82a87738796c705d0 |