diff --git a/lib/solvers/LongDistancePairSolver/LongDistancePairSolver.ts b/lib/solvers/LongDistancePairSolver/LongDistancePairSolver.ts index 9911d3949..5906f2077 100644 --- a/lib/solvers/LongDistancePairSolver/LongDistancePairSolver.ts +++ b/lib/solvers/LongDistancePairSolver/LongDistancePairSolver.ts @@ -1,4 +1,7 @@ -import { getConnectivityMapsFromInputProblem } from "lib/solvers/MspConnectionPairSolver/getConnectivityMapFromInputProblem" +import { + getConnectivityMapsFromInputProblem, + isGlobalNetHandledByLabels, +} from "lib/solvers/MspConnectionPairSolver/getConnectivityMapFromInputProblem" import type { MspConnectionPair } from "lib/solvers/MspConnectionPairSolver/MspConnectionPairSolver" import type { InputProblem, @@ -74,6 +77,8 @@ export class LongDistancePairSolver extends BaseSolver { const addedPairKeys = new Set() for (const netId of Object.keys(netConnMap.netMap)) { + if (isGlobalNetHandledByLabels(inputProblem, netConnMap, netId)) continue + const allPinIdsInNet = netConnMap.getIdsConnectedToNet(netId) if (allPinIdsInNet.length < 2) continue diff --git a/lib/solvers/MspConnectionPairSolver/MspConnectionPairSolver.ts b/lib/solvers/MspConnectionPairSolver/MspConnectionPairSolver.ts index 5aae38063..8bec9a5bc 100644 --- a/lib/solvers/MspConnectionPairSolver/MspConnectionPairSolver.ts +++ b/lib/solvers/MspConnectionPairSolver/MspConnectionPairSolver.ts @@ -6,7 +6,10 @@ import type { PinId, } from "lib/types/InputProblem" import { ConnectivityMap } from "connectivity-map" -import { getConnectivityMapsFromInputProblem } from "./getConnectivityMapFromInputProblem" +import { + getConnectivityMapsFromInputProblem, + isGlobalNetHandledByLabels, +} from "./getConnectivityMapFromInputProblem" import { getOrthogonalMinimumSpanningTree } from "./getMspConnectionPairsFromPins" import { doesPairCrossRestrictedCenterLines } from "./doesPairCrossRestrictedCenterLines" import type { GraphicsObject } from "graphics-debug" @@ -75,7 +78,12 @@ export class MspConnectionPairSolver extends BaseSolver { } } - this.queuedDcNetIds = Object.keys(netConnMap.netMap) + const directConnNetIds = new Set(Object.keys(directConnMap.netMap)) + this.queuedDcNetIds = Object.keys(netConnMap.netMap).filter( + (netId) => + directConnNetIds.has(netId) || + !isGlobalNetHandledByLabels(inputProblem, netConnMap, netId), + ) } override getConstructorParams(): ConstructorParameters< @@ -94,7 +102,10 @@ export class MspConnectionPairSolver extends BaseSolver { const dcNetId = this.queuedDcNetIds.shift()! - const allIds = this.globalConnMap.getIdsConnectedToNet(dcNetId) as string[] + const routeConnMap = this.dcConnMap.netMap[dcNetId] + ? this.dcConnMap + : this.globalConnMap + const allIds = routeConnMap.getIdsConnectedToNet(dcNetId) as string[] const directlyConnectedPins = allIds.filter((id) => !!this.pinMap[id]) if (directlyConnectedPins.length <= 1) { diff --git a/lib/solvers/MspConnectionPairSolver/getConnectivityMapFromInputProblem.ts b/lib/solvers/MspConnectionPairSolver/getConnectivityMapFromInputProblem.ts index d3a098c33..d741871af 100644 --- a/lib/solvers/MspConnectionPairSolver/getConnectivityMapFromInputProblem.ts +++ b/lib/solvers/MspConnectionPairSolver/getConnectivityMapFromInputProblem.ts @@ -1,6 +1,31 @@ import { ConnectivityMap } from "connectivity-map" import type { InputProblem } from "lib/types/InputProblem" +export const getNetConnectionIdsWithLabelOrientations = ( + inputProblem: InputProblem, +): Set => { + const netIds = new Set() + for (const netConn of inputProblem.netConnections) { + if (inputProblem.availableNetLabelOrientations[netConn.netId]?.length) { + netIds.add(netConn.netId) + } + } + return netIds +} + +export const isGlobalNetHandledByLabels = ( + inputProblem: InputProblem, + netConnMap: ConnectivityMap, + netId: string, +): boolean => { + const netIdsWithLabels = + getNetConnectionIdsWithLabelOrientations(inputProblem) + if (netIdsWithLabels.has(netId)) return true + + const allIds = netConnMap.getIdsConnectedToNet(netId) as string[] + return allIds.some((id) => netIdsWithLabels.has(id)) +} + export const getConnectivityMapsFromInputProblem = ( inputProblem: InputProblem, ): { directConnMap: ConnectivityMap; netConnMap: ConnectivityMap } => { @@ -14,7 +39,14 @@ export const getConnectivityMapsFromInputProblem = ( ]) } - const netConnMap = new ConnectivityMap(directConnMap.netMap) + const netConnMap = new ConnectivityMap( + Object.fromEntries( + Object.entries(directConnMap.netMap).map(([netId, ids]) => [ + netId, + [...ids], + ]), + ), + ) for (const netConn of inputProblem.netConnections) { netConnMap.addConnections([[netConn.netId, ...netConn.pinIds]]) diff --git a/tests/examples/__snapshots__/example01.snap.svg b/tests/examples/__snapshots__/example01.snap.svg index 2614ba80f..4829176e3 100644 --- a/tests/examples/__snapshots__/example01.snap.svg +++ b/tests/examples/__snapshots__/example01.snap.svg @@ -2,106 +2,111 @@ +x-" data-x="-0.8" data-y="0.2" cx="422.5742574257426" cy="289.44950495049505" r="3" fill="hsl(319, 100%, 50%, 0.8)" /> +x-" data-x="-0.8" data-y="0" cx="422.5742574257426" cy="311.62772277227725" r="3" fill="hsl(320, 100%, 50%, 0.8)" /> +x-" data-x="-0.8" data-y="-0.2" cx="422.5742574257426" cy="333.80594059405945" r="3" fill="hsl(321, 100%, 50%, 0.8)" /> +x+" data-x="0.8" data-y="-0.2" cx="600" cy="333.80594059405945" r="3" fill="hsl(322, 100%, 50%, 0.8)" /> +x+" data-x="0.8" data-y="0" cx="600" cy="311.62772277227725" r="3" fill="hsl(323, 100%, 50%, 0.8)" /> +x+" data-x="0.8" data-y="0.2" cx="600" cy="289.44950495049505" r="3" fill="hsl(324, 100%, 50%, 0.8)" /> +y+" data-x="-2" data-y="0.5" cx="289.50495049504957" cy="256.1821782178218" r="3" fill="hsl(121, 100%, 50%, 0.8)" /> +y-" data-x="-2" data-y="-0.5" cx="289.50495049504957" cy="367.0732673267327" r="3" fill="hsl(122, 100%, 50%, 0.8)" /> +y+" data-x="-4" data-y="0.5" cx="67.72277227722776" cy="256.1821782178218" r="3" fill="hsl(2, 100%, 50%, 0.8)" /> +y-" data-x="-4" data-y="-0.5" cx="67.72277227722776" cy="367.0732673267327" r="3" fill="hsl(3, 100%, 50%, 0.8)" /> - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + +globalConnNetId: connectivity_net0" data-x="-1.1" data-y="0.42500000000000016" x="378.21782178217825" y="239.54851485148515" width="22.178217821782198" height="49.9009900990099" fill="#ef444466" stroke="#ef4444" stroke-width="0.009017857142857143" /> +globalConnNetId: connectivity_net1" data-x="-1.5" data-y="0" x="320" y="300.5386138613862" width="49.90099009900996" height="22.17821782178214" fill="hsl(40, 100%, 50%, 0.35)" stroke="black" stroke-width="0.009017857142857143" /> + + + + + + +globalConnNetId: connectivity_net2" data-x="-2" data-y="-0.726" x="278.41584158415844" y="367.1841584158416" width="22.178217821782198" height="49.90099009900996" fill="#00000066" stroke="#000000" stroke-width="0.009017857142857143" /> - + - + - + - + - + + + + @@ -114,10 +112,7 @@ orientation: x+" data-x="1.757519574999999" data-y="0.85" cx="547.3539750075635" - - - - + @@ -125,6 +120,12 @@ orientation: x+" data-x="1.757519574999999" data-y="0.85" cx="547.3539750075635" + + + + + + @@ -136,28 +137,27 @@ orientation: x+" data-x="1.757519574999999" data-y="0.85" cx="547.3539750075635" +globalConnNetId: connectivity_net0" data-x="-2.3148566499999994" data-y="0.9762093000000004" x="59.22281274267999" y="270.2760341291854" width="23.398233329971788" height="52.64602499243642" fill="#ef444466" stroke="#ef4444" stroke-width="0.00854765388392857" /> + + + +globalConnNetId: connectivity_net0" data-x="1.751" data-y="-0.224" x="534.8921256572664" y="410.68992036019574" width="23.398233329971845" height="52.64602499243648" fill="#ef444466" stroke="#ef4444" stroke-width="0.00854765388392857" /> +globalConnNetId: connectivity_net0" data-x="1.7580660749999977" data-y="2.5285814" x="535.7187940151516" y="88.66221107549416" width="23.39823332997173" height="52.64602499243642" fill="#ef444466" stroke="#ef4444" stroke-width="0.00854765388392857" /> +globalConnNetId: connectivity_net1" data-x="-2.31430995" data-y="-0.9762093000000004" x="59.28677181348735" y="498.6917639320694" width="23.398233329971788" height="52.64602499243642" fill="#00000066" stroke="#000000" stroke-width="0.00854765388392857" /> +globalConnNetId: connectivity_net2" data-x="1.982519574999999" data-y="0.85" x="547.3539750075635" y="299.6653032094798" width="52.64602499243654" height="23.39823332997173" fill="hsl(40, 100%, 50%, 0.35)" stroke="black" stroke-width="0.00854765388392857" />