Branch and Bound Solver Calculator

Enter items and capacity, then run the solver. Choose best-first or depth-first exploration mode quickly. See optimal value, chosen items, and pruning statistics below.

Solve a 0/1 Knapsack Instance
Each line: name,value,weight or value weight.
Maximum total weight allowed.
Best-first usually prunes earlier on dense items.
Bounding uses the current sorted order.
Stops early if the search grows too large.
Hard stop to keep the page responsive.
Use summary-only for bigger item lists.
Example line: A,40,2 meaning value 40 and weight 2.

Example Data Table

Use this sample to verify the solver output and exports.

ItemValueWeightValue/Weight
A40220.000
B3056.000
C50105.000
D1052.000
E3575.000

Capacity: 16. A common optimal set is A + B + E (value 105, weight 14), but your run depends on sort and limits.

Formula Used

This solver targets the 0/1 knapsack objective: maximize Σ vᵢ xᵢ subject to Σ wᵢ xᵢ ≤ C, where xᵢ ∈ {0,1}.

Branch-and-bound explores include/exclude decisions per item. Each node gets an upper bound using a fractional knapsack relaxation: fill remaining capacity with whole items, then one fractional item, using the chosen sort order. Nodes with bound ≤ best are pruned.

How to Use This Calculator

  1. Enter a positive capacity (maximum weight).
  2. Add items, one per line, as name,value,weight.
  3. Pick an exploration strategy and a sort order.
  4. Set limits if you expect a large search tree.
  5. Press Solve Now to view results above.
  6. Download CSV or PDF for records and sharing.

What the Solver Optimizes

This calculator solves the 0/1 knapsack model, where each item is either chosen or rejected. The objective is to maximize total value while respecting a strict capacity limit. It is widely used to model selection under constraints, such as budgeted projects, limited storage, or fixed processing windows. Because the decision variables are binary, the problem is combinatorial, and exact solutions benefit from intelligent pruning for realistic input sizes.

How Branch and Bound Cuts Work

Branching creates a decision tree: at level i, the algorithm tries including item i and excluding item i. Bounding assigns an optimistic upper limit to each partial decision so unpromising branches can be discarded early. This reduces the search dramatically compared with enumerating all 2^n subsets.

Upper Bound from Fractional Relaxation

The bound here is computed with a fractional knapsack relaxation. After placing the already-fixed items, the remaining capacity is filled greedily with whole items in the selected sort order, and then with a fraction of the next item. The resulting value is an admissible upper bound for the true 0/1 optimum below that node.

Best‑First Versus Depth‑First Search

Best‑first prioritizes the node with the highest bound, often finding strong solutions quickly and pruning aggressively once a good incumbent exists. Depth‑first dives deeper using a stack, which can be memory‑light and fast for small instances, but may explore weaker branches longer before tightening the incumbent.

Interpreting Diagnostics and Gap

Nodes created count all generated states, expanded counts states that actually branched, and pruned counts states discarded by the bound rule. The displayed “gap” equals the last seen upper bound minus the best feasible value found. A zero gap with completed search indicates optimality.

Practical Data Tips for Reliable Runs

Keep weights positive, scale units consistently, and avoid extreme magnitudes that obscure comparisons. For larger lists, start with density sorting and best‑first exploration, then raise node and time limits gradually. Export the CSV to audit the node trace and reproduce results in reports.

FAQs

What problem does this solver handle?

It solves a 0/1 knapsack selection: choose a subset of items to maximize value without exceeding the capacity constraint.

Why can the result say “Not proven”?

If the search stops due to node or time limits, the best solution is feasible but optimality is not mathematically guaranteed.

How do I format item input?

Enter one item per line as name,value,weight. You may also use two numbers as value weight.

What does the upper bound represent?

It is an optimistic estimate from a fractional relaxation. If the bound is not better than the best found value, that branch is pruned.

Best-first or depth-first: which should I choose?

Best-first often finds strong incumbents quickly and prunes earlier. Depth-first can be simpler and memory-light for small inputs.

Why can sorting change speed and trace shape?

Sorting affects the fractional bound quality and node ordering. Better bounds prune earlier, reducing explored nodes and improving runtime.

Related Calculators

knapsack problem solver

Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.