{"id":13936725,"url":"https://github.com/TaipanRex/pyvisgraph","last_synced_at":"2025-07-19T22:31:38.934Z","repository":{"id":39916535,"uuid":"50633227","full_name":"TaipanRex/pyvisgraph","owner":"TaipanRex","description":"Given a list of simple obstacle polygons, build the visibility graph and find the shortest path between two points","archived":false,"fork":false,"pushed_at":"2020-12-18T11:40:50.000Z","size":929,"stargazers_count":222,"open_issues_count":29,"forks_count":45,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-11-14T22:56:03.070Z","etag":null,"topics":["shortest-path","visibility-graph","visibility-graph-algorithm"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TaipanRex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-29T03:04:13.000Z","updated_at":"2024-11-14T14:25:18.000Z","dependencies_parsed_at":"2022-09-09T22:50:21.952Z","dependency_job_id":null,"html_url":"https://github.com/TaipanRex/pyvisgraph","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TaipanRex%2Fpyvisgraph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TaipanRex%2Fpyvisgraph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TaipanRex%2Fpyvisgraph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TaipanRex%2Fpyvisgraph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TaipanRex","download_url":"https://codeload.github.com/TaipanRex/pyvisgraph/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226686730,"owners_count":17666928,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["shortest-path","visibility-graph","visibility-graph-algorithm"],"created_at":"2024-08-07T23:02:56.504Z","updated_at":"2024-11-27T04:31:22.790Z","avatar_url":"https://github.com/TaipanRex.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Pyvisgraph - Python Visibility Graph\r\n\r\n[![MIT License](https://img.shields.io/github/license/taipanrex/pyvisgraph.svg?style=flat)](/LICENSE.txt)\r\n[![PyPI](https://img.shields.io/pypi/v/pyvisgraph.svg?style=flat)](https://pypi.python.org/pypi/pyvisgraph)\r\n\r\nGiven a set of simple obstacle polygons, build a visibility graph and find\r\nthe shortest path between two points.\r\n\r\n![Figure 1](docs/images/graph.png)\r\n\r\nPyvisgraph is a MIT-licensed Python package for building visibility graphs from\r\na list of simple obstacle polygons. The visibility graph algorithm (D.T. Lee)\r\nruns in O(n^2 log n) time. The shortest path is found using Djikstra's\r\nalgorithm.\r\n\r\nTo see how visibility graphs work interactively, take a look at the\r\n[Visibility Graph Simulator](https://github.com/TaipanRex/visgraph_simulator)\r\nbuilt with Pyvisgraph.\r\n\r\n## Installing Pyvisgraph\r\n```\r\n$ pip install pyvisgraph\r\n```\r\nPyvisgraph supports Python 2 and 3.\r\n\r\n## Usage\r\nHere is an example of building a visibility graph given a list of\r\nsimple polygons:\r\n```\r\n\u003e\u003e\u003e import pyvisgraph as vg\r\n\u003e\u003e\u003e polys = [[vg.Point(0.0,1.0), vg.Point(3.0,1.0), vg.Point(1.5,4.0)],\r\n\u003e\u003e\u003e          [vg.Point(4.0,4.0), vg.Point(7.0,4.0), vg.Point(5.5,8.0)]]\r\n\u003e\u003e\u003e g = vg.VisGraph()\r\n\u003e\u003e\u003e g.build(polys)\r\n\u003e\u003e\u003e shortest = g.shortest_path(vg.Point(1.5,0.0), vg.Point(4.0, 6.0))\r\n\u003e\u003e\u003e print shortest\r\n[Point(1.50, 0.00), Point(3.00, 1.00), Point(4.00, 6.00)]\r\n```\r\nOnce the visibility graph is built, it can be saved and subsequently loaded.\r\nThis is useful for large graphs where build time is long. `pickle` is used\r\nfor saving and loading.\r\n```\r\n\u003e\u003e\u003e g.save('graph.pk1')\r\n\u003e\u003e\u003e g2 = VisGraph()\r\n\u003e\u003e\u003e g2.load('graph.pk1')\r\n```\r\nFor obstacles with a large number of points, Pyvisgraph can take advantage of\r\nprocessors with multiple cores using the `multiprocessing` module. Simply\r\nadd the number of workers (processes) to the `build` method:\r\n```\r\n\u003e\u003e\u003e g.build(polys, workers=4)\r\n```\r\nPyvisgraph also has some useful helper functions:\r\n* `g.update([list of Points])`: Updates the visibility graph\r\n  by checking visibility of each `Point` in the list.\r\n* `g.point_in_polygon(Point)`: Check if `Point` is in the interior of any of\r\n  the obstacle polygons. Returns the polygon_id of said polygon, -1 if not\r\n  inside any polygon.\r\n* `g.closest_point(Point, polygon_id)`: Return the closest point outside\r\n  polygon with polygon_id from Point.\r\n\r\nFor further examples, please look at the scripts provided in the `examples`\r\nfolder.\r\n\r\n## Example \u0026 performance\r\nThis example uses a shapefile representing world shorelines as obstacles.\r\nTwo vessels were picked randomly and their current location found\r\nusing [AIS](https://en.wikipedia.org/wiki/Automatic_identification_system). Red\r\nlines are laden voyage legs (carrying cargo) and dotted blue lines are ballast\r\nlegs (no cargo, moving to load destination). Pyvisgraph has the following\r\nperformance on a Microsoft Surface Pro 3 (Intel i7-4650U @ 1.7Ghz, 8GB DDR3\r\nRAM), where time is in seconds:\r\n```\r\nShoreline obstacle graph [points: 4335 edges: 4335]\r\nUsing 4 worker processes...\r\nTime to create visibility graph: 554.683238029\r\nVisibility graph edges: 118532\r\nTime to update visgraph \u0026 find shortest path: 1.09287905693\r\nShorest path nodes: 19\r\nTime to find shortest path between existing points: 0.508340835571\r\n```\r\nFor one vessel the origin and destination Points were not part of the built\r\nvisibility graph and had to first be computed. For the second vessel, these\r\nPoints were first added to the visibility graph using `update`, then finding\r\nthe shortest path is faster. Using Matplotlib basemap to visualize the routes:\r\n![Figure 2](docs/images/example.png)\r\n\r\nFor more information about the implementation, see these series of articles:\r\n* [Distance Tables Part 1: Defining the Problem](https://taipanrex.github.io/2016/09/17/Distance-Tables-Part-1-Defining-the-Problem.html)\r\n* [Distance Tables Part 2: Lee's Visibility Graph Algorithm](https://taipanrex.github.io/2016/10/19/Distance-Tables-Part-2-Lees-Visibility-Graph-Algorithm.html)\r\n* More to come...\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTaipanRex%2Fpyvisgraph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTaipanRex%2Fpyvisgraph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTaipanRex%2Fpyvisgraph/lists"}