How this calculation works
Choose a minimum-cost spanning edge subset with exactly k selected incident edges at each vertex. Feasibility and cost are reported together with the selected edges, making the degree constraints inspectable.
min Σ_e c_e x_e subject to Σ_(e incident v)x_e=k for every v; x_e∈{0,1}.A worked example
For the four-cycle with side costs1 and diagonal costs4, k=2 selects all four sides for cost4. Each vertex then has degree2. The two diagonals alone have degree1 and do not satisfy the requirement.
Good to know
Simple undirected graph≤10 vertices,≤22 edges,nonnegative costs≤1000000,k2–4 smaller than n. Exact branch search capped at1500000 states. A2-factor can contain multiple cycles; it is not required to be one Hamiltonian cycle.
Every vertex has an exact selected degree
A k-factor is a spanning subgraph in which every declared vertex has degree exactly k. The vertices remain present even if a proposed edge selection would leave one unserved, so selecting a cheap subgraph is not enough.
This differs from a matching, where selected degree is at most one, and from an ordinary edge cover, which only requires some incident selected edge. Here all vertex degree equalities must hold simultaneously.
Compare this with the Maximum weight matching calculator for a general graph. A matching imposes degree at most one;general k factors require exact specified degree.
Costs belong to edges and are counted once
Each input row gives two distinct zero-based endpoints and one nonnegative cost. Choosing that undirected edge adds its cost once, even though it contributes one degree to each of its endpoints.
A zero-cost edge is valid and can appear in an optimum. Negative costs, loops and parallel edges are outside the stated model. Keep all costs in the same unit if the minimum is intended to represent a budget.
Prune only when a degree bound proves failure
The search considers selecting or excluding each edge. It tracks selected degrees and how many unused incident edges remain, pruning a branch if a degree already exceeds k or cannot possibly reach k.
Because costs are nonnegative, a partial selection already no cheaper than the incumbent cannot improve the optimum. These pruning rules preserve completeness; they do not replace exact search with a greedy preference for inexpensive edges.
The square supplies a cost-four2-factor
Selecting all four unit-cost sides gives degree two at each of the four vertices and total cost four. Any feasible2-factor needs four selected edges because the degree sum is eight.
Every available edge costs at least one, so four is also a lower bound. The side cycle attains it. This independently checks the default result and shows why choosing only the two cheap opposite sides would violate the degree constraints.
A2-factor need not be one cycle
When k equals two, each connected component of a feasible simple factor is a cycle. More than one cycle is allowed, so a minimum2-factor can differ from a traveling-salesperson or Hamiltonian-cycle solution.
The returned edge list is the right object to inspect for connectivity. If a single tour is required, adding that connectivity condition changes the problem. The calculator does not silently enforce it or label a disconnected factor as a tour.
Infeasible and unresolved are different outcomes
Some degree requests fail immediately because too few incident edges are available; other obstructions appear only through the global search. A completed search with no feasible subset returns explicit infeasibility.
Reaching the state cap returns an error instead of presenting the best partial selection as optimal. The small vertex and edge bounds make meaningful exact examples practical but are not a promise to solve arbitrary large factor instances.
Use equal-degree designs with explicit assumptions
The model can describe a design where every item must participate in the same number of selected pairwise relationships. It balances incidence counts exactly while allowing costs to determine which permitted relationships are used.
It does not model directed in-degree and out-degree separately, edge capacities, lower and upper degree ranges or reliability of selected relationships. Those additions require different constraints and should not be inferred from a successful factor witness.
A few questions, answered
Is a2-factor always Hamiltonian?
No. It can be a disjoint union of several cycles.
Can an edge have zero cost?
Yes. Costs are nonnegative, and zero is permitted.
Why does each edge contribute two degrees?
One incidence belongs to each endpoint, but the edge cost is paid once.
What happens if search reaches its cap?
The page reports an unresolved error rather than claiming a feasible selection is optimal.