How this calculation works
Choose exactly k facility vertices minimizing the sum of client weight times shortest weighted distance.
min |F|=k Σ_v w_v min_f∈F d(v,f).A worked example
With two facilities and endpoint client weights three, the default unit path attains total weighted distance four by locating at vertices 0 and 4.
Good to know
Connected undirected graph on 1–16 vertices; strictly positive edge lengths at most 10^6, nonnegative client weights at most 10^6, exactly 1≤k≤min(5,n). Exact facility subsets; floating-point arithmetic and deterministic ties.
Minimize aggregate service distance
The graph k-median problem places facilities at exactly k distinct vertices. Every vertex is a client with a nonnegative demand weight, and each client is assigned to its nearest selected facility using shortest weighted graph distance. The objective adds those weighted service distances across all clients.
Facilities and clients share the declared vertex set. A selected facility serves its own vertex at distance zero. A zero-weight client still exists in the network and can be a facility location or transit vertex, but its own service distance contributes nothing to the objective total.
Compare this with the Graph radius diameter and center calculator from an adjacency matrix. Choose k facility vertices minimizing total weighted client distance,not the worst distance from a single center.
Separate road lengths from client weights
Each edge row contains two zero-based endpoints followed by a strictly positive length. The graph is undirected and must be connected. Lengths describe travel cost along a route, whereas the separate client-weight list describes the importance or volume of demand at each vertex in label order.
Enter exactly one client weight per vertex and choose k between one and five without exceeding the vertex count. Client weights may be zero; edge lengths may not. Duplicated unordered edges, loops and nonfinite numbers are rejected. Changing either kind of weight can change the optimal facility locations.
Work through weighted endpoints
The default network is a five-vertex path with four unit-length edges. Endpoint clients each have weight three, while the three interior clients each have weight one. Selecting both endpoints as facilities gives service distances zero, one, two, one and zero, whose weighted sum is four.
The returned assignment table shows this contribution client by client. An alternative optimum may exist, so the displayed facilities need not be interpreted as uniquely necessary. A central pair that leaves both high-weight endpoints one step away already pays six before accounting for any interior demand, explaining why endpoint coverage is valuable here.
Search facility subsets exactly
The calculator first computes shortest distances between every pair of vertices using repeated intermediate-vertex relaxation. Positive edge lengths ensure that using an extra cycle cannot improve a route. It then evaluates every facility subset having exactly k vertices, rather than making a sequence of irreversible greedy location choices.
For each candidate subset, every client independently selects its closest facility. There are no capacity limits coupling those assignments, so choosing the nearest facility minimizes that candidate’s total. Comparing all candidate totals therefore proves the optimum within the declared model, and the retained assignments certify the cost of the winning subset.
Audit assignments and objective units
The facilities list contains vertex labels, while each assignment record identifies its client, chosen facility, distance and weighted contribution. Adding the contributions should reproduce the reported objective. If a client has zero weight, its nearest-facility distance can be positive even though its contribution is exactly zero.
When edge lengths are kilometers and client weights are shipments, the objective has kilometer-shipment units. It is not an average until divided by total client weight. If all client weights vanish, every facility subset has objective zero; selecting a particular witness does not express a meaningful preference among those tied locations.
Distinguish median from center objectives
A graph center minimizes the worst distance to a facility, whereas a median minimizes a total. Large client weights can pull a median toward heavily demanded vertices even when a lightly weighted peripheral vertex becomes farther away. Neither objective is automatically the right one for every service-planning question.
The parameter k fixes the number of facilities rather than imposing a facility-opening cost. Adding that cost and allowing k to vary would define another model. Capacity restrictions, unequal opening prices and clients forbidden from using certain facilities are likewise not encoded by the simple weighted-distance objective used on this page.
Interpret bounded numerical results
The input limit is sixteen vertices with at most five facilities, so every eligible subset can be checked directly. Distances and costs use finite floating-point numbers. Equal or extremely close totals should be interpreted with their numerical precision in mind, especially when decimal lengths represent rounded measurements from another source.
A successful result gives one optimum for the entered distances and weights, not a guarantee about future travel times or demand. For sensitivity analysis, change a clearly identified client weight or edge length and compare both cost and facilities. Always retain the original units and zero-weight conventions when comparing such scenarios.
A few questions, answered
Are client weights edge lengths?
No. Edge lengths define distances; client weights multiply each client’s assigned distance.
Can a client weight be zero?
Yes. Its own contribution vanishes, while its vertex remains available for routes and facilities.
Are facilities capacity limited?
No. Every client uses a nearest facility without capacity restrictions.
Does the calculator minimize the worst distance?
No. It minimizes the sum of weighted distances; a center objective is different.