cost-matrix


Namecost-matrix JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryDesigned to simplify the creation of cost matrices for optimization problems.
upload_time2024-06-03 19:18:32
maintainerNone
docs_urlNone
authorLuan
requires_python<3.13,>=3.9
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # cost-matrix

`cost-matrix` is a Python package designed to simplify the creation of cost matrices for optimization problems. Whether you're dealing with distance calculations or travel durations, `cost-matrix` provides a robust set of tools to meet your needs.

This package is invaluable for anyone working on optimization problems, data analysis, or transportation planning. With its diverse range of distance calculation methods and integration with OSRM, it provides a comprehensive solution for generating cost matrices efficiently.

## Key Features:
- **Manhattan**: Compute distances based on orthogonal paths.
- **Euclidean**: Calculate straight-line distances in a Cartesian plane.
- **Spherical**: Calculate distances between geographical points considering the Earth's curvature.
- **OSRM**: Integrate with the Open Source Routing Machine (OSRM) to obtain travel duration or distance matrices.

## Installation

To install the `cost-matrix` package, you can use pip:

```sh
pip install cost-matrix
```


## Example Usage:
```python
import numpy as np
import cost_matrix

# Define source and destination coordinates (latitude, longitude)
sources = np.array([[37.7749, -122.4194], [34.0522, -118.2437]])  # San Francisco, Los Angeles
destinations = np.array([[40.7128, -74.0060], [51.5074, -0.1278]])  # New York, London

# Calculate Manhattan distance matrix
manhattan_matrix = cost_matrix.manhattan(sources, destinations)
print(manhattan_matrix)

# Calculate Euclidean distance matrix
euclidean_matrix = cost_matrix.euclidean(sources, destinations)
print(euclidean_matrix)

# Calculate Spherical distance matrix
spherical_matrix = cost_matrix.spherical(sources, destinations)
print(spherical_matrix)

# Calculate OSRM travel distances matrix
osrm_distance_matrix = cost_matrix.osrm(sources, destinations)
print(osrm_distance_matrix)

# Calculate OSRM travel durations matrix
osrm_duration_matrix = cost_matrix.osrm(
    sources, 
    destinations, 
    cost_type="durations", 
    server_address="http://localhost:5000",
    batch_size=250
)
print(osrm_duration_matrix)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "cost-matrix",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<3.13,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Luan",
    "author_email": "llvdmoraes@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/06/4a/216bedb6735d47d7c6da75acc2833c33a9ad2ca845cfb3ef6bcb145b94c7/cost_matrix-0.1.0.tar.gz",
    "platform": null,
    "description": "# cost-matrix\n\n`cost-matrix` is a Python package designed to simplify the creation of cost matrices for optimization problems. Whether you're dealing with distance calculations or travel durations, `cost-matrix` provides a robust set of tools to meet your needs.\n\nThis package is invaluable for anyone working on optimization problems, data analysis, or transportation planning. With its diverse range of distance calculation methods and integration with OSRM, it provides a comprehensive solution for generating cost matrices efficiently.\n\n## Key Features:\n- **Manhattan**: Compute distances based on orthogonal paths.\n- **Euclidean**: Calculate straight-line distances in a Cartesian plane.\n- **Spherical**: Calculate distances between geographical points considering the Earth's curvature.\n- **OSRM**: Integrate with the Open Source Routing Machine (OSRM) to obtain travel duration or distance matrices.\n\n## Installation\n\nTo install the `cost-matrix` package, you can use pip:\n\n```sh\npip install cost-matrix\n```\n\n\n## Example Usage:\n```python\nimport numpy as np\nimport cost_matrix\n\n# Define source and destination coordinates (latitude, longitude)\nsources = np.array([[37.7749, -122.4194], [34.0522, -118.2437]])  # San Francisco, Los Angeles\ndestinations = np.array([[40.7128, -74.0060], [51.5074, -0.1278]])  # New York, London\n\n# Calculate Manhattan distance matrix\nmanhattan_matrix = cost_matrix.manhattan(sources, destinations)\nprint(manhattan_matrix)\n\n# Calculate Euclidean distance matrix\neuclidean_matrix = cost_matrix.euclidean(sources, destinations)\nprint(euclidean_matrix)\n\n# Calculate Spherical distance matrix\nspherical_matrix = cost_matrix.spherical(sources, destinations)\nprint(spherical_matrix)\n\n# Calculate OSRM travel distances matrix\nosrm_distance_matrix = cost_matrix.osrm(sources, destinations)\nprint(osrm_distance_matrix)\n\n# Calculate OSRM travel durations matrix\nosrm_duration_matrix = cost_matrix.osrm(\n    sources, \n    destinations, \n    cost_type=\"durations\", \n    server_address=\"http://localhost:5000\",\n    batch_size=250\n)\nprint(osrm_duration_matrix)\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Designed to simplify the creation of cost matrices for optimization problems.",
    "version": "0.1.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a5582b622e4413e17ee903129071f36c6a560cf4016f89541f1efed817c71995",
                "md5": "91c8de85b9733c730dcbed4c567b5747",
                "sha256": "252c19ba595581cde04371058bcbff5f879d26ce51a78b1a0fe09b347e8e4e35"
            },
            "downloads": -1,
            "filename": "cost_matrix-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "91c8de85b9733c730dcbed4c567b5747",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.13,>=3.9",
            "size": 4711,
            "upload_time": "2024-06-03T19:18:31",
            "upload_time_iso_8601": "2024-06-03T19:18:31.044715Z",
            "url": "https://files.pythonhosted.org/packages/a5/58/2b622e4413e17ee903129071f36c6a560cf4016f89541f1efed817c71995/cost_matrix-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "064a216bedb6735d47d7c6da75acc2833c33a9ad2ca845cfb3ef6bcb145b94c7",
                "md5": "4efa31c13894d81500ffa34dc7846f3e",
                "sha256": "cb0a51467448e158a399e7f8da084efd0d3ed5e08aaf167d25b4a0aad9d96966"
            },
            "downloads": -1,
            "filename": "cost_matrix-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4efa31c13894d81500ffa34dc7846f3e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.13,>=3.9",
            "size": 3593,
            "upload_time": "2024-06-03T19:18:32",
            "upload_time_iso_8601": "2024-06-03T19:18:32.569190Z",
            "url": "https://files.pythonhosted.org/packages/06/4a/216bedb6735d47d7c6da75acc2833c33a9ad2ca845cfb3ef6bcb145b94c7/cost_matrix-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-03 19:18:32",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "cost-matrix"
}
        
Elapsed time: 0.23814s