项目作者: pysal

项目描述 :
Spatial Optimization
高级语言: Python
项目地址: git://github.com/pysal/spopt.git
创建时间: 2019-03-01T18:56:11Z
项目社区:https://github.com/pysal/spopt

开源协议:BSD 3-Clause "New" or "Revised" License

下载




spopt: Spatial Optimization

Regionalization, facility location, and transportation-oriented modeling

tag
Continuous Integration
codecov
Documentation
License
Ruff
status
DOI
Discord

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), it is under active development for the inclusion of newly proposed models and methods for regionalization, facility location, and transportation-oriented solutions.

Regionalization

  1. import spopt, libpysal, geopandas, numpy
  2. mexico = geopandas.read_file(libpysal.examples.get_path("mexicojoin.shp"))
  3. mexico["count"] = 1
  4. attrs = [f"PCGDP{year}" for year in range(1950, 2010, 10)]
  5. w = libpysal.weights.Queen.from_dataframe(mexico)
  6. mexico["count"], threshold_name, threshold, top_n = 1, "count", 4, 2
  7. numpy.random.seed(123456)
  8. model = spopt.region.MaxPHeuristic(mexico, w, attrs, threshold_name, threshold, top_n)
  9. model.solve()
  10. mexico["maxp_new"] = model.labels_
  11. mexico.plot(column="maxp_new", categorical=True, figsize=(12,8), ec="w");



Locate

  1. from spopt.locate import MCLP
  2. from spopt.locate.util import simulated_geo_points
  3. import numpy, geopandas, pulp, spaghetti
  4. solver = pulp.PULP_CBC_CMD(msg=False, warmStart=True)
  5. lattice = spaghetti.regular_lattice((0, 0, 10, 10), 9, exterior=True)
  6. ntw = spaghetti.Network(in_data=lattice)
  7. street = spaghetti.element_as_gdf(ntw, arcs=True)
  8. street_buffered = geopandas.GeoDataFrame(
  9. geopandas.GeoSeries(street["geometry"].buffer(0.5).unary_union),
  10. crs=street.crs,
  11. columns=["geometry"],
  12. )
  13. client_points = simulated_geo_points(street_buffered, needed=100, seed=5)
  14. ntw.snapobservations(client_points, "clients", attribute=True)
  15. clients_snapped = spaghetti.element_as_gdf(
  16. ntw, pp_name="clients", snapped=True
  17. )
  18. facility_points = simulated_geo_points(street_buffered, needed=10, seed=6)
  19. ntw.snapobservations(facility_points, "facilities", attribute=True)
  20. facilities_snapped = spaghetti.element_as_gdf(
  21. ntw, pp_name="facilities", snapped=True
  22. )
  23. cost_matrix = ntw.allneighbordistances(
  24. sourcepattern=ntw.pointpatterns["clients"],
  25. destpattern=ntw.pointpatterns["facilities"],
  26. )
  27. numpy.random.seed(0)
  28. ai = numpy.random.randint(1, 12, 100)
  29. mclp_from_cost_matrix = MCLP.from_cost_matrix(cost_matrix, ai, 4, p_facilities=4)
  30. mclp_from_cost_matrix = mclp_from_cost_matrix.solve(solver)

see notebook for plotting code



Examples

More examples can be found in the Tutorials section of the documentation.

All examples can be run interactively by launching this repository as a Binder.

Requirements

Installation

spopt is available on the Python Package Index. Therefore, you can either install directly with pip from the command line:

  1. $ 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:

  1. $ pip install .

You may also install the latest stable spopt via conda-forge channel by running:

  1. $ conda install --channel conda-forge spopt

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 on GitHub. To submit patches, please review PySAL’s documentation for developers, the PySAL development guidelines, the spopt contributing guidelines before opening a pull request. Once your changes get merged, you’ll automatically be added to the Contributors List.

Support

If you are having trouble, please create an issue, start a discussion, or talk to us in PySAL’s Discord channel.

Code of Conduct

As a PySAL-federated project, spopt follows the Code of Conduct under the PySAL governance model.

License

The project is licensed under the BSD 3-Clause license.

Citation

If you use PySAL-spopt in a scientific publication, we would appreciate using the following citations:

  1. @misc{spopt2021,
  2. author = {Feng, Xin, and Gaboardi, James D. and Knaap, Elijah and
  3. Rey, Sergio J. and Wei, Ran},
  4. month = {jan},
  5. year = {2021},
  6. title = {pysal/spopt},
  7. url = {https://github.com/pysal/spopt},
  8. doi = {10.5281/zenodo.4444156},
  9. keywords = {python,regionalization,spatial-optimization,location-modeling}
  10. }
  11. @article{spopt2022,
  12. author = {Feng, Xin and Barcelos, Germano and Gaboardi, James D. and
  13. Knaap, Elijah and Wei, Ran and Wolf, Levi J. and
  14. Zhao, Qunshan and Rey, Sergio J.},
  15. year = {2022},
  16. title = {spopt: a python package for solving spatial optimization problems in PySAL},
  17. journal = {Journal of Open Source Software},
  18. publisher = {The Open Journal},
  19. volume = {7},
  20. number = {74},
  21. pages = {3330},
  22. url = {https://doi.org/10.21105/joss.03330},
  23. doi = {10.21105/joss.03330},
  24. }

Funding

This project is/was partially funded through:

National Science Foundation Award #1831615: RIDIR: Scalable Geospatial Analytics for Social Science Research