Skip to main content

A python project which finds the optimal N locations in a given area according to the given location inputs. This package can be used for business or individual needs.

Project description

What is it?

The OptimalLoc package is a Python library designed to provide a solution for finding optimal locations based on various needs such as transportation and logistics, urban planning, retail, healthcare, and emergency services. The package utilizes a mixed integer linear optimization algorithm to calculate the optimal locations based on input demands and a specified number of location points.

Main Features

  • Hexagon mapping: The package uses the Uber h3 library to map locations onto hexagons on a map. This allows for efficient optimization calculations by reducing the number of data points involved.
  • Event frequency calculation: The package calculates the frequency of events in each hexagonal region based on the provided input data. This information is used in the optimization algorithm to determine the optimal locations.
  • Distance data management: The package includes functionality to create and read distance data between pairs of hexagonal regions. This data can be stored in a database, such as MongoDB, or as a dataframe.
  • Optimization algorithm: The package utilizes a mixed integer linear optimization algorithm, implemented using the pulp library, to determine the optimal locations based on the given demands and the desired number of location points.
  • Visualization: The package provides a frontend app built with Streamlit to visualize the optimal results on a map. Users can interact with the app to analyze and understand the optimal locations.

Purpose of the Package

The OptimalLoc package aims to assist various industries, including logistics, retail, and emergency services, in optimizing their operations by identifying the best locations for their needs. By finding the optimal locations, organizations can improve efficiency, reduce costs, and enhance their overall performance.

Getting Started

Installation

To install the OptimalLoc package, you can use pip, the package installer for Python:

pip install optimal-loc

Usage

To use the OptimalLoc package for finding optimal locations, follow the steps below:

  1. Import the OptimalLoc class from the package:

    import optimal_loc
    
  2. Create an instance of the OptimalLoc class:

    sol = optimal_loc.OptimalLoc()
    
  3. Prepare your input data:

    • Load your data into a pandas DataFrame, ensuring it includes the required columns for latitude and longitude information.
    • Clean and preprocess the data as needed.
  4. Create hexagon distance data:

    • Call the create_hexagon_distance_data method of the OptimalLoc instance, providing your preprocessed data and specifying the hexagon size ('small', 'medium', or 'big').
    • This step will calculate the hexagons on which the points in your data fall and create the necessary data to calculate distances between these hexagons.

    Example:

    sol.create_hexagon_distance_data(data, 'medium')
    
  5. Read the distances:

    • If you have a large distance dataset, you can store it in a MongoDB database and read it using the read_distances_from_mongodb method.
    • Alternatively, you can directly read the distance data from a dataframe using the read_distances method.

    Example (reading from MongoDB):

    sol.read_distances_from_mongodb(mongo_client=MongoClient,
                                    mongo_database_name="db_name",
                                    mongo_collection_name="collection_name")
    

    Example (reading from a dataframe):

    sol.read_distances(read_from_dataframe=True, distance_dataframe=distance_data)
    
  6. Calculate optimal locations:

    • Call the calculate_optimal_locations method of the OptimalLoc instance, specifying the number of desired optimal locations and providing the distance and frequency data.
    • This step will run the mixed integer linear optimization algorithm and calculate the optimal points or hexagon regions.

    Example:

    sol.calculate_optimal_locations(number_of_loc=5)
    
  7. Access the results:

    • After running the optimization algorithm, the optimal and supply data will be available in the optimal_data and supply_data attributes of the OptimalLoc instance, respectively.

    Example:

    optimal_results = sol.optimal_data
    supply_results = sol.supply_data
    
  8. Visualize the results:

    • To visualize the optimal results on a map, you can call the visualize function from the optimal_loc.bash_command module.

    Example:

    optimal_loc.visualize()
    
  9. Explore and analyze the optimal locations using the provided Streamlit frontend app.

    Example:

    • Open the app in a web browser using the displayed URL.
    • Interact with the app to analyze the optimal locations visually and perform further analyses.

By following these steps, you can utilize the OptimalLoc package to find optimal locations for various applications, such as transportation and logistics, urban planning, retail, healthcare, and emergency services.

Contribution

Contributions are welcome. Notice a bug let us know.

Author

  • Main Maintainer: Sinan Demirhan (SDemirhan)

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

optimal_loc-0.1.7.tar.gz (123.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

optimal_loc-0.1.7-py3-none-any.whl (122.4 kB view details)

Uploaded Python 3

File details

Details for the file optimal_loc-0.1.7.tar.gz.

File metadata

  • Download URL: optimal_loc-0.1.7.tar.gz
  • Upload date:
  • Size: 123.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.7.13 Darwin/21.6.0

File hashes

Hashes for optimal_loc-0.1.7.tar.gz
Algorithm Hash digest
SHA256 5ae0513f3bd5330f8a00d338d6b9149d8b2294477e90fdb52d9e3781c047685a
MD5 e28bba154ae0f62da7e0eadbc1fa24ea
BLAKE2b-256 b748c22e483782e4b37b8e18a572afff42a1f0ad04cfc46aa584bcc96a510b70

See more details on using hashes here.

File details

Details for the file optimal_loc-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: optimal_loc-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 122.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.7.13 Darwin/21.6.0

File hashes

Hashes for optimal_loc-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 ea3508b29fd68b8f7e2485c7089ac94e4144fd5b9cc01cd895e0063e52f0f656
MD5 e1b31c47bbc7195d131d70f810257cd5
BLAKE2b-256 7574ef441e8cdbe4626342b974d084d71b1c38b9cbd996fe1c117cb3518b7c69

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page