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
@@ -0,0 +1,53 @@
/**
* Specialized solver that extends SingleInnerPartitionPackingSolver
* but applies custom horizontal layout for decoupling capacitors.
*/

import { SingleInnerPartitionPackingSolver } from "./SingleInnerPartitionPackingSolver"
import type { PartitionInputProblem, ChipPin, PinId } from "../../types/InputProblem"

export class DecouplingCapsPackingSolver extends SingleInnerPartitionPackingSolver {
constructor(params: {
partitionInputProblem: PartitionInputProblem
pinIdToStronglyConnectedPins?: Record<PinId, ChipPin[]>
}) {
super(params)
}

override createLayoutFromPackingResult(
packedComponents: any,
): any {
// Custom layout: arrange caps in a clean horizontal row
const chips = Object.entries(this.partitionInputProblem.chipMap)
const chipPlacements: Record<string, any> = {}

// Get gap setting
const gap = this.partitionInputProblem.decouplingCapsGap ?? 0.05

// Sort chips by size (largest first) for better stability
const sortedChips = chips.sort((a, b) => {
const sizeA = (a[1]?.size?.x ?? 0) * (a[1]?.size?.y ?? 0)
const sizeB = (b[1]?.size?.x ?? 0) * (b[1]?.size?.y ?? 0)
return sizeB - sizeA
})

// Position each chip in a horizontal row
let currentX = 0
for (const [chipId, chip] of sortedChips) {
const size = chip?.size || { x: 0.1, y: 0.1 }

chipPlacements[chipId] = {
x: currentX,
y: 0,
ccwRotationDegrees: 0,
}

currentX += size.x + gap
}

return {
chipPlacements,
groupPlacements: {},
}
}
}
17 changes: 13 additions & 4 deletions lib/solvers/PackInnerPartitionsSolver/PackInnerPartitionsSolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { BaseSolver } from "../BaseSolver"
import type { ChipPin, InputProblem, PinId } from "../../types/InputProblem"
import type { OutputLayout } from "../../types/OutputLayout"
import { SingleInnerPartitionPackingSolver } from "./SingleInnerPartitionPackingSolver"
import { DecouplingCapsPackingSolver } from "./DecouplingCapsPackingSolver"
import { stackGraphicsHorizontally } from "graphics-debug"

export type PackedPartition = {
Expand Down Expand Up @@ -45,10 +46,18 @@ export class PackInnerPartitionsSolver extends BaseSolver {
// If no active solver, create one for the current partition
if (!this.activeSolver) {
const currentPartition = this.partitions[this.currentPartitionIndex]!
this.activeSolver = new SingleInnerPartitionPackingSolver({
partitionInputProblem: currentPartition,
pinIdToStronglyConnectedPins: this.pinIdToStronglyConnectedPins,
})

// Use specialized solver for decoupling_caps partitions
if (currentPartition.partitionType === "decoupling_caps") {
this.activeSolver = new DecouplingCapsPackingSolver({
partitionInputProblem: currentPartition,
})
} else {
this.activeSolver = new SingleInnerPartitionPackingSolver({
partitionInputProblem: currentPartition,
pinIdToStronglyConnectedPins: this.pinIdToStronglyConnectedPins,
})
}
this.activeSubSolver = this.activeSolver
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export class SingleInnerPartitionPackingSolver extends BaseSolver {

constructor(params: {
partitionInputProblem: PartitionInputProblem
pinIdToStronglyConnectedPins: Record<PinId, ChipPin[]>
pinIdToStronglyConnectedPins?: Record<PinId, ChipPin[]>
}) {
super()
this.partitionInputProblem = params.partitionInputProblem
this.pinIdToStronglyConnectedPins = params.pinIdToStronglyConnectedPins
this.pinIdToStronglyConnectedPins = params.pinIdToStronglyConnectedPins || {}
}

override _step() {
Expand Down Expand Up @@ -144,6 +144,28 @@ export class SingleInnerPartitionPackingSolver extends BaseSolver {
private createLayoutFromPackingResult(
packedComponents: PackSolver2["packedComponents"],
): OutputLayout {
// Custom layout for decoupling_caps: arrange in horizontal row
if (this.partitionInputProblem.partitionType === "decoupling_caps") {
const chips = Object.entries(this.partitionInputProblem.chipMap)
const chipPlacements: Record<string, Placement> = {}
const gap = this.partitionInputProblem.decouplingCapsGap ?? 0.05

// Sort by size (largest first)
const sorted = chips.sort((a, b) => {
const areaA = (a[1]?.size?.x ?? 0) * (a[1]?.size?.y ?? 0)
const areaB = (b[1]?.size?.x ?? 0) * (b[1]?.size?.y ?? 0)
return areaB - areaA
})

let currentX = 0
for (const [chipId, chip] of sorted) {
const size = chip?.size || { x: 0.1, y: 0.1 }
chipPlacements[chipId] = { x: currentX, y: 0, ccwRotationDegrees: 0 }
currentX += size.x + gap
}
return { chipPlacements, groupPlacements: {} }
}

const chipPlacements: Record<string, Placement> = {}

for (const packedComponent of packedComponents) {
Expand Down
Loading