How this calculation works
Weighted set cover chooses which candidate sets to buy so that their union contains every required element at minimum total set cost. Overlap is allowed, and a selected set is charged once regardless of how many elements it covers. This calculator reads a cost followed by a coverage flag for each universe element. It checks every supported subset of candidate sets, accumulating each subset’s union and total cost exactly. It reports one complete optimum or explains that some requirements cannot be covered at all.
Minimize Σwⱼzⱼ subject to Σ over sets j containing i of zⱼ≥1 for every element i; zⱼ∈{0,1}.A worked example
The universe is {1,2,3}. Set one covers {1,2} and costs four; set two covers {2,3} and costs four; set three covers {1,2,3} and costs seven. Choosing the first two sets covers everything but costs eight. Choosing only the third set costs seven and is optimal. Element two is covered twice in the two-set choice, but that repetition is neither a new requirement nor a refund. The output selects set row three with total cost seven.
Good to know
Supports 1–20 required elements and at most 18 candidate sets. Costs are nonnegative integers at most 1,000,000 and coverage flags are exactly zero or one. Every supported subset is considered, so the result is exact within those limits. Tied minimum costs prefer fewer selected sets and then deterministic enumeration order. Empty sets and zero-cost sets are allowed but do not excuse an uncovered element. This model has no quotas, mutually exclusive choices, probabilistic coverage, repeated set purchases or partial-coverage reward.
Reference: Carnegie Mellon — weighted set-cover formulation (opens in a new tab) ↗
Cover constraints apply to elements; costs apply to selected sets
A row represents one indivisible candidate set, not an individual assignment of each marked element. Selecting it covers all of its one-flag columns at once. Several selected rows may cover the same column, which is permitted because the constraint is at least one. The objective still adds each selected row’s cost exactly once. Treating overlap as an error would instead turn the task into an exact-cover problem and can exclude the true minimum set cover.
Before comparing costs, inspect whether every required element appears somewhere in the candidate collection. A column of all zeros makes complete coverage impossible, independent of the prices of other sets. The tool lists those uncoverable element labels and does not return the cheapest partial union as if it were a feasible full answer. A zero-cost row can be useful, but a free empty row contributes no coverage.
An exact small search avoids mislabeling a greedy approximation
The general problem is computationally difficult at large scale. Greedily choosing a low cost per newly covered element is a useful approximation in some settings, but it need not find the optimum. This calculator instead limits the number of candidates and checks every subset. Its state count shows the supported exponential search scope. The hard input limit is part of the result’s meaning, not permission to call a prematurely stopped greedy solution exact.
Equal minimum costs can be achieved by different collections. The secondary preference for fewer selected sets only breaks ties after the primary cost objective; it does not allow a more expensive single set to beat a cheaper multi-set cover. The Assignment problem calculator from cost matrix pairs disjoint rows and columns, whereas set cover can satisfy many element requirements through one overlapping row. The Minimum vertex cut calculator with disjoint paths removes graph vertices to separate terminals and does not solve this arbitrary universe-coverage objective.
A few questions, answered
Does each element have to be covered exactly once?
No. At least once is sufficient, and overlap is allowed. Requiring exactly one occurrence would define a different exact-cover problem.
Can I enter negative set costs?
No. This bounded model accepts nonnegative costs. Zero is valid, and its effect is still evaluated over complete covers.