A generalized graph library for dealing with generalized graph structures.
Project description
research, Inc. - HARPGraph2
HARPGraph2 (v0.1.0)
A generalized graph library for dealing with generalized graph structures. - Made by Harper Chisari
PseudoDiGraph
PseudoDiGraph is a class that supports both directed and undirected edges, as well as hyperedges. It uses an incidence matrix to represent the graph, where:
1represents an undirected edge.0.5represents a directed edge away from a node.-0.5represents a directed edge towards a node.
Features
-
Adding Nodes and Edges
add_node(node): Adds a node to the graph.add_edge(nodes): Adds an edge to the graph. Ifnodesis a tuple, it is treated as a directed edge; if it is a list, it is treated as an undirected edge.
-
Removing Nodes and Edges
remove_node(node): Removes a node and all edges connected to it from the graph.remove_edge(nodes): Removes a specified edge from the graph.
-
Getting Edges
get_undirected_edges(nodes=None): Returns all undirected edges. Ifnodesis specified, only edges involving those nodes are returned.get_directed_edges(nodes=None): Returns all directed edges. Ifnodesis specified, only edges involving those nodes are returned.
-
Plotting and Exporting
plot(): Plots the graph and stores the coordinates for future exports.export(output_folder='output_images', filename='graph_plot.png'): Exports the graph plot to a specified file using the coordinates generated byplot().
Examples
Creating a Directed Graph
from HARPGraph2 import PseudoDiGraph
# Create a directed graph
graph = PseudoDiGraph(directed=True)
graph.add_edge(('A', 'B')) # Directed edge from A to B
print("Directed edges:", graph.get_directed_edges())
graph.plot() # Displays the plot
graph.export() # Saves the plot to the default 'output_images/graph_plot.png'
Creating an Undirected Graph
from HARPGraph2 import PseudoDiGraph
# Create an undirected graph
graph = PseudoDiGraph()
graph.add_node('C')
graph.add_node('D')
graph.add_edge(('C', 'D')) # Unordered hyper edge between C and D
graph.add_node('E')
graph.add_node('F')
graph.add_edge(('D', 'E')) # Directed edge from D to E
graph.add_edge(('E', 'C')) # Directed edge from E to D
graph.add_edge(['C', 'F']) # Undirected edge between C and F
print("Undirected edges:", graph.get_undirected_edges())
print("Directed edges:", graph.get_directed_edges())
graph.plot() # Displays the plot
graph.export(output_folder="output_images") # Saves the plot to the default 'output_images/graph_plot.png'
Removing Nodes and Edges
from HARPGraph2 import PseudoDiGraph
# Create a graph and add nodes and edges
graph = PseudoDiGraph()
graph.add_node('C')
graph.add_node('D')
graph.add_edge(('C', 'D')) # Unordered hyper edge between C and D
graph.add_node('E')
graph.add_node('F')
graph.add_edge(('D', 'E')) # Directed edge from D to E
graph.add_edge(('E', 'C')) # Directed edge from E to D
graph.add_edge(['C', 'F']) # Undirected edge between C and F
# Remove edges and nodes
graph.remove_edge(('C', 'D'))
graph.remove_node('E')
print("Undirected edges after removal:", graph.get_undirected_edges())
print("Directed edges after removal:", graph.get_directed_edges())
graph.plot() # Displays the plot after removals
graph.export(output_folder="output_images", filename="graph_plot_after_removal.png") # Saves the plot to 'output_images/graph_plot_after_removal.png'
Installation
To install the library, clone the repository and run:
pip install HARPGraph2
${\color{grey}\textsf{Copyright © 2024 HARP research, Inc. Visit us at }}$ https://harpresearch.ai
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file HARPGraph2-0.1.0.tar.gz.
File metadata
- Download URL: HARPGraph2-0.1.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.65.0 urllib3/1.26.15 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9aa6325ec88ba12e5a3c721796f81c1ec642bcc43839de7e315498619f2983c
|
|
| MD5 |
7af948122ebd4bdd91c4e130b105af2f
|
|
| BLAKE2b-256 |
0b48948b258279396232b081183f8dbde2816af922d75d08cf404f1b7db4673f
|
File details
Details for the file HARPGraph2-0.1.0-py3-none-any.whl.
File metadata
- Download URL: HARPGraph2-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.65.0 urllib3/1.26.15 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd23c963539c5201adf41616e58440784e0d12c29afccea3ecacf9f2d6fa7165
|
|
| MD5 |
37da2ac394b07e98df669bd227d498ab
|
|
| BLAKE2b-256 |
8861ad95a6bc1c791478fb47701c86d605a80fbe84e842686ae81ddb15062ec5
|