Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cost_matrix-0.1.0.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

cost_matrix-0.1.0-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

Supported by

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