Facility Location Generator
Given demand scattered across a map, where should a small number of depots go so that everyone's journey is as short as possible? Choosing them one at a time — always the site that helps most right now — is the obvious approach and a genuinely useful one. It is also not always right, because a site that looks best on its own need not belong in the best pair, and seeing that happen is the fastest way to understand why the problem is hard.
What this generator does
Scatters demand points on a grid, each with its own demand weight, and picks facility sites greedily — adding whichever site reduces total weighted distance most, one at a time. It then evaluates every combination of that size and reports the genuine best, so the greedy answer can be compared rather than trusted.
How to use this tool
- Choose how many demand locations and how many facilities to open.
- Look at the positions and demands, and pick your own sites.
- Generate, and compare the greedy placement with the best possible one.
- Increase the facility count and watch the weighted distance fall with diminishing returns.
Understanding the controls
- How many locations
- Between 2 and 10 demand points, each with a position and a demand weight that scales its contribution.
- How many facilities to open
- Between 1 and 4. More facilities always reduce total distance, but with clearly diminishing returns.
- Seed
- Any word reproduces the same map, the same demands and the same answers.
Common use cases
- Teaching the p-median problem with the greedy-versus-optimal gap made visible
- Depot, hub and service-centre placement exercises
- Showing why weighted demand pulls a facility away from the geometric centre
- Test instances for a location-optimisation implementation
- Setting a reproducible exercise from a seed
How this generator works
Each demand point is served by whichever open facility is nearest, and its straight-line distance is multiplied by its demand — so a busy site pulls a facility towards it more strongly than a quiet one. Greedy adds sites one at a time by immediate benefit. The exhaustive search evaluates every combination of the requested size, which is what lets the page state whether greedy was right this time instead of assuming it.
Randomness and fairness
The positions and demands are random; both placements are computed from them. A seed reproduces the problem exactly and is therefore explicitly not cryptographically secure. Without a seed the browser's cryptographically secure generator is used.
For how randomness is produced across the whole site, see how Generate Random works.
Limitations and good to know
- Facilities can only be opened at demand points, which is the p-median form rather than free placement anywhere.
- Straight-line distance, so no road network, barriers or travel times.
- No cost of opening a facility, so more is always better — the count is your constraint, not an optimised value.
- No capacity limit per facility; every site is served by its nearest regardless of load.
- A generated case vanishes with the page; the seed brings it back.
Privacy and your data
The map and both searches run entirely in your browser. Nothing about the problem or your seed is transmitted or kept.
Related generators
- Transportation Problem GeneratorBalanced supply-and-demand shipping problems solved by the least-cost rule, with exhaustive search saying honestly whether that answer was optimal.
- Set Cover Problem GeneratorCoverage problems where greedy selection is compared against the true minimum found by exhaustive search, so the cost of approximation is visible.
- Random Coordinate GeneratorA latitude/longitude coordinate, uniformly distributed across the globe — could land anywhere, ocean included.
- Task Assignment OptimiserThe cheapest one-to-one matching of people to tasks, proved optimal against every possible assignment.