Designed to simplify the creation of cost matrices for optimization problems.
Project description
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cost_matrix-0.1.1.tar.gz
.
File metadata
- Download URL: cost_matrix-0.1.1.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-35-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6290518812b1cf0887109ef79c1e94e6cbc34061a0f9c008261cc7df173b08d |
|
MD5 | 64e7cb2e3424a8b0df09721b2da69bd9 |
|
BLAKE2b-256 | e56d7e300359c4fc575fcd553409f11eceb8d602e405f7d0d4bd205feb22d86b |
File details
Details for the file cost_matrix-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: cost_matrix-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-35-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6725fe16b0605aa0116f0f0cfb71e8e7ff384beaa65a06b7636c65a46b54cba8 |
|
MD5 | cc3ca8104cf0ba697fa69a89bb564ca5 |
|
BLAKE2b-256 | e4b2b4f9941c2b8fdb27e7a4260bbf13f31d670eb834802089300a2b69dbb5f7 |