cost-matrix 0.1.0__py3-none-any.whl → 0.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,28 @@
1
1
  import numpy as np
2
2
 
3
3
 
4
- def euclidean(sources: np.ndarray, destinations: np.ndarray) -> np.ndarray:
5
- return np.linalg.norm(sources - destinations, axis=1)
4
+ def euclidean(sources, destinations):
5
+ """
6
+ Calculate the Euclidean distance matrix between source and destination points.
7
+
8
+ Parameters
9
+ ----------
10
+ sources : np.ndarray
11
+ Array of shape (n, d) containing the source points.
12
+ destinations : np.ndarray
13
+ Array of shape (m, d) containing the destination points.
14
+
15
+ Returns
16
+ -------
17
+ np.ndarray
18
+ Euclidean distance matrix of shape (n, m).
19
+ """
20
+ # Expand dimensions to enable broadcasting
21
+ sources_expanded = sources[:, np.newaxis, :]
22
+ destinations_expanded = destinations[np.newaxis, :, :]
23
+
24
+ # Compute differences along the last dimension
25
+ differences = sources_expanded - destinations_expanded
26
+
27
+ # Compute Euclidean distances using norm along the last dimension
28
+ return np.linalg.norm(differences, axis=2)
@@ -2,4 +2,28 @@ import numpy as np
2
2
 
3
3
 
4
4
  def manhattan(sources: np.ndarray, destinations: np.ndarray) -> np.ndarray:
5
- return np.sum(np.abs(sources - destinations), axis=1)
5
+ """
6
+ Compute the Manhattan distance matrix between source and destination points.
7
+
8
+ Parameters
9
+ ----------
10
+ sources : np.ndarray
11
+ Array of shape (n, d) containing the source points.
12
+ destinations : np.ndarray
13
+ Array of shape (m, d) containing the destination points.
14
+
15
+ Returns
16
+ -------
17
+ np.ndarray
18
+ Manhattan distance matrix of shape (n, m).
19
+ """
20
+ # Expand dimensions to enable broadcasting
21
+ sources_expanded = sources[:, np.newaxis, :]
22
+ destinations_expanded = destinations[np.newaxis, :, :]
23
+
24
+ # Compute absolute differences along the last dimension
25
+ differences = np.abs(sources_expanded - destinations_expanded)
26
+
27
+ # Sum absolute differences along the last dimension to get
28
+ # Manhattan distance
29
+ return np.sum(differences, axis=2)
@@ -11,7 +11,28 @@ def osrm(
11
11
  batch_size: int = 150,
12
12
  cost_type: str = "distances",
13
13
  ) -> np.ndarray:
14
- """Compute the OSRM cost matrix between sources and destinations"""
14
+ """
15
+ Compute the OSRM cost matrix between sources and destinations
16
+
17
+ Parameters
18
+ ----------
19
+ sources : np.ndarray
20
+ Array of shape (n, d) containing the source points.
21
+ destinations : np.ndarray
22
+ Array of shape (m, d) containing the destination points.
23
+ server_address : str
24
+ Address of the OSRM server. Default is "http://router.project-osrm.org".
25
+ batch_size : int
26
+ Number of points to send in each request. Default is 150.
27
+ cost_type : str
28
+ Type of cost to be computed. Default is "distances". Options are
29
+ "distances" and "durations".
30
+
31
+ Returns
32
+ -------
33
+ np.ndarray
34
+ OSRM cost matrix of shape (n, m).
35
+ """
15
36
 
16
37
  num_sources = sources.shape[0]
17
38
  num_destinations = destinations.shape[0]
@@ -4,7 +4,21 @@ EARTH_RADIUS_METERS = 6371000
4
4
 
5
5
 
6
6
  def spherical(sources: np.ndarray, destinations: np.ndarray) -> np.ndarray:
7
- """Distance matrix using the Spherical distance"""
7
+ """
8
+ Compute the distance matrix using the Spherical distance]
9
+
10
+ Parameters
11
+ ----------
12
+ sources : np.ndarray
13
+ Array of shape (n, d) containing the source points.
14
+ destinations : np.ndarray
15
+ Array of shape (m, d) containing the destination points.
16
+
17
+ Returns
18
+ -------
19
+ np.ndarray
20
+ Spherical distance matrix of shape (n, m).
21
+ """
8
22
 
9
23
  sources_rad = np.radians(sources)
10
24
  destinations_rad = np.radians(destinations)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cost-matrix
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Designed to simplify the creation of cost matrices for optimization problems.
5
5
  Author: Luan
6
6
  Author-email: llvdmoraes@gmail.com
@@ -69,4 +69,5 @@ osrm_duration_matrix = cost_matrix.osrm(
69
69
  batch_size=250
70
70
  )
71
71
  print(osrm_duration_matrix)
72
+ ```
72
73
 
@@ -0,0 +1,8 @@
1
+ cost_matrix/__init__.py,sha256=9EaPsXe0SIuym34-CPmzUPSGJuBd2AkQZHqjcwlUywE,202
2
+ cost_matrix/euclidean_matrix.py,sha256=PiOJFjalkvk1p4ktcCvFD7EeXswvsnm8f-oze1gFRlk,844
3
+ cost_matrix/manhattan_matrix.py,sha256=OgOepYRfskarZmNNarl58YqNRw7WXYnjztWV2BbjGBI,907
4
+ cost_matrix/osrm_matrix.py,sha256=5cCNCko-0f2LENXv2HhOD_o9G6JKHLFx19AjVxrpaQI,4953
5
+ cost_matrix/spherical_matrix.py,sha256=9_y5XCpdAEiWcvljPX7kFYSUt0nU3Gq4DOwr7LlbhQY,1271
6
+ cost_matrix-0.1.1.dist-info/METADATA,sha256=88TXrl5feVI1544bxFTYWTPfybVNfpHCM1O7e6RXe2I,2680
7
+ cost_matrix-0.1.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
8
+ cost_matrix-0.1.1.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- cost_matrix/__init__.py,sha256=9EaPsXe0SIuym34-CPmzUPSGJuBd2AkQZHqjcwlUywE,202
2
- cost_matrix/euclidean_matrix.py,sha256=a8uLh0COVb5duaKV6DMfG9HklkJX2dOARKfnnWxLxsc,155
3
- cost_matrix/manhattan_matrix.py,sha256=bWTTiIgvb0PDWSdfCXuffHEIgb9nNMb4w7Qwhe3EbaQ,155
4
- cost_matrix/osrm_matrix.py,sha256=VuuoQVRGxMjoN_eUfs9yur9lwINg8JZxB3SX-6cvBFk,4327
5
- cost_matrix/spherical_matrix.py,sha256=SxaihjkKyrp0den5w-VsimGcjjQEi-q-_cvxeTM3xyY,946
6
- cost_matrix-0.1.0.dist-info/METADATA,sha256=4TVrFT0TlklV7jcvRAJarKqi-TE2_TPMtSJJtVZTmIQ,2676
7
- cost_matrix-0.1.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
8
- cost_matrix-0.1.0.dist-info/RECORD,,