Why Weight Customer Locations?
A facility may need to serve customers who are not equally important to the decision. A hospital might give greater weight to locations with more residents; a distribution center might use demand forecasts as weights. If the objective penalizes the squared distance to each customer location, the optimal facility location is a weighted average of those locations.
The formula is simple, but its meaning depends on the objective and its assumptions. In particular, it applies to an unconstrained facility location problem with positive weights and squared Euclidean distances. We will derive the formula, prove that it gives the unique global minimum, and check it in several examples.
Model and Definition
Suppose there are \(n\) customer locations in \(d\)-dimensional Euclidean space. Write the location of customer \(i\) as the vector \(\mathbf{p}_i\in\mathbb{R}^d\), and let \(w_i>0\) be that customer's weight. The facility location is a vector \(\mathbf{x}\in\mathbb{R}^d\). The squared Euclidean distance from the facility to customer \(i\) is \(\|\mathbf{x}-\mathbf{p}_i\|^2\).
A larger weight makes a customer's squared distance contribute more to the objective. Multiplying every weight by the same positive constant changes the value of \(J\), but not the minimizing location. If the weights are relative importance scores, they need not add to one.
For planar locations, write \(\mathbf{p}_i=(a_i,b_i)\) and \(\mathbf{x}=(x,y)\). Then the objective is \(\sum_{i=1}^{n}w_i\big((x-a_i)^2+(y-b_i)^2\big)\). The weighted centroid is formed by taking a weighted average of each coordinate separately.
Why the Weighted Centroid Minimizes the Objective
Let \(W=\sum_{i=1}^{n}w_i\), so \(W>0\), and define \(\mathbf{c}=(\sum_{i=1}^{n}w_i\mathbf{p}_i)/W\). The key fact is that the weighted deviations from \(\mathbf{c}\) sum to zero:
For any proposed facility location \(\mathbf{x}\), write \(\mathbf{x}-\mathbf{p}_i=(\mathbf{x}-\mathbf{c})+(\mathbf{c}-\mathbf{p}_i)\) and expand the squared norm using the dot product. Summing the result separates the objective into a term depending on \(\mathbf{x}\) and a term independent of it.
The middle term vanishes because \(\sum_i w_i(\mathbf{c}-\mathbf{p}_i)=\mathbf{0}\). Since \(W>0\), the term \(W\|\mathbf{x}-\mathbf{c}\|^2\) is nonnegative, and it is zero exactly when \(\mathbf{x}=\mathbf{c}\). Thus \(J(\mathbf{x})\geq J(\mathbf{c})\) for every \(\mathbf{x}\), with equality only at \(\mathbf{c}\). This proves that the weighted centroid is the unique global minimum, not merely a candidate found by solving a stationarity equation.
The same result can be seen by differentiating. In coordinates, differentiating with respect to each coordinate gives \(\nabla J(\mathbf{x})=2\sum_i w_i(\mathbf{x}-\mathbf{p}_i)=2(W\mathbf{x}-\sum_i w_i\mathbf{p}_i)\). Setting the gradient equal to zero gives \(\mathbf{x}=\mathbf{c}\). The sum-of-squares identity above supplies the additional global and uniqueness check.
Worked Example: Three Customers in a Plane
Worked Example: Three Customers in a Plane
Three customers are at \((0,0)\), \((6,0)\), and \((0,4)\), with weights \(1\), \(2\), and \(3\), respectively. Find the facility location minimizing the weighted sum of squared distances, and calculate the minimum objective value.
The total weight is \(W=1+2+3=6\). The weighted coordinate sums are \(1(0)+2(6)+3(0)=12\) in the first coordinate and \(1(0)+2(0)+3(4)=12\) in the second. Therefore, the weighted centroid is \((12/6,12/6)=(2,2)\).
At \((2,2)\), the squared distances to the three customers are \(2^2+2^2=8\), \((-4)^2+2^2=20\), and \(2^2+(-2)^2=8\). After applying the weights, the objective is \(1(8)+2(20)+3(8)=8+40+24=72\).
To check the minimizing condition, the weighted coordinate sums are both \(12\), and \(W(2,2)=(12,12)\). Hence \(\nabla J(2,2)=2((12,12)-(12,12))=(0,0)\). The sum-of-squares identity proves that this stationary location is the unique global minimum, with objective value \(72\).
Worked Example: Checking the Identity at Another Location
Worked Example: Checking the Identity at Another Location
Consider locations \((1,2)\), \((3,0)\), and \((5,4)\), with weights \(1\), \(2\), and \(1\). First calculate the weighted centroid: the total weight is \(W=1+2+1=4\), the weighted first-coordinate sum is \(1(1)+2(3)+1(5)=12\), and the weighted second-coordinate sum is \(1(2)+2(0)+1(4)=6\). Thus \(\mathbf{c}=(12/4,6/4)=(3,3/2)\).
At the centroid, the squared distances are \((1-3)^2+(2-3/2)^2=4+1/4=17/4\), \((3-3)^2+(0-3/2)^2=9/4\), and \((5-3)^2+(4-3/2)^2=4+25/4=41/4\). The weighted objective is \(J(\mathbf{c})=1(17/4)+2(9/4)+1(41/4)=76/4=19\).
Now check the identity at the proposed location \(\mathbf{x}=(0,0)\). Its direct objective is \(1(1^2+2^2)+2(3^2+0^2)+1(5^2+4^2)=5+18+41=64\). The identity gives \(J(\mathbf{x})=J(\mathbf{c})+W\|\mathbf{x}-\mathbf{c}\|^2\). Here \(\|\mathbf{x}-\mathbf{c}\|^2=3^2+(3/2)^2=9+9/4=45/4\), so \(19+4(45/4)=19+45=64\), matching the direct calculation.
This check illustrates why the centroid is optimal: any displacement from it adds \(W\) times the squared displacement to the minimum objective.
Worked Example: A Facility Along a Straight Road
Worked Example: A Facility Along a Straight Road
Suppose three customers are located at \(-2\), \(1\), and \(7\) kilometres along a straight road, with weights \(2\), \(3\), and \(1\). Find the best facility coordinate and the minimum weighted squared-distance objective.
The total weight is \(W=2+3+1=6\). The weighted sum of the coordinates is \(2(-2)+3(1)+1(7)=-4+3+7=6\). The weighted centroid is therefore \(c=6/6=1\) kilometre.
The distances from \(1\) kilometre to the three locations are \(3\), \(0\), and \(6\) kilometres. Their weighted squared-distance contributions are \(2(3^2)=18\), \(3(0^2)=0\), and \(1(6^2)=36\), so the objective at the centroid is \(18+0+36=54\) weighted square kilometres.
For a derivative check, \(J'(x)=2\big(2(x+2)+3(x-1)+(x-7)\big)=2(6x-6)\). Thus \(J'(1)=0\). Also \(J''(x)=12>0\), and the identity \(J(x)=J(1)+6(x-1)^2\) confirms that every other location has a larger objective.
Common Pitfall: Using the Ordinary Average
The ordinary average treats every customer as equally important. That is appropriate only when the weights are all equal. In the first example, the unweighted average of the three locations is \(((0+6+0)/3,(0+0+4)/3)=(2,4/3)\), not the weighted centroid \((2,2)\).
The ordinary average does not minimize the stated weighted objective. At \((2,4/3)\), the weighted coordinate sums are still \((12,12)\), but \(W(2,4/3)=(12,8)\). Consequently, \(\nabla J(2,4/3)=2((12,8)-(12,12))=(0,-8)\), which is not zero. The error is using an unweighted average even though the objective assigns different weights. The weighted sum in each coordinate must be divided by the total weight, not by the number of customers.
When the Formula Applies
The weighted centroid result relies on the objective being a sum of weighted squared Euclidean distances and the facility being unrestricted in \(\mathbb{R}^d\). If the facility must lie in a prescribed region, the weighted centroid might not be feasible; the unconstrained formula alone then does not solve the constrained problem. Likewise, replacing squared distance by ordinary distance changes the objective, so the derivation here no longer establishes the minimizing location.
For positive weights, the total weight is positive and the minimum is unique. More generally, the same identity and uniqueness conclusion hold for nonnegative weights provided at least one weight is positive. Negative weights do not represent positive importance in this model and do not satisfy the conditions used to prove the result.
The practical value of the formula is that it turns a multivariable minimization into a direct calculation: multiply each location by its weight, add those weighted locations, and divide by the total weight. The sum-of-squares identity then gives an exact check of both the minimum and the cost of moving the facility away from it.
Check Your Understanding
Use the definitions and result above to answer these questions.
- For two locations \((0,0)\) and \((4,2)\) with weights \(1\) and \(3\), what is the weighted centroid?
- Why does the condition \(\sum_i w_i(\mathbf{p}_i-\mathbf{c})=\mathbf{0}\) make the cross term vanish in the objective expansion?
- What does the identity \(J(\mathbf{x})=J(\mathbf{c})+W\|\mathbf{x}-\mathbf{c}\|^2\) tell you about uniqueness?
- In what situation might the unconstrained weighted centroid fail to be an admissible facility location?
- Why is dividing by the number of customers generally incorrect when their weights differ?