The "Hidden Supplier Location" problem typically involves determining the optimal location for a supplier that minimizes the total distance to all customers. The solution depends on the dimensionality of the problem (1D, 2D, etc.) and constraints. Below are key approaches:
- Problem: Customers are positioned at points (x_1, x_2, \dots, xn) on a line. Find (s) minimizing (\sum{i=1}^n |s - x_i|).
- Solution: The median of the customer locations.
- Odd (n): Median is the middle value when sorted.
- Even (n): Any point between the two middle values minimizes the total distance. Typically, the lower median is chosen.
- Algorithm:
- Sort the customer locations.
- If (n) is odd, return the middle element.
- If (n) is even, return the left median (e.g., at index (n//2 - 1)).
Example:
- Customers: ([1, 3, 5, 7])
Sorted: ([1, 3, 5, 7])
Medians: (3) and (5). Both yield total distance (8). Choose (3) (lower median).
2D Case (Customers in a Plane)
- Problem: Customers are at points ((x_i, y_i)). Find (s = (s_x, sy)) minimizing (\sum{i=1}^n \sqrt{(s_x - x_i)^2 + (s_y - y_i)^2}).
- Solution: The geometric median. No closed-form solution; use iterative algorithms.
- Algorithm (Weiszfeld's Algorithm):
- Initialize (s) (e.g., centroid or random point).
- Iterate until convergence: [ s{\text{new}} = \frac{\sum{i=1}^n \frac{(x_i, y_i)}{di}}{\sum{i=1}^n \frac{1}{d_i}}, \quad \text{where} \quad d_i = |s - (x_i, y_i)|_2 \quad (\text{if } d_i > 0). ]
- Handle cases where (s) coincides with a customer (avoid division by zero).
Example:
- Customers: ((0,0), (2,0), (0,2))
Geometric median: ((1, 1)) (total distance (\approx 4.24)).
Key Insights
- 1D vs. 2D:
- 1D: Median (exact, (O(n \log n)) due to sorting).
- 2D: Geometric median (iterative, (O(n)) per iteration).
- Constraints:
- If supplier must be at a customer location, choose the median in 1D or compute distances for all points in 2D.
- If Euclidean distance is replaced with Manhattan distance ((|s_x - x_i| + |s_y - y_i|)), the solution is the median of (x_i) and (y_i) separately.
- Extensions:
- Weighted Customers: Use weighted median (1D) or weighted geometric median (2D).
- Barriers/Obstacles: Use Dijkstra or A* for path-based distances.
When to Use Which Approach
| Scenario | Solution | Complexity |
|---|---|---|
| Customers on a line | Median | (O(n \log n)) |
| Customers in a plane | Geometric median | Iterative ((O(n))/iter) |
| Manhattan distance in 2D | Median of x/y coords | (O(n \log n)) |
| Supplier at customer loc. | Minimize over points | (O(n)) (1D), (O(n^2)) (2D) |
For implementation, use libraries like numpy (1D) or scipy.spatial (2D geometric median). The "hidden" aspect often implies solving with partial information (e.g., querying distances), but the core optimization remains as above.
Request an On-site Audit / Inquiry