Close

Balancing - Brute force fail, website success.

A project log for Minimalist Li-Ion Discharger/Capacity meter.

What you need to grade your scavenged cells for building balanced packs.

Daren SchwenkeDaren Schwenke 02/05/2019 at 20:050 Comments

While I'm waiting for all my cells to cycle a second time, I've been messing around with some scripts for sorting the cells.

I started to write a little python script to calculate all the possible combinations of the cells, to basically randomly seek cell groups of 5 which most evenly match them.

#!/usr/bin/python
import itertools
files = open("cells.txt")
cells = []
for line in files:
  cells.append(int(line.rstrip()))

perm_iter = itertools.permutations(cells)
for item in perm_iter:
    groups = itertools.izip(*[itertools.islice(item, i, None, 5) for i in range(5)])
    print list( itertools.imap(sum,groups) )

I never got beyond printing them, because from what I can tell, this would take until the heat death of the universe to finish.  In 10 minutes it tried only the combinations for the first 2 groups.  The results are returning in lexicographical order as well, so even randomly stumbling upon the right answer would take nearly until the end.

I also tried just iterating through the list, with just dumb grouping of the strongest with the weakest and meeting in the middle.  That was fast, but since the cell values were not linear... not perfect.

I think I'll need to be a bit more directed in my search.  I'm sure there is something in between that will work.  Just gotta find it.  Or I could just do an acceptable job manually in about 5 minutes, but this is more fun.

Feel free to offer suggestions on a script to generate my matched sets of 5.  :)

<EDIT>

I posed this question at the local hackerspace Facebook page, and Daniel Near suggested this:

http://repackr.com/

You paste your list of capacities as a CSV, enter the serial and parallel configuration desired, and...

That is just perfect.  One less thing to do.

</EDIT>

Discussions