From 993a264020034277ecb9dde30335449e49754420 Mon Sep 17 00:00:00 2001 From: roope heinonen Date: Fri, 23 Aug 2024 13:19:33 +0300 Subject: [PATCH] removed testing of converting the java lists to python list, should be done in gp2 project codes --- src/r5py/r5/travel_time_matrix_computer.py | 15 +--------- src/r5py/util/custom_cost_conversions.py | 33 ---------------------- 2 files changed, 1 insertion(+), 47 deletions(-) diff --git a/src/r5py/r5/travel_time_matrix_computer.py b/src/r5py/r5/travel_time_matrix_computer.py index 17a7a819..0e2a8608 100644 --- a/src/r5py/r5/travel_time_matrix_computer.py +++ b/src/r5py/r5/travel_time_matrix_computer.py @@ -3,11 +3,8 @@ """Calculate travel times between many origins and destinations.""" import copy -import numpy as np - import pandas -from r5py.util.custom_cost_conversions import convert_java_lists_to_python_in_batches from .base_travel_time_matrix_computer import BaseTravelTimeMatrixComputer from ..util import start_jvm @@ -110,17 +107,7 @@ def _parse_results(self, from_id, results): # add OSM IDs if found in results # osmIdsResults are generated when routing with custom_cost_transport_network if hasattr(results, "osmIdResults") and results.osmIdResults: - # use batching for larger sest to avoid memory issues - # only use batchinkg for large lists - if len(results.osmIdResults) > 1_000: - od_matrix["osm_ids"] = convert_java_lists_to_python_in_batches( - results.osmIdResults - ) - else: - osm_ids_python = [ - np.array(sublist).tolist() for sublist in results.osmIdResults - ] - od_matrix["osm_ids"] = osm_ids_python + od_matrix["osm_ids"] = results.osmIdResults # R5’s NULL value is MAX_INT32 od_matrix = self._fill_nulls(od_matrix) diff --git a/src/r5py/util/custom_cost_conversions.py b/src/r5py/util/custom_cost_conversions.py index 9728dcb1..407a86df 100644 --- a/src/r5py/util/custom_cost_conversions.py +++ b/src/r5py/util/custom_cost_conversions.py @@ -1,8 +1,3 @@ -import os -import math -import concurrent.futures -import numpy as np - import jpype import jpype.imports @@ -146,31 +141,3 @@ def convert_python_custom_costs_to_java_custom_costs( raise CustomCostConversionError( "Failed to convert from python to java for custom cost factors. custom_cost_segment_weight_factors must be provided for custom cost transport network" ) from e - - -def get_dynamic_batch_size(total_paths, min_batch_size=500, max_batch_size=10_000): - if total_paths <= 10_000: - # For small datasets, use a higher batch size - return min(total_paths // 2, max_batch_size) - else: - # For larger datasets, scale batch size logarithmically - batch_size = min_batch_size * math.log10(total_paths / 10_000) - # Ensure the batch size is within the desired range - return int(max(min(batch_size, max_batch_size), min_batch_size)) - - -def convert_sublist_to_python(sublist): - return np.array(sublist).tolist() - - -def convert_java_lists_to_python_in_batches(java_lists): - # Get the number of available CPU cores - batch_size = get_dynamic_batch_size(len(java_lists)) - max_workers = os.cpu_count() - python_lists = [] - for i in range(0, len(java_lists), batch_size): - batch = java_lists[i : i + batch_size] - with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor: - # Convert each batch in parallel using threading - python_lists.extend(executor.map(convert_sublist_to_python, batch)) - return python_lists