{"id":13856747,"url":"https://github.com/pysal/spopt","last_synced_at":"2025-06-20T02:41:23.885Z","repository":{"id":37854753,"uuid":"173353142","full_name":"pysal/spopt","owner":"pysal","description":"Spatial Optimization","archived":false,"fork":false,"pushed_at":"2025-06-11T16:47:16.000Z","size":144825,"stargazers_count":336,"open_issues_count":29,"forks_count":54,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-06-11T18:11:36.827Z","etag":null,"topics":["facility-location","location-allocation","location-modeling","python","regionalization","resource-planning","routing","spatial-analysis","spatial-optimization","transportation"],"latest_commit_sha":null,"homepage":"https://pysal.org/spopt/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pysal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-03-01T18:56:11.000Z","updated_at":"2025-06-11T16:47:21.000Z","dependencies_parsed_at":"2024-06-18T15:34:32.094Z","dependency_job_id":"a83165ed-bd1e-4e83-b23f-6dd725b40d32","html_url":"https://github.com/pysal/spopt","commit_stats":{"total_commits":826,"total_committers":19,"mean_commits":"43.473684210526315","dds":0.5932203389830508,"last_synced_commit":"464fd650cb1662432609c06d660c39f0f36c9eb4"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/pysal/spopt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pysal%2Fspopt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pysal%2Fspopt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pysal%2Fspopt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pysal%2Fspopt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pysal","download_url":"https://codeload.github.com/pysal/spopt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pysal%2Fspopt/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260188825,"owners_count":22971875,"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":["facility-location","location-allocation","location-modeling","python","regionalization","resource-planning","routing","spatial-analysis","spatial-optimization","transportation"],"created_at":"2024-08-05T03:01:11.604Z","updated_at":"2025-06-20T02:41:18.874Z","avatar_url":"https://github.com/pysal.png","language":"Python","readme":"\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"docs/_static/images/pysal_banner.svg\" width=\"370\" height=\"200\" /\u003e\n\u003c/p\u003e\n\n# `spopt`: Spatial Optimization\n\n#### Regionalization, facility location, and transportation-oriented modeling\n\n![tag](https://img.shields.io/github/v/release/pysal/spopt?include_prereleases\u0026sort=semver)\n[![Continuous Integration](https://github.com/pysal/spopt/actions/workflows/testing.yml/badge.svg)](https://github.com/pysal/spopt/actions/workflows/testing.yml)\n[![codecov](https://codecov.io/gh/pysal/spopt/branch/main/graph/badge.svg)](https://codecov.io/gh/pysal/spopt)\n[![Documentation](https://img.shields.io/static/v1.svg?label=docs\u0026message=current\u0026color=9cf)](http://pysal.org/spopt/)\n[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n[![status](https://joss.theoj.org/papers/1413cf2c0cf3c561386949f2e1208563/status.svg)](https://joss.theoj.org/papers/1413cf2c0cf3c561386949f2e1208563)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4444156.svg)](https://doi.org/10.5281/zenodo.4444156)\n[![Discord](https://img.shields.io/badge/Discord-join%20chat-7289da?style=flat\u0026logo=discord\u0026logoColor=cccccc\u0026link=https://discord.gg/BxFTEPFFZn)](https://discord.gg/BxFTEPFFZn)\n\n\nSpopt is an open-source Python library for solving optimization problems with spatial data. Originating from the `region` module in [PySAL (Python Spatial Analysis Library)](http://pysal.org), it is under active development for the inclusion of newly proposed models and methods for regionalization, facility location, and transportation-oriented solutions. \n\n### Regionalization\n\n```python\nimport spopt, libpysal, geopandas, numpy\nmexico = geopandas.read_file(libpysal.examples.get_path(\"mexicojoin.shp\"))\nmexico[\"count\"] = 1\nattrs = [f\"PCGDP{year}\" for year in range(1950, 2010, 10)]\nw = libpysal.weights.Queen.from_dataframe(mexico)\nmexico[\"count\"], threshold_name, threshold, top_n = 1, \"count\", 4, 2\nnumpy.random.seed(123456)\nmodel = spopt.region.MaxPHeuristic(mexico, w, attrs, threshold_name, threshold, top_n)\nmodel.solve()\nmexico[\"maxp_new\"] = model.labels_\nmexico.plot(column=\"maxp_new\", categorical=True, figsize=(12,8), ec=\"w\");\n```\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"docs/_static/images/maxp.svg\" height=\"350\" /\u003e\n\u003c/p\u003e\n\n### Locate\n```python\nfrom spopt.locate import MCLP\nfrom spopt.locate.util import simulated_geo_points\nimport numpy, geopandas, pulp, spaghetti\n\nsolver = pulp.PULP_CBC_CMD(msg=False, warmStart=True)\nlattice = spaghetti.regular_lattice((0, 0, 10, 10), 9, exterior=True)\nntw = spaghetti.Network(in_data=lattice)\nstreet = spaghetti.element_as_gdf(ntw, arcs=True)\nstreet_buffered = geopandas.GeoDataFrame(\n    geopandas.GeoSeries(street[\"geometry\"].buffer(0.5).unary_union),\n    crs=street.crs,\n    columns=[\"geometry\"],\n)\nclient_points = simulated_geo_points(street_buffered, needed=100, seed=5)\nntw.snapobservations(client_points, \"clients\", attribute=True)\nclients_snapped = spaghetti.element_as_gdf(\n    ntw, pp_name=\"clients\", snapped=True\n)\nfacility_points = simulated_geo_points(street_buffered, needed=10, seed=6)\nntw.snapobservations(facility_points, \"facilities\", attribute=True)\nfacilities_snapped = spaghetti.element_as_gdf(\n    ntw, pp_name=\"facilities\", snapped=True\n)\ncost_matrix = ntw.allneighbordistances(\n    sourcepattern=ntw.pointpatterns[\"clients\"],\n    destpattern=ntw.pointpatterns[\"facilities\"],\n)\nnumpy.random.seed(0)\nai = numpy.random.randint(1, 12, 100)\nmclp_from_cost_matrix = MCLP.from_cost_matrix(cost_matrix, ai, 4, p_facilities=4)\nmclp_from_cost_matrix = mclp_from_cost_matrix.solve(solver)\n```\n*see [notebook](https://github.com/pysal/spopt/blob/main/notebooks/mclp.ipynb) for plotting code*\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"docs/_static/images/mclp.png\" height=\"350\" /\u003e\n\u003c/p\u003e\n\n## Examples\nMore examples can be found in the [Tutorials](https://pysal.org/spopt/tutorials.html) section of the documentation.\n- [Max-p-regions problem](https://pysal.org/spopt/notebooks/maxp.html)\n- [Skater](https://pysal.org/spopt/notebooks/skater.html)\n- [Region K means](https://pysal.org/spopt/notebooks/reg-k-means.html)\n- [Facility Location Real World Problem](https://pysal.org/spopt/notebooks/facloc-real-world.html)\n\nAll examples can be run interactively by launching this repository as a [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/pysal/spopt/main).\n\n## Requirements\n- [scipy](http://scipy.github.io/devdocs/)\n- [numpy](https://numpy.org/devdocs/)\n- [pandas](https://pandas.pydata.org/docs/)\n- [networkx](https://networkx.org/)\n- [libpysal](https://pysal.org/libpysal/)\n- [scikit-learn](https://scikit-learn.org/stable/)\n- [geopandas](https://geopandas.org/)\n- [pulp](https://coin-or.github.io/pulp/)\n- [shapely](https://shapely.readthedocs.io/en/stable/)\n- [spaghetti](https://github.com/pysal/spaghetti)\n\n## Installation\nspopt is available on the [Python Package Index](https://pypi.org/). Therefore, you can either install directly with pip from the command line:\n```\n$ pip install -U spopt\n```\nor download the source distribution (.tar.gz) and decompress it to your selected destination. Open a command shell and navigate to the decompressed folder. Type:\n```\n$ pip install .\n```\nYou may also install the latest stable spopt via conda-forge channel by running:\n```\n$ conda install --channel conda-forge spopt\n```\n\n## Related packages\n\n* Region\n* Locate\n  * [`allagash`](https://github.com/apulverizer/allagash)\n  * [`maximum-coverage-location`](https://github.com/cyang-kth/maximum-coverage-location)\n  * [`OR_classic_problem`](https://github.com/khamechian1987/OR_classic_problem)\n  * [`p-center`](https://github.com/antoniomedrano/p-center)\n  * [`pyspatialopt`](https://github.com/apulverizer/pyspatialopt)\n\n## Contribute\n\nPySAL-spopt is under active development and contributors are welcome.\n\nIf you have any suggestions, feature requests, or bug reports, please open new [issues](https://github.com/pysal/spopt/issues) on GitHub. To submit patches, please review [PySAL's documentation for developers](https://pysal.org/docs/devs/), the PySAL [development guidelines](https://github.com/pysal/pysal/wiki), the `spopt` [contributing guidelines](https://github.com/pysal/spopt/blob/main/.github/CONTRIBUTING.md) before  opening a [pull request](https://github.com/pysal/spopt/pulls). Once your changes get merged, you’ll automatically be added to the [Contributors List](https://github.com/pysal/spopt/graphs/contributors).\n\n## Support\nIf you are having trouble, please [create an issue](https://github.com/pysal/spopt/issues), [start a discussion](https://github.com/pysal/spopt/discussions), or talk to us in [PySAL's Discord channel](https://discord.gg/BxFTEPFFZn).\n\n## Code of Conduct\n\nAs a PySAL-federated project, `spopt` follows the [Code of Conduct](https://github.com/pysal/governance/blob/main/conduct/code_of_conduct.rst) under the [PySAL governance model](https://github.com/pysal/governance).\n\n## License\n\nThe project is licensed under the [BSD 3-Clause license](https://github.com/pysal/spopt/blob/main/LICENSE.txt).\n\n## Citation\n\nIf you use PySAL-spopt in a scientific publication, we would appreciate using the following citations:\n\n```\n@misc{spopt2021,\n    author    = {Feng, Xin, and Gaboardi, James D. and Knaap, Elijah and\n                Rey, Sergio J. and Wei, Ran},\n    month     = {jan},\n    year      = {2021},\n    title     = {pysal/spopt},\n    url       = {https://github.com/pysal/spopt},\n    doi       = {10.5281/zenodo.4444156},\n    keywords  = {python,regionalization,spatial-optimization,location-modeling}\n}\n\n@article{spopt2022,\n    author    = {Feng, Xin and Barcelos, Germano and Gaboardi, James D. and\n                Knaap, Elijah and Wei, Ran and Wolf, Levi J. and\n                Zhao, Qunshan and Rey, Sergio J.},\n    year      = {2022},\n    title     = {spopt: a python package for solving spatial optimization problems in PySAL},\n    journal   = {Journal of Open Source Software},\n    publisher = {The Open Journal},\n    volume    = {7},\n    number    = {74},\n    pages     = {3330},\n    url       = {https://doi.org/10.21105/joss.03330},\n    doi       = {10.21105/joss.03330},\n}\n```\n\n## Funding\n\nThis project is/was partially funded through:\n\n[\u003cimg align=\"middle\" src=\"docs/_static/images/nsf_logo.png\" width=\"75\"\u003e](https://www.nsf.gov/index.jsp) National Science Foundation Award #1831615: [RIDIR: Scalable Geospatial Analytics for Social Science Research](https://www.nsf.gov/awardsearch/showAward?AWD_ID=1831615)\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpysal%2Fspopt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpysal%2Fspopt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpysal%2Fspopt/lists"}