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)

GitHub

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.2.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

cost_matrix-0.2.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file cost_matrix-0.2.0.tar.gz.

File metadata

  • Download URL: cost_matrix-0.2.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.4 Linux/6.8.0-60-generic

File hashes

Hashes for cost_matrix-0.2.0.tar.gz
Algorithm Hash digest
SHA256 48f2bf86c012f8d8f09697ec3c9739ab28af3c9fbf86dc4feac2606d8d8dfae7
MD5 dd47343ad3b88e4b0cbe8122a69f9f90
BLAKE2b-256 823ef789ae00f47bc1f09ac6c58cfb3a94c9ff66e3787304802f1855192bb748

See more details on using hashes here.

File details

Details for the file cost_matrix-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: cost_matrix-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.4 Linux/6.8.0-60-generic

File hashes

Hashes for cost_matrix-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 72d97a01a4155c06a891fecfdc1342dbe5e253a8c4155887dff54eb47c4b8c8f
MD5 6f5037789b136e0d04b2b6caf2f67c33
BLAKE2b-256 b4025561548af7402328ad533bb803faf0d4e59c74324d24e6d0037e9e505957

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