A tool to design better battery packs by dividing (typically salvaged) cells into groups of similar capacity (mAh). Uses iterative maximum weight maximum cardinality matching to create optimal groups of 2S, 4S, 8S, or 16S configurations.
Note: Only powers of 2 are supported (2S, 4S, 8S, 16S) because the algorithm uses iterative pairing - it creates optimal pairs first, then pairs those pairs, and so on. This approach works well for powers of 2 but doesn't extend naturally to other group sizes like 3S or 6S, which would require different algorithms.
Warning: Battery packs are dangerous, and used cells are unpredictable. Use at your own risk.
Github - but you can also File->Save Page As, there's no build step. Original source is Gia's Blog.
Cell ID | Capacity (mAh) | Group | Action |
---|
Minimize total capacity loss: Optimizes for global efficiency by minimizing the sum of all capacity differences across all groups. Best when you want maximum total usable capacity from your cell collection.
Optimize for individual pack balance: Uses minimax optimization to minimize the worst-case imbalance within any single group. Best for safety and longevity since no pack will have terrible internal balance.
The iterative pairing algorithm works by creating optimal pairs first, then pairing those pairs, and so on. This naturally extends to 4S (pair the pairs), 8S (pair the 4S groups), etc. Other group sizes like 3S or 6S would require different algorithms such as k-uniform hypergraph matching or greedy clustering.
Important limitation: This tool only considers capacity (mAh) for grouping cells. Cells with similar capacity but very different internal resistance can cause problems:
In parallel configurations: Cells with lower internal resistance will carry more current, leading to uneven heating and degradation.
In series configurations: While less critical than in parallel, large internal resistance differences can still cause uneven voltage drops under load and affect charging balance.
This tool is designed for series-only configurations where capacity matching is the primary concern. In general, I suggest tossing out cells with anomalously high resistance.
Total capacity loss: Uses maximum weight matching where edge weights are inversely proportional to capacity differences. Recursively builds larger groups by treating smaller groups as single units.
Individual pack balance: Uses binary search to find the minimum achievable maximum group variance. For each candidate variance threshold, checks if a valid grouping exists using constrained maximum cardinality matching.
Both algorithms are based on Edmonds' blossom algorithm for maximum weight matching in general graphs. I used this JS implementation: @graph-algorithm/maximum-matching
Except for the bundled dependencies, I hereby place this tool in the public domain. I don't mind a shout-out :)