Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ export class SingleInnerPartitionPackingSolver extends BaseSolver {
}

override _step() {
// For decoupling cap partitions, use a clean linear row layout
// instead of the general PackSolver2 to avoid messy overlapping
if (this.partitionInputProblem.partitionType === "decoupling_caps") {
this.layout = this.createLinearDecouplingCapLayout()
this.solved = true
return
}

// Initialize PackSolver2 if not already created
if (!this.activeSubSolver) {
const packInput = this.createPackInput()
Expand All @@ -64,6 +72,46 @@ export class SingleInnerPartitionPackingSolver extends BaseSolver {
}
}

/**
* Arranges decoupling capacitors in a clean horizontal row centered at
* the origin. Chips are sorted by chipId for deterministic, reproducible
* ordering and spaced evenly using decouplingCapsGap (falling back to
* chipGap when not set).
*/
private createLinearDecouplingCapLayout(): OutputLayout {
const chips = Object.entries(this.partitionInputProblem.chipMap).sort(
([a], [b]) => a.localeCompare(b),
)

const gap =
this.partitionInputProblem.decouplingCapsGap ??
this.partitionInputProblem.chipGap

// Calculate total width of the row
const totalChipWidth = chips.reduce((sum, [, chip]) => sum + chip.size.x, 0)
const totalGapWidth = Math.max(0, chips.length - 1) * gap
const totalWidth = totalChipWidth + totalGapWidth

// Place chips left-to-right, centered around x=0
const chipPlacements: Record<string, Placement> = {}
let currentX = -totalWidth / 2

for (const [chipId, chip] of chips) {
currentX += chip.size.x / 2
chipPlacements[chipId] = {
x: currentX,
y: 0,
ccwRotationDegrees: 0,
}
currentX += chip.size.x / 2 + gap
}

return {
chipPlacements,
groupPlacements: {},
}
}

private createPackInput(): PackInput {
// Fall back to filtered mapping (weak + strong)
const pinToNetworkMap = createFilteredNetworkMapping({
Expand Down
Loading
Loading