Skip to main content

Logical Graph Builder that can be used for various problems that can be modeled as a graph data structure

Project description

coopgraph

Logical Graph Builder that can be used for various problems that can be modeled as a graph data structure

An Example:

from Graphs import Graph, Node
from dataStructs import Vector2

a = Node(name='A', pos=Vector2(0, 0))
b = Node(name='B', pos=Vector2(3, 3))
c = Node(name='C', pos=Vector2(2, 0))
d = Node(name='D', pos=Vector2(2, 1))
e = Node(name='E', pos=Vector2(3, 4))
f = Node(name='F', pos=Vector2(5, 5))


g = { a: [d],
      b: [c],
      c: [b, d, e],
      d: [a, c],
      e: [c, f],
      f: []
    }

graph = Graph(g)

The graph structure can then be used to perform various graph-related analysis:

Two find nodes that have no outbound connections

print(graph.find_isolated_vertices())

To find the shortest path between two nodes

print(graph.astar(a, e))

Note that for astar calculation, edges can be enabled or disabled against one or more disablers. This is useful for implementing temporary criteria in:

edges_to_disable = [value for key, value in graph.edges()][:3]

graph.disable_edges(edges_to_disable, "myDisabler")
path = graph.astar(a, e)
graph.disable_edges(edges_to_disable, "myDisabler")

you can also ignore disablers directly by passing a list of disabler names to the astar() method

edges_to_disable = [value for key, value in graph.edges()][:3]
graph.disable_edges(edges_to_disable, "myIngoredDisabler")

ignored = ["myIngoredDisabler"]
path = graph.astar(a, e, ignored_disablers=ignored)

An astar() call can also include custom g and h functions that allow for better control of the astar algorithm

def g(node1 Node, node2: Node) -> float:
    if node1.pos - node2.pos > 10:
        return 1
    else
        return .5

def h(node1 Node, node2: Node) -> float:
    if node1.pos - node2.pos > 10:
        return 100
    else
        return -100

path = graph.astar(a, e, g_func=g, h_func=h)

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

coopgraph-1.4.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

coopgraph-1.4-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file coopgraph-1.4.tar.gz.

File metadata

  • Download URL: coopgraph-1.4.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for coopgraph-1.4.tar.gz
Algorithm Hash digest
SHA256 e3ec330829875ef00dcb447b536d18664ef488e37562bd3bd2cc4c3c2fee3b6f
MD5 c2932d0f3b2ea2a3ba7b2f2a9949f06f
BLAKE2b-256 0eeeb7f71b93d4c92fdfd51f2efc32b6f0a407fcc9624e5e0a4a76230ba74202

See more details on using hashes here.

File details

Details for the file coopgraph-1.4-py3-none-any.whl.

File metadata

  • Download URL: coopgraph-1.4-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for coopgraph-1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a27ca24338b123f2c0fd5a1d8dcd020fee906aeeb8b58dc77a34b95771103aa9
MD5 5e03a69c7caec708aa3723ea73f36396
BLAKE2b-256 6694af2ba1dcf1d627d3e1aebd6c9fc0487f042581350ca53090bf7e28677a0b

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