{ "cells": [ { "cell_type": "markdown", "id": "timely-rogers", "metadata": {}, "source": [ "# LiXX_Cell_Pack_Matcher\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "id": "temporal-pipeline", "metadata": {}, "outputs": [], "source": [ "l" ] }, { "cell_type": "code", "execution_count": 10, "id": "outer-america", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[('B01', 2124), ('B02', 2005), ('B03', 2127), ('B04', 2099), ('B05', 2117), ('B06', 1999), ('B07', 1999), ('B08', 1999), ('B09', 1999), ('B10', 1999), ('B11', 1999), ('B12', 1999)]\n" ] } ], "source": [ "cellList = [\n", "('B01', 2124), \n", "('B02', 2005),\n", "('B03', 2127),\n", "('B04', 2099),\n", "('B05', 2117),\n", "('B06', 1999),\n", "('B07', 1999),\n", "('B08', 1999),\n", "('B09', 1999),\n", "('B10', 1999),\n", "('B11', 1999),\n", "('B12', 1999)\n", "];\n", "\n", "cellsParallel = int(2)\n", "cellsSerial = int(6) # 6 for 6S LiXX and so on..\n", "\n", "if(cellsParallel*cellsSerial) != len(cellList):\n", " print(\"Battery pack is not possible for this configuration\")\n", "else:\n", " print (cellList)" ] }, { "cell_type": "code", "execution_count": 11, "id": "southeast-enclosure", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from itertools import combinations \n", "import collections\n", "\n", "combCells = combinations(cellList, cellsParallel) #combine cells to parallel Pairs\n", "combPacks = combinations(combCells, cellsSerial) #combine parallel Pairs to serial pack\n", "\n", "possiblePacks = []\n", "possiblePacks.clear()\n", "\n", "for combPack in list(combPacks): \n", " #print(\"combPack: \", combPack) \n", " cellsPackList = []\n", " cellsPackList.clear()\n", " \n", " for serialPair in combPack:\n", " #print(\"CellPairsInThisPack: \", serialPair)\n", " for cellsTmp in serialPair:\n", " #print(\"CellInThisPair: \" , cellsTmp)\n", " cellsPackList.append(cellsTmp);\n", " if collections.Counter(cellsPackList) == collections.Counter(cellList):\n", " #test if this pack is a possible solution\n", " possiblePacks.append(combPack); \n", " \n", "bestSolution = (possiblePacks[0], 1000 );\n", " \n", "for possiblePack in possiblePacks:\n", " #loop though a possible solution\n", " #print(\"possiblePack: \", possiblePack);\n", " \n", " packMatchQuality = 0\n", " \n", " for serialPair in possiblePack:\n", " #loop through the serial pairs\n", " cellCapacityInThisPairList = []\n", " cellCapacityInThisPairList.clear()\n", " for cellsTmp in serialPair:\n", " #loop through the cells in this serial paar\n", " cellCapacityInThisPairList.append(cellsTmp[1]); #save capacity in list \n", " \n", " cv = lambda x: np.std(x, ddof=1) / np.mean(x) * 100\n", " packMatchQuality = packMatchQuality + cv(np.array(cellCapacityInThisPairList))\n", " \n", " if bestSolution[1] > packMatchQuality:\n", " bestSolution = (possiblePack, packMatchQuality );\n", " \n", "\n", " \n", " " ] }, { "cell_type": "code", "execution_count": 12, "id": "occupational-deadline", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Matching Quality: 0.9155148399305513\n", "CellPairsInThisPack: (('B01', 2124), ('B03', 2127))\n", "CellPairsInThisPack: (('B02', 2005), ('B06', 1999))\n", "CellPairsInThisPack: (('B04', 2099), ('B05', 2117))\n", "CellPairsInThisPack: (('B07', 1999), ('B08', 1999))\n", "CellPairsInThisPack: (('B09', 1999), ('B10', 1999))\n", "CellPairsInThisPack: (('B11', 1999), ('B12', 1999))\n" ] } ], "source": [ "print (\"Matching Quality: \", bestSolution[1]) \n", "\n", "for serialPair in bestSolution[0]:\n", " #loop through the serial pairs\n", " print(\"CellPairsInThisPack: \", serialPair)\n", "\n", " \n", "\n" ] }, { "cell_type": "code", "execution_count": null, "id": "informative-sequence", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.8" } }, "nbformat": 4, "nbformat_minor": 5 }