This commit is contained in:
2025-12-21 09:00:48 +01:00
parent fecdcafed2
commit cfb031aee6
4 changed files with 420 additions and 390 deletions

View File

@ -2,11 +2,7 @@
LiXX Cell Pack Matcher - Styles LiXX Cell Pack Matcher - Styles
========================================================================== */ ========================================================================== */
/* --------------------------------------------------------------------------
CSS Custom Properties (Variables)
-------------------------------------------------------------------------- */
:root { :root {
/* Colors */
--bg-primary: #0f1419; --bg-primary: #0f1419;
--bg-secondary: #1a1f2e; --bg-secondary: #1a1f2e;
--bg-tertiary: #242b3d; --bg-tertiary: #242b3d;
@ -20,38 +16,27 @@
--warning: #f59e0b; --warning: #f59e0b;
--danger: #ef4444; --danger: #ef4444;
--border-color: #2f3336; --border-color: #2f3336;
/* Cell visualization colors */
--cell-low: #ef4444; --cell-low: #ef4444;
--cell-mid: #22c55e; --cell-mid: #22c55e;
--cell-high: #3b82f6; --cell-high: #3b82f6;
/* Spacing */
--space-xs: 0.25rem; --space-xs: 0.25rem;
--space-sm: 0.5rem; --space-sm: 0.5rem;
--space-md: 1rem; --space-md: 1rem;
--space-lg: 1.5rem; --space-lg: 1.5rem;
--space-xl: 2rem; --space-xl: 2rem;
--space-2xl: 3rem; --space-2xl: 3rem;
/* Typography */
--font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
--font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', Consolas, monospace; --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', Consolas, monospace;
/* Borders & Shadows */
--radius-sm: 4px; --radius-sm: 4px;
--radius-md: 8px; --radius-md: 8px;
--radius-lg: 12px; --radius-lg: 12px;
--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3); --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
--shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4); --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
--shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5); --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
/* Transitions */
--transition-fast: 150ms ease; --transition-fast: 150ms ease;
--transition-normal: 250ms ease; --transition-normal: 250ms ease;
} }
/* Light mode support */
@media (prefers-color-scheme: light) { @media (prefers-color-scheme: light) {
:root { :root {
--bg-primary: #ffffff; --bg-primary: #ffffff;
@ -67,9 +52,6 @@
} }
} }
/* --------------------------------------------------------------------------
Base Styles
-------------------------------------------------------------------------- */
*, *,
*::before, *::before,
*::after { *::after {
@ -90,27 +72,19 @@ body {
color: var(--text-primary); color: var(--text-primary);
background-color: var(--bg-primary); background-color: var(--bg-primary);
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
} }
/* Focus styles for keyboard navigation */
:focus-visible { :focus-visible {
outline: 2px solid var(--accent); outline: 2px solid var(--accent);
outline-offset: 2px; outline-offset: 2px;
} }
/* --------------------------------------------------------------------------
Layout
-------------------------------------------------------------------------- */
.container { .container {
max-width: 1000px; max-width: 1000px;
margin: 0 auto; margin: 0 auto;
padding: var(--space-lg); padding: var(--space-lg);
} }
/* --------------------------------------------------------------------------
Header
-------------------------------------------------------------------------- */
header { header {
text-align: center; text-align: center;
margin-bottom: var(--space-2xl); margin-bottom: var(--space-2xl);
@ -137,9 +111,6 @@ header {
font-size: 1.1rem; font-size: 1.1rem;
} }
/* --------------------------------------------------------------------------
Cards
-------------------------------------------------------------------------- */
.card { .card {
background: var(--bg-secondary); background: var(--bg-secondary);
border: 1px solid var(--border-color); border: 1px solid var(--border-color);
@ -163,9 +134,6 @@ header {
color: var(--text-secondary); color: var(--text-secondary);
} }
/* --------------------------------------------------------------------------
Form Elements
-------------------------------------------------------------------------- */
.form-group { .form-group {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -225,9 +193,6 @@ output {
color: var(--text-secondary); color: var(--text-secondary);
} }
/* --------------------------------------------------------------------------
Buttons
-------------------------------------------------------------------------- */
.btn { .btn {
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;
@ -305,9 +270,6 @@ output {
gap: var(--space-sm); gap: var(--space-sm);
} }
/* --------------------------------------------------------------------------
Configuration Grid
-------------------------------------------------------------------------- */
.config-grid { .config-grid {
display: grid; display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
@ -325,9 +287,6 @@ output {
border-radius: var(--radius-md); border-radius: var(--radius-md);
} }
/* --------------------------------------------------------------------------
Cell Input Section
-------------------------------------------------------------------------- */
.cell-input-header { .cell-input-header {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
@ -412,9 +371,6 @@ output {
font-family: var(--font-mono); font-family: var(--font-mono);
} }
/* --------------------------------------------------------------------------
Settings Grid
-------------------------------------------------------------------------- */
.settings-grid { .settings-grid {
display: grid; display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
@ -422,9 +378,6 @@ output {
margin-bottom: var(--space-xl); margin-bottom: var(--space-xl);
} }
/* --------------------------------------------------------------------------
Progress Section
-------------------------------------------------------------------------- */
.progress-container { .progress-container {
margin-bottom: var(--space-lg); margin-bottom: var(--space-lg);
} }
@ -480,7 +433,6 @@ output {
color: var(--accent); color: var(--accent);
} }
/* Live Preview */
.live-preview { .live-preview {
margin-top: var(--space-lg); margin-top: var(--space-lg);
padding: var(--space-md); padding: var(--space-md);
@ -529,9 +481,6 @@ output {
margin-left: var(--space-xs); margin-left: var(--space-xs);
} }
/* --------------------------------------------------------------------------
Warning Banner
-------------------------------------------------------------------------- */
.warning-banner { .warning-banner {
display: flex; display: flex;
gap: var(--space-md); gap: var(--space-md);
@ -571,9 +520,6 @@ output {
color: var(--accent); color: var(--accent);
} }
/* --------------------------------------------------------------------------
Results Summary
-------------------------------------------------------------------------- */
.results-summary { .results-summary {
display: grid; display: grid;
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
@ -582,6 +528,7 @@ output {
} }
.result-metric { .result-metric {
position: relative;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
@ -589,6 +536,7 @@ output {
background: var(--bg-tertiary); background: var(--bg-tertiary);
border-radius: var(--radius-md); border-radius: var(--radius-md);
text-align: center; text-align: center;
cursor: help;
} }
.metric-value { .metric-value {
@ -604,335 +552,9 @@ output {
margin-top: var(--space-xs); margin-top: var(--space-xs);
} }
/* --------------------------------------------------------------------------
Pack Visualization
-------------------------------------------------------------------------- */
.pack-visualization {
margin-bottom: var(--space-xl);
}
.pack-grid {
display: flex;
flex-direction: column;
gap: var(--space-sm);
padding: var(--space-lg);
background: var(--bg-tertiary);
border-radius: var(--radius-md);
overflow-x: auto;
}
.pack-row {
display: flex;
gap: var(--space-sm);
align-items: center;
}
.pack-row-label {
min-width: 30px;
font-size: 0.75rem;
font-weight: 600;
color: var(--text-muted);
text-align: right;
}
.pack-cells {
display: flex;
gap: var(--space-xs);
}
.pack-cell {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-width: 70px;
padding: var(--space-sm);
background: var(--cell-mid);
border-radius: var(--radius-sm);
font-size: 0.7rem;
color: white;
text-align: center;
transition: transform var(--transition-fast);
}
.pack-cell:hover {
transform: scale(1.05);
}
.pack-cell .cell-label {
font-weight: 600;
margin-bottom: 2px;
}
.pack-cell .cell-capacity {
opacity: 0.9;
}
.pack-cell .cell-ir {
opacity: 0.7;
font-size: 0.65rem;
}
.pack-legend {
display: flex;
justify-content: center;
gap: var(--space-lg);
margin-top: var(--space-md);
font-size: 0.75rem;
color: var(--text-secondary);
}
.legend-color {
display: inline-block;
width: 12px;
height: 12px;
border-radius: 2px;
margin-right: var(--space-xs);
vertical-align: middle;
}
/* --------------------------------------------------------------------------
Results Table
-------------------------------------------------------------------------- */
.results-table-wrapper {
overflow-x: auto;
margin-bottom: var(--space-xl);
}
.results-table {
width: 100%;
border-collapse: collapse;
font-size: 0.875rem;
}
.results-table th,
.results-table td {
padding: var(--space-sm) var(--space-md);
text-align: left;
border-bottom: 1px solid var(--border-color);
}
.results-table th {
font-weight: 600;
color: var(--text-secondary);
background: var(--bg-tertiary);
}
.results-table td {
font-family: var(--font-mono);
}
.results-table .deviation-good {
color: var(--success);
}
.results-table .deviation-warning {
color: var(--warning);
}
.results-table .deviation-bad {
color: var(--danger);
}
/* --------------------------------------------------------------------------
Excluded Cells
-------------------------------------------------------------------------- */
.excluded-cells {
padding: var(--space-lg);
background: var(--bg-tertiary);
border-radius: var(--radius-md);
margin-bottom: var(--space-xl);
}
.excluded-cells h3 {
margin-top: 0;
}
.excluded-cells p {
margin: 0;
font-family: var(--font-mono);
font-size: 0.875rem;
color: var(--text-secondary);
}
/* --------------------------------------------------------------------------
Export Buttons
-------------------------------------------------------------------------- */
.export-buttons {
display: flex;
flex-wrap: wrap;
gap: var(--space-sm);
justify-content: center;
}
/* --------------------------------------------------------------------------
Footer
-------------------------------------------------------------------------- */
footer {
text-align: center;
padding: var(--space-xl) 0;
font-size: 0.875rem;
color: var(--text-muted);
}
footer a {
color: var(--text-secondary);
text-decoration: none;
}
footer a:hover {
color: var(--accent);
}
.disclaimer {
margin-top: var(--space-sm);
font-size: 0.75rem;
}
/* --------------------------------------------------------------------------
Dialog / Modal
-------------------------------------------------------------------------- */
dialog {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
max-width: 400px;
width: 90%;
padding: var(--space-xl);
background: var(--bg-secondary);
border: 1px solid var(--border-color);
border-radius: var(--radius-lg);
box-shadow: var(--shadow-lg);
color: var(--text-primary);
}
dialog::backdrop {
background: rgba(0, 0, 0, 0.7);
}
dialog h2 {
margin: 0 0 var(--space-lg);
}
.shortcuts-list {
display: grid;
grid-template-columns: auto 1fr;
gap: var(--space-sm) var(--space-lg);
margin-bottom: var(--space-xl);
}
.shortcuts-list dt {
font-weight: 500;
}
.shortcuts-list dd {
margin: 0;
color: var(--text-secondary);
}
kbd {
display: inline-block;
padding: 2px 6px;
font-size: 0.75rem;
font-family: var(--font-mono);
background: var(--bg-tertiary);
border: 1px solid var(--border-color);
border-radius: var(--radius-sm);
}
/* --------------------------------------------------------------------------
Responsive Adjustments
-------------------------------------------------------------------------- */
@media (max-width: 640px) {
.container {
padding: var(--space-md);
}
.card {
padding: var(--space-lg);
}
.logo h1 {
font-size: 1.25rem;
}
.config-grid,
.settings-grid {
grid-template-columns: 1fr;
}
.cell-input-header {
flex-direction: column;
align-items: flex-start;
}
.button-group {
width: 100%;
}
.button-group .btn {
flex: 1;
}
.results-summary {
grid-template-columns: repeat(2, 1fr);
}
.pack-cell {
min-width: 55px;
padding: var(--space-xs);
}
}
/* --------------------------------------------------------------------------
Reduced Motion
-------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
/* --------------------------------------------------------------------------
Print Styles
-------------------------------------------------------------------------- */
@media print {
body {
background: white;
color: black;
}
.card {
border: 1px solid #ccc;
box-shadow: none;
break-inside: avoid;
}
.btn,
#progress-section,
.export-buttons {
display: none;
}
.warning-banner {
border: 2px solid #f59e0b;
}
}
/* -------------------------------------------------------------------------- /* --------------------------------------------------------------------------
Metric Tooltips Metric Tooltips
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
.result-metric {
position: relative;
cursor: help;
}
.metric-tooltip { .metric-tooltip {
visibility: hidden; visibility: hidden;
opacity: 0; opacity: 0;
@ -1015,8 +637,319 @@ kbd {
color: var(--text-muted); color: var(--text-muted);
} }
/* Mobile: tap to show tooltip */ .pack-visualization {
margin-bottom: var(--space-xl);
}
.pack-grid {
display: flex;
flex-direction: column;
gap: var(--space-sm);
padding: var(--space-lg);
background: var(--bg-tertiary);
border-radius: var(--radius-md);
overflow-x: auto;
}
.pack-row {
display: flex;
gap: var(--space-sm);
align-items: center;
}
.pack-row-label {
min-width: 30px;
font-size: 0.75rem;
font-weight: 600;
color: var(--text-muted);
text-align: right;
}
.pack-cells {
display: flex;
gap: var(--space-xs);
}
.pack-cell {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-width: 70px;
padding: var(--space-sm);
background: var(--cell-mid);
border-radius: var(--radius-sm);
font-size: 0.7rem;
color: white;
text-align: center;
cursor: pointer;
transition: transform var(--transition-fast);
}
.pack-cell:hover {
transform: scale(1.05);
}
.pack-cell .cell-label {
font-weight: 600;
margin-bottom: 2px;
}
.pack-cell .cell-capacity {
opacity: 0.9;
}
.pack-cell .cell-ir {
opacity: 0.7;
font-size: 0.65rem;
}
/* Pack cell tooltips */
.pack-cell .tooltip {
visibility: hidden;
opacity: 0;
position: absolute;
bottom: 100%;
left: 50%;
transform: translateX(-50%);
margin-bottom: 8px;
padding: var(--space-sm) var(--space-md);
background: var(--bg-primary);
border: 1px solid var(--border-color);
border-radius: var(--radius-sm);
font-size: 0.75rem;
white-space: nowrap;
z-index: 100;
box-shadow: var(--shadow-md);
transition: opacity var(--transition-fast), visibility var(--transition-fast);
color: var(--text-primary);
}
.pack-cell .tooltip::after {
content: '';
position: absolute;
top: 100%;
left: 50%;
transform: translateX(-50%);
border: 6px solid transparent;
border-top-color: var(--border-color);
}
.pack-cell:hover .tooltip,
.pack-cell:focus .tooltip {
visibility: visible;
opacity: 1;
}
.tooltip-row {
display: flex;
justify-content: space-between;
gap: var(--space-md);
}
.tooltip-label {
color: var(--text-muted);
}
.tooltip-value {
color: var(--text-primary);
font-weight: 600;
}
.pack-legend {
display: flex;
justify-content: center;
gap: var(--space-lg);
margin-top: var(--space-md);
font-size: 0.75rem;
color: var(--text-secondary);
}
.legend-color {
display: inline-block;
width: 12px;
height: 12px;
border-radius: 2px;
margin-right: var(--space-xs);
vertical-align: middle;
}
.results-table-wrapper {
overflow-x: auto;
margin-bottom: var(--space-xl);
}
.results-table {
width: 100%;
border-collapse: collapse;
font-size: 0.875rem;
}
.results-table th,
.results-table td {
padding: var(--space-sm) var(--space-md);
text-align: left;
border-bottom: 1px solid var(--border-color);
}
.results-table th {
font-weight: 600;
color: var(--text-secondary);
background: var(--bg-tertiary);
}
.results-table td {
font-family: var(--font-mono);
}
.results-table .deviation-good {
color: var(--success);
}
.results-table .deviation-warning {
color: var(--warning);
}
.results-table .deviation-bad {
color: var(--danger);
}
.excluded-cells {
padding: var(--space-lg);
background: var(--bg-tertiary);
border-radius: var(--radius-md);
margin-bottom: var(--space-xl);
}
.excluded-cells h3 {
margin-top: 0;
}
.excluded-cells p {
margin: 0;
font-family: var(--font-mono);
font-size: 0.875rem;
color: var(--text-secondary);
}
.export-buttons {
display: flex;
flex-wrap: wrap;
gap: var(--space-sm);
justify-content: center;
}
footer {
text-align: center;
padding: var(--space-xl) 0;
font-size: 0.875rem;
color: var(--text-muted);
}
footer a {
color: var(--text-secondary);
text-decoration: none;
}
footer a:hover {
color: var(--accent);
}
.disclaimer {
margin-top: var(--space-sm);
font-size: 0.75rem;
}
dialog {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
max-width: 400px;
width: 90%;
padding: var(--space-xl);
background: var(--bg-secondary);
border: 1px solid var(--border-color);
border-radius: var(--radius-lg);
box-shadow: var(--shadow-lg);
color: var(--text-primary);
}
dialog::backdrop {
background: rgba(0, 0, 0, 0.7);
}
dialog h2 {
margin: 0 0 var(--space-lg);
}
.shortcuts-list {
display: grid;
grid-template-columns: auto 1fr;
gap: var(--space-sm) var(--space-lg);
margin-bottom: var(--space-xl);
}
.shortcuts-list dt {
font-weight: 500;
}
.shortcuts-list dd {
margin: 0;
color: var(--text-secondary);
}
kbd {
display: inline-block;
padding: 2px 6px;
font-size: 0.75rem;
font-family: var(--font-mono);
background: var(--bg-tertiary);
border: 1px solid var(--border-color);
border-radius: var(--radius-sm);
}
@media (max-width: 640px) { @media (max-width: 640px) {
.container {
padding: var(--space-md);
}
.card {
padding: var(--space-lg);
}
.logo h1 {
font-size: 1.25rem;
}
.config-grid,
.settings-grid {
grid-template-columns: 1fr;
}
.cell-input-header {
flex-direction: column;
align-items: flex-start;
}
.button-group {
width: 100%;
}
.button-group .btn {
flex: 1;
}
.results-summary {
grid-template-columns: repeat(2, 1fr);
}
.pack-cell {
min-width: 55px;
padding: var(--space-xs);
}
.metric-tooltip { .metric-tooltip {
width: 240px; width: 240px;
left: 0; left: 0;
@ -1027,3 +960,37 @@ kbd {
left: 20%; left: 20%;
} }
} }
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}
@media print {
body {
background: white;
color: black;
}
.card {
border: 1px solid #ccc;
box-shadow: none;
break-inside: avoid;
}
.btn,
#progress-section,
.export-buttons {
display: none;
}
.warning-banner {
border: 2px solid #f59e0b;
}
}

View File

@ -178,7 +178,7 @@
<li>Used cells may have hidden defects not detectable by capacity/IR testing</li> <li>Used cells may have hidden defects not detectable by capacity/IR testing</li>
<li>Internal resistance mismatch >20% can reduce cycle life by up to 40%</li> <li>Internal resistance mismatch >20% can reduce cycle life by up to 40%</li>
<li>Always use a BMS with cell-level monitoring and balancing</li> <li>Always use a BMS with cell-level monitoring and balancing</li>
<li>Use only same model of cells in a pack.</li> <li>Use only same model of cells in a pack</li>
<li>Never charge unattended; use fireproof storage</li> <li>Never charge unattended; use fireproof storage</li>
<li>Cells with significantly different ages may degrade unpredictably</li> <li>Cells with significantly different ages may degrade unpredictably</li>
</ul> </ul>

View File

@ -90,6 +90,47 @@ function formatNumber(num) {
return num.toLocaleString(); return num.toLocaleString();
} }
// =============================================================================
// Combination Calculator
// =============================================================================
function binomial(n, k) {
if (k > n) return 0;
if (k === 0 || k === n) return 1;
let result = 1;
for (let i = 0; i < k; i++) {
result = result * (n - i) / (i + 1);
}
return Math.round(result);
}
function calculateTotalCombinations(numCells, serial, parallel) {
const totalNeeded = serial * parallel;
if (numCells < totalNeeded) return 0;
let total = 1;
let remaining = numCells;
for (let i = 0; i < serial; i++) {
total *= binomial(remaining, parallel);
remaining -= parallel;
}
return total;
}
function updateMaxIterations() {
const serial = parseInt(DOM.cellsSerial.value) || 1;
const parallel = parseInt(DOM.cellsParallel.value) || 1;
const validCells = AppState.cells.filter(c => c.capacity && c.capacity > 0);
const totalCombinations = calculateTotalCombinations(validCells.length, serial, parallel);
// Set max iterations: use total combinations if reasonable, cap at 1,000,000
const suggested = Math.min(Math.max(totalCombinations, 1000), 1000000);
DOM.maxIterations.value = suggested;
}
// ============================================================================= // =============================================================================
// Configuration Management // Configuration Management
// ============================================================================= // =============================================================================
@ -101,6 +142,7 @@ function updateConfigDisplay() {
DOM.configDisplay.textContent = `${serial}S${parallel}P`; DOM.configDisplay.textContent = `${serial}S${parallel}P`;
DOM.totalCellsNeeded.textContent = total; DOM.totalCellsNeeded.textContent = total;
updateMatchingButtonState(); updateMatchingButtonState();
updateMaxIterations();
} }
// ============================================================================= // =============================================================================
@ -196,6 +238,8 @@ function updateCellStats() {
? `${Math.round(capacities.reduce((a, b) => a + b, 0) / capacities.length)} mAh` : '-'; ? `${Math.round(capacities.reduce((a, b) => a + b, 0) / capacities.length)} mAh` : '-';
DOM.statAvgIr.textContent = irs.length > 0 DOM.statAvgIr.textContent = irs.length > 0
? `${(irs.reduce((a, b) => a + b, 0) / irs.length).toFixed(1)}` : '-'; ? `${(irs.reduce((a, b) => a + b, 0) / irs.length).toFixed(1)}` : '-';
updateMaxIterations();
} }
function loadExampleData() { function loadExampleData() {

View File

@ -232,10 +232,14 @@ class ExhaustiveSearch {
: [[...this.cells]]; : [[...this.cells]];
for (const cellSubset of cellCombos) { for (const cellSubset of cellCombos) {
if (this.stopped) break; if (this.stopped) {
return this.returnBestResult(iteration, totalCombinations);
}
for (const partition of this.generatePartitions(cellSubset, this.parallel, this.serial)) { for (const partition of this.generatePartitions(cellSubset, this.parallel, this.serial)) {
if (this.stopped) break; if (this.stopped) {
return this.returnBestResult(iteration, totalCombinations);
}
const scoreResult = calculateScore(partition, this.capacityWeight, this.irWeight); const scoreResult = calculateScore(partition, this.capacityWeight, this.irWeight);
@ -247,7 +251,8 @@ class ExhaustiveSearch {
iteration++; iteration++;
this.stats.recordIteration(); this.stats.recordIteration();
if (iteration % (this.maxIterations * 0.01) === 0) { // Check frequently for stop and send progress updates every 100 iterations
if (iteration % 100 === 0) {
const stats = this.stats.getStats(iteration, Math.min(totalCombinations, this.maxIterations)); const stats = this.stats.getStats(iteration, Math.min(totalCombinations, this.maxIterations));
self.postMessage({ self.postMessage({
@ -265,12 +270,29 @@ class ExhaustiveSearch {
} }
if (iteration >= this.maxIterations) { if (iteration >= this.maxIterations) {
this.stopped = true; return this.returnBestResult(iteration, totalCombinations);
break;
} }
} }
} }
return this.returnBestResult(iteration, totalCombinations);
}
returnBestResult(iteration, totalCombinations) {
if (!this.bestSolution) {
// No solution found yet, create one from first cells
const config = [];
for (let i = 0; i < this.serial; i++) {
config.push(this.cells.slice(i * this.parallel, (i + 1) * this.parallel));
}
const scoreResult = calculateScore(config, this.capacityWeight, this.irWeight);
this.bestSolution = { config, ...scoreResult };
this.bestScore = scoreResult.score;
}
const usedLabels = new Set(this.bestSolution.config.flat().map(c => c.label));
const excludedCells = this.cells.filter(c => !usedLabels.has(c.label));
// Final progress update // Final progress update
const stats = this.stats.getStats(iteration, Math.min(totalCombinations, this.maxIterations)); const stats = this.stats.getStats(iteration, Math.min(totalCombinations, this.maxIterations));
self.postMessage({ self.postMessage({
@ -286,9 +308,6 @@ class ExhaustiveSearch {
} }
}); });
const usedLabels = new Set(this.bestSolution.config.flat().map(c => c.label));
const excludedCells = this.cells.filter(c => !usedLabels.has(c.label));
return { return {
configuration: this.bestSolution.config, configuration: this.bestSolution.config,
score: this.bestScore, score: this.bestScore,