Name | spopt JSON |
Version |
0.6.1
JSON |
| download |
home_page | None |
Summary | Spatial Optimization in PySAL |
upload_time | 2024-06-20 13:41:41 |
maintainer | spopt contributors |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | BSD 3-Clause |
keywords |
spatial
optimization
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
<p align="center">
<img src="docs/_static/images/pysal_banner.svg" width="370" height="200" />
</p>
# `spopt`: Spatial Optimization
#### Regionalization, facility location, and transportation-oriented modeling
![tag](https://img.shields.io/github/v/release/pysal/spopt?include_prereleases&sort=semver)
[![Continuous Integration](https://github.com/pysal/spopt/actions/workflows/testing.yml/badge.svg)](https://github.com/pysal/spopt/actions/workflows/testing.yml)
[![codecov](https://codecov.io/gh/pysal/spopt/branch/main/graph/badge.svg)](https://codecov.io/gh/pysal/spopt)
[![Documentation](https://img.shields.io/static/v1.svg?label=docs&message=current&color=9cf)](http://pysal.org/spopt/)
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
[![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)
[![status](https://joss.theoj.org/papers/1413cf2c0cf3c561386949f2e1208563/status.svg)](https://joss.theoj.org/papers/1413cf2c0cf3c561386949f2e1208563)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4444156.svg)](https://doi.org/10.5281/zenodo.4444156)
[![Discord](https://img.shields.io/badge/Discord-join%20chat-7289da?style=flat&logo=discord&logoColor=cccccc&link=https://discord.gg/BxFTEPFFZn)](https://discord.gg/BxFTEPFFZn)
Spopt 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.
### Regionalization
```python
import spopt, libpysal, geopandas, numpy
mexico = geopandas.read_file(libpysal.examples.get_path("mexicojoin.shp"))
mexico["count"] = 1
attrs = [f"PCGDP{year}" for year in range(1950, 2010, 10)]
w = libpysal.weights.Queen.from_dataframe(mexico)
mexico["count"], threshold_name, threshold, top_n = 1, "count", 4, 2
numpy.random.seed(123456)
model = spopt.region.MaxPHeuristic(mexico, w, attrs, threshold_name, threshold, top_n)
model.solve()
mexico["maxp_new"] = model.labels_
mexico.plot(column="maxp_new", categorical=True, figsize=(12,8), ec="w");
```
<p align="center">
<img src="docs/_static/images/maxp.svg" height="350" />
</p>
### Locate
```python
from spopt.locate import MCLP
from spopt.locate.util import simulated_geo_points
import numpy, geopandas, pulp, spaghetti
solver = pulp.PULP_CBC_CMD(msg=False, warmStart=True)
lattice = spaghetti.regular_lattice((0, 0, 10, 10), 9, exterior=True)
ntw = spaghetti.Network(in_data=lattice)
street = spaghetti.element_as_gdf(ntw, arcs=True)
street_buffered = geopandas.GeoDataFrame(
geopandas.GeoSeries(street["geometry"].buffer(0.5).unary_union),
crs=street.crs,
columns=["geometry"],
)
client_points = simulated_geo_points(street_buffered, needed=100, seed=5)
ntw.snapobservations(client_points, "clients", attribute=True)
clients_snapped = spaghetti.element_as_gdf(
ntw, pp_name="clients", snapped=True
)
facility_points = simulated_geo_points(street_buffered, needed=10, seed=6)
ntw.snapobservations(facility_points, "facilities", attribute=True)
facilities_snapped = spaghetti.element_as_gdf(
ntw, pp_name="facilities", snapped=True
)
cost_matrix = ntw.allneighbordistances(
sourcepattern=ntw.pointpatterns["clients"],
destpattern=ntw.pointpatterns["facilities"],
)
numpy.random.seed(0)
ai = numpy.random.randint(1, 12, 100)
mclp_from_cost_matrix = MCLP.from_cost_matrix(cost_matrix, ai, 4, p_facilities=4)
mclp_from_cost_matrix = mclp_from_cost_matrix.solve(solver)
```
*see [notebook](https://github.com/pysal/spopt/blob/main/notebooks/mclp.ipynb) for plotting code*
<p align="center">
<img src="docs/_static/images/mclp.png" height="350" />
</p>
## Examples
More examples can be found in the [Tutorials](https://pysal.org/spopt/tutorials.html) section of the documentation.
- [Max-p-regions problem](https://pysal.org/spopt/notebooks/maxp.html)
- [Skater](https://pysal.org/spopt/notebooks/skater.html)
- [Region K means](https://pysal.org/spopt/notebooks/reg-k-means.html)
- [Facility Location Real World Problem](https://pysal.org/spopt/notebooks/facloc-real-world.html)
All 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).
## Requirements
- [scipy](http://scipy.github.io/devdocs/)
- [numpy](https://numpy.org/devdocs/)
- [pandas](https://pandas.pydata.org/docs/)
- [networkx](https://networkx.org/)
- [libpysal](https://pysal.org/libpysal/)
- [scikit-learn](https://scikit-learn.org/stable/)
- [geopandas](https://geopandas.org/)
- [pulp](https://coin-or.github.io/pulp/)
- [shapely](https://shapely.readthedocs.io/en/stable/)
- [spaghetti](https://github.com/pysal/spaghetti)
## Installation
spopt is available on the [Python Package Index](https://pypi.org/). Therefore, you can either install directly with pip from the command line:
```
$ pip install -U spopt
```
or download the source distribution (.tar.gz) and decompress it to your selected destination. Open a command shell and navigate to the decompressed folder. Type:
```
$ pip install .
```
You may also install the latest stable spopt via conda-forge channel by running:
```
$ conda install --channel conda-forge spopt
```
## Related packages
* Region
* Locate
* [`allagash`](https://github.com/apulverizer/allagash)
* [`maximum-coverage-location`](https://github.com/cyang-kth/maximum-coverage-location)
* [`OR_classic_problem`](https://github.com/khamechian1987/OR_classic_problem)
* [`p-center`](https://github.com/antoniomedrano/p-center)
* [`pyspatialopt`](https://github.com/apulverizer/pyspatialopt)
## Contribute
PySAL-spopt is under active development and contributors are welcome.
If 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).
## Support
If 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).
## Code of Conduct
As 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).
## License
The project is licensed under the [BSD 3-Clause license](https://github.com/pysal/spopt/blob/main/LICENSE.txt).
## Citation
If you use PySAL-spopt in a scientific publication, we would appreciate using the following citations:
```
@misc{spopt2021,
author = {Feng, Xin, and Gaboardi, James D. and Knaap, Elijah and
Rey, Sergio J. and Wei, Ran},
month = {jan},
year = {2021},
title = {pysal/spopt},
url = {https://github.com/pysal/spopt},
doi = {10.5281/zenodo.4444156},
keywords = {python,regionalization,spatial-optimization,location-modeling}
}
@article{spopt2022,
author = {Feng, Xin and Barcelos, Germano and Gaboardi, James D. and
Knaap, Elijah and Wei, Ran and Wolf, Levi J. and
Zhao, Qunshan and Rey, Sergio J.},
year = {2022},
title = {spopt: a python package for solving spatial optimization problems in PySAL},
journal = {Journal of Open Source Software},
publisher = {The Open Journal},
volume = {7},
number = {74},
pages = {3330},
url = {https://doi.org/10.21105/joss.03330},
doi = {10.21105/joss.03330},
}
```
## Funding
This project is/was partially funded through:
[<img align="middle" src="docs/_static/images/nsf_logo.png" width="75">](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)
Raw data
{
"_id": null,
"home_page": null,
"name": "spopt",
"maintainer": "spopt contributors",
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "spatial optimization",
"author": null,
"author_email": "\"James D. Gaboardi\" <jgaboardi@gmail.com>, Xin Feng <xin.feng@ucr.edu>",
"download_url": "https://files.pythonhosted.org/packages/57/0a/a4e5a26d650a54da009f772a9cd57c03300285130d52bbb640bf26611dcb/spopt-0.6.1.tar.gz",
"platform": null,
"description": "\n<p align=\"center\">\n<img src=\"docs/_static/images/pysal_banner.svg\" width=\"370\" height=\"200\" />\n</p>\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&sort=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&message=current&color=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&logo=discord&logoColor=cccccc&link=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<p align=\"center\">\n<img src=\"docs/_static/images/maxp.svg\" height=\"350\" />\n</p>\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<p align=\"center\">\n<img src=\"docs/_static/images/mclp.png\" height=\"350\" />\n</p>\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\u2019ll 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[<img align=\"middle\" src=\"docs/_static/images/nsf_logo.png\" width=\"75\">](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",
"bugtrack_url": null,
"license": "BSD 3-Clause",
"summary": "Spatial Optimization in PySAL",
"version": "0.6.1",
"project_urls": {
"Home": "https://pysal.org/spopt/",
"Repository": "https://github.com/pysal/spopt"
},
"split_keywords": [
"spatial",
"optimization"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ee5908e1796f4dda22a780254ad24c525dd4641daee86a3f5212c807b4a55c4a",
"md5": "5c38ec094e3b60279ed47cd26cafeddf",
"sha256": "1e05fa545a78fca501556e3f6921ada3f95f6319df7d99bb24ce635fff3d1be8"
},
"downloads": -1,
"filename": "spopt-0.6.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5c38ec094e3b60279ed47cd26cafeddf",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 243143,
"upload_time": "2024-06-20T13:41:39",
"upload_time_iso_8601": "2024-06-20T13:41:39.817297Z",
"url": "https://files.pythonhosted.org/packages/ee/59/08e1796f4dda22a780254ad24c525dd4641daee86a3f5212c807b4a55c4a/spopt-0.6.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "570aa4e5a26d650a54da009f772a9cd57c03300285130d52bbb640bf26611dcb",
"md5": "5931e8f18373f5a4e9583fb9e220261c",
"sha256": "22fd867543cd04325d11d7d75a68dcdf8fba4c2c2fe959ba60ccef13dc54acf7"
},
"downloads": -1,
"filename": "spopt-0.6.1.tar.gz",
"has_sig": false,
"md5_digest": "5931e8f18373f5a4e9583fb9e220261c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 30537353,
"upload_time": "2024-06-20T13:41:41",
"upload_time_iso_8601": "2024-06-20T13:41:41.731044Z",
"url": "https://files.pythonhosted.org/packages/57/0a/a4e5a26d650a54da009f772a9cd57c03300285130d52bbb640bf26611dcb/spopt-0.6.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-20 13:41:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pysal",
"github_project": "spopt",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "spopt"
}