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:
pip install cost-matrix
Example Usage:
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)
GitHub
Metadata
Release files for cost-matrix 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cost_matrix-0.2.0.tar.gz | 4.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cost_matrix-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.7 kB
Release files / cost_matrix-0.2.0.tar.gz
| Download URL | cost_matrix-0.2.0.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
48f2bf86c012f8d8f09697ec3c9739ab28af3c9fbf86dc4feac2606d8d8dfae7
|
|
BLAKE2b-256 checksum How to use checksums |
823ef789ae00f47bc1f09ac6c58cfb3a94c9ff66e3787304802f1855192bb748
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.4 Linux/6.8.0-60-generic
|
Release files / cost_matrix-0.2.0-py3-none-any.whl
| Download URL | cost_matrix-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
72d97a01a4155c06a891fecfdc1342dbe5e253a8c4155887dff54eb47c4b8c8f
|
|
BLAKE2b-256 checksum How to use checksums |
b4025561548af7402328ad533bb803faf0d4e59c74324d24e6d0037e9e505957
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.4 Linux/6.8.0-60-generic
|