Skip to content
Closed
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 @@ -56,7 +56,7 @@ export class HgPortPointPathingSolver extends HyperGraphSolver<
this.totalRipCount = 0
if (params.weights.MAX_ITERATIONS_PER_PATH > 0) {
this.MAX_ITERATIONS =
params.weights.MAX_ITERATIONS_PER_PATH * params.effort
params.weights.MAX_ITERATIONS_PER_PATH * (params.effort ?? 1)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export interface HgPortPointPathingSolverParams {
colorMap?: Record<string, string>
inputSolvedRoutes?: SolvedRoutesHg[]
layerCount: number
effort: number
effort?: number
preserveTerminalPcbPortIds?: boolean
minViaPadDiameter?: number
flags: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ const DUPLICATE_PORT_TRAVERSAL_PENALTY = 150
const DEFAULT_CRAMPED_PORT_TRAVERSAL_PENALTY = 150
const MAX_CONNECTIONS_FOR_DUPLICATE_CONGESTED_PORT_PREPASS = 180

const getEffortScale = (effort: number) => Math.max(effort, 1e-2)
export const getEffortScale = (effort?: number) =>
Math.max(Number.isFinite(effort) ? (effort as number) : 1, 1e-2)

const getTinyViaSizeOptions = (
minViaPadDiameter?: number,
Expand All @@ -139,7 +140,7 @@ const getTinyViaSizeOptions = (
: {}

const getTinyHyperGraphSolveGraphOptions = (
effort: number,
effort?: number,
minViaPadDiameter?: number,
): TinyHyperGraphSolverOptions => {
const effortScale = getEffortScale(effort)
Expand All @@ -153,7 +154,7 @@ const getTinyHyperGraphSolveGraphOptions = (
}

const getTinyHyperGraphSectionSolverOptions = (
effort: number,
effort?: number,
minViaPadDiameter?: number,
): TinyHyperGraphSectionSolverOptions => {
const effortScale = getEffortScale(effort)
Expand All @@ -168,7 +169,7 @@ const getTinyHyperGraphSectionSolverOptions = (

const getTinyHyperGraphPipelineInput = (
serializedHyperGraph: SerializedHyperGraph,
effort: number,
effort?: number,
minViaPadDiameter?: number,
): TinyHyperGraphSectionPipelineInput => ({
serializedHyperGraph,
Expand Down
15 changes: 15 additions & 0 deletions tests/get-effort-scale.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect, test } from "bun:test"
import { getEffortScale } from "../lib/solvers/PortPointPathingSolver/tinyhypergraph/TinyHypergraphPortPointPathingSolver"

test("getEffortScale handles undefined and numeric values correctly", () => {
// undefined should fallback to 1
expect(getEffortScale(undefined)).toBe(1)
// NaN should fallback to 1
expect(getEffortScale(Number.NaN)).toBe(1)
// Normal effort value
expect(getEffortScale(2)).toBe(2)
// Fractional effort value above minimum
expect(getEffortScale(0.5)).toBe(0.5)
// Very small effort should be floored at 0.01 (1e-2)
expect(getEffortScale(0.001)).toBe(0.01)
})
Loading