Skip to main content

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:

  • 1 represents an undirected edge.
  • 0.5 represents a directed edge away from a node.
  • -0.5 represents a directed edge towards a node.

Features

  1. Adding Nodes and Edges

    • add_node(node): Adds a node to the graph.
    • add_edge(nodes): Adds an edge to the graph. If nodes is a tuple, it is treated as a directed edge; if it is a list, it is treated as an undirected edge.
  2. 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.
  3. Getting Edges

    • get_undirected_edges(nodes=None): Returns all undirected edges. If nodes is specified, only edges involving those nodes are returned.
    • get_directed_edges(nodes=None): Returns all directed edges. If nodes is specified, only edges involving those nodes are returned.
  4. 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 by plot().

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

Metadata

Release files for HARPGraph2 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for HARPGraph2 0.1.0
File Size Uploaded
HARPGraph2-0.1.0.tar.gz 5.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for HARPGraph2 0.1.0
File Interpreter ABI Platform
HARPGraph2-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.9 kB

Release files / HARPGraph2-0.1.0.tar.gz

Download URL HARPGraph2-0.1.0.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e9aa6325ec88ba12e5a3c721796f81c1ec642bcc43839de7e315498619f2983c
BLAKE2b-256 checksum
How to use checksums
0b48948b258279396232b081183f8dbde2816af922d75d08cf404f1b7db4673f
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / HARPGraph2-0.1.0-py3-none-any.whl

Download URL HARPGraph2-0.1.0-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bd23c963539c5201adf41616e58440784e0d12c29afccea3ecacf9f2d6fa7165
BLAKE2b-256 checksum
How to use checksums
8861ad95a6bc1c791478fb47701c86d605a80fbe84e842686ae81ddb15062ec5
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page