@tscircuit/hypergraph 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +23 -1
- package/dist/index.js +58 -15
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,11 @@ type RegionPort = {
|
|
|
19
19
|
* ports that are likely to block off connections
|
|
20
20
|
*/
|
|
21
21
|
ripCount?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Optionally can be used by solvers to keep track of the distance to
|
|
24
|
+
* each end era.
|
|
25
|
+
*/
|
|
26
|
+
distanceToEndMap?: Record<RegionId, number>;
|
|
22
27
|
};
|
|
23
28
|
type Region = {
|
|
24
29
|
regionId: RegionId;
|
|
@@ -345,11 +350,26 @@ declare class HyperGraphSolver<RegionType extends Region = Region, RegionPortTyp
|
|
|
345
350
|
* can also help avoid loops
|
|
346
351
|
*/
|
|
347
352
|
routeSolvedHook(solvedRoute: SolvedRoute): void;
|
|
353
|
+
/**
|
|
354
|
+
* OPTIONALLY OVERRIDE THIS
|
|
355
|
+
*
|
|
356
|
+
* You can override this to perform actions when a new route begins, e.g.
|
|
357
|
+
* you may want to log or track which connection is being processed.
|
|
358
|
+
*/
|
|
359
|
+
routeStartedHook(connection: Connection): void;
|
|
348
360
|
ripSolvedRoute(solvedRoute: SolvedRoute): void;
|
|
349
361
|
beginNewConnection(): void;
|
|
350
362
|
_step(): void;
|
|
351
363
|
}
|
|
352
364
|
|
|
365
|
+
declare const JUMPER_GRAPH_SOLVER_DEFAULTS: {
|
|
366
|
+
portUsagePenalty: number;
|
|
367
|
+
portUsagePenaltySq: number;
|
|
368
|
+
crossingPenalty: number;
|
|
369
|
+
crossingPenaltySq: number;
|
|
370
|
+
ripCost: number;
|
|
371
|
+
greedyMultiplier: number;
|
|
372
|
+
};
|
|
353
373
|
declare class JumperGraphSolver extends HyperGraphSolver<JRegion, JPort> {
|
|
354
374
|
UNIT_OF_COST: string;
|
|
355
375
|
portUsagePenalty: number;
|
|
@@ -368,11 +388,13 @@ declare class JumperGraphSolver extends HyperGraphSolver<JRegion, JPort> {
|
|
|
368
388
|
baseMaxIterations?: number;
|
|
369
389
|
additionalMaxIterationsPerConnection?: number;
|
|
370
390
|
});
|
|
391
|
+
private populateDistanceToEndMaps;
|
|
371
392
|
estimateCostToEnd(port: JPort): number;
|
|
372
393
|
getPortUsagePenalty(port: JPort): number;
|
|
373
394
|
computeIncreasedRegionCostIfPortsAreUsed(region: JRegion, port1: JPort, port2: JPort): number;
|
|
374
395
|
getRipsRequiredForPortUsage(region: JRegion, port1: JPort, port2: JPort): RegionPortAssignment[];
|
|
375
396
|
routeSolvedHook(solvedRoute: SolvedRoute): void;
|
|
397
|
+
routeStartedHook(connection: Connection): void;
|
|
376
398
|
visualize(): GraphicsObject;
|
|
377
399
|
}
|
|
378
400
|
|
|
@@ -386,4 +408,4 @@ declare const applyTransformToGraph: (graph: JumperGraph, matrix: Matrix) => Jum
|
|
|
386
408
|
*/
|
|
387
409
|
declare const rotateGraph90Degrees: (graph: JumperGraph) => JumperGraph;
|
|
388
410
|
|
|
389
|
-
export { type Candidate, type Connection, type ConnectionId, type GScore, type GraphEdgeId, type HyperGraph, HyperGraphSolver, type JPort, type JRegion, type JumperGraph, JumperGraphSolver, type JumperGraphWithConnections, type NetworkId, type PortAssignment, type PortId, type Region, type RegionId, type RegionPort, type RegionPortAssignment, type SerializedConnection, type SerializedGraphPort, type SerializedGraphRegion, type SerializedHyperGraph, type SerializedRegionPortAssignment, type SolvedRoute, type XYConnection, applyTransformToGraph, createGraphWithConnectionsFromBaseGraph, generateJumperGrid, generateJumperX4Grid, rotateGraph90Degrees };
|
|
411
|
+
export { type Candidate, type Connection, type ConnectionId, type GScore, type GraphEdgeId, type HyperGraph, HyperGraphSolver, type JPort, type JRegion, JUMPER_GRAPH_SOLVER_DEFAULTS, type JumperGraph, JumperGraphSolver, type JumperGraphWithConnections, type NetworkId, type PortAssignment, type PortId, type Region, type RegionId, type RegionPort, type RegionPortAssignment, type SerializedConnection, type SerializedGraphPort, type SerializedGraphRegion, type SerializedHyperGraph, type SerializedRegionPortAssignment, type SolvedRoute, type XYConnection, applyTransformToGraph, createGraphWithConnectionsFromBaseGraph, generateJumperGrid, generateJumperX4Grid, rotateGraph90Degrees };
|
package/dist/index.js
CHANGED
|
@@ -1935,6 +1935,14 @@ var HyperGraphSolver = class extends BaseSolver {
|
|
|
1935
1935
|
*/
|
|
1936
1936
|
routeSolvedHook(solvedRoute) {
|
|
1937
1937
|
}
|
|
1938
|
+
/**
|
|
1939
|
+
* OPTIONALLY OVERRIDE THIS
|
|
1940
|
+
*
|
|
1941
|
+
* You can override this to perform actions when a new route begins, e.g.
|
|
1942
|
+
* you may want to log or track which connection is being processed.
|
|
1943
|
+
*/
|
|
1944
|
+
routeStartedHook(connection) {
|
|
1945
|
+
}
|
|
1938
1946
|
ripSolvedRoute(solvedRoute) {
|
|
1939
1947
|
for (const port of solvedRoute.path.map((candidate) => candidate.port)) {
|
|
1940
1948
|
port.ripCount = (port.ripCount ?? 0) + 1;
|
|
@@ -1954,6 +1962,7 @@ var HyperGraphSolver = class extends BaseSolver {
|
|
|
1954
1962
|
this.currentEndRegion = this.currentConnection.endRegion;
|
|
1955
1963
|
this.candidateQueue = new PriorityQueue();
|
|
1956
1964
|
this.visitedPointsForCurrentConnection.clear();
|
|
1965
|
+
this.routeStartedHook(this.currentConnection);
|
|
1957
1966
|
for (const port of this.currentConnection.startRegion.ports) {
|
|
1958
1967
|
this.candidateQueue.enqueue({
|
|
1959
1968
|
port,
|
|
@@ -2212,13 +2221,6 @@ var visualizeJumperGraphSolver = (solver) => {
|
|
|
2212
2221
|
return graphics;
|
|
2213
2222
|
};
|
|
2214
2223
|
|
|
2215
|
-
// node_modules/@tscircuit/math-utils/dist/chunk-EFLPMB4J.js
|
|
2216
|
-
function distance(p1, p2) {
|
|
2217
|
-
const dx = p1.x - p2.x;
|
|
2218
|
-
const dy = p1.y - p2.y;
|
|
2219
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
2220
|
-
}
|
|
2221
|
-
|
|
2222
2224
|
// lib/JumperGraphSolver/perimeterChordUtils.ts
|
|
2223
2225
|
function perimeterT(p, xmin, xmax, ymin, ymax) {
|
|
2224
2226
|
const W = xmax - xmin;
|
|
@@ -2327,18 +2329,26 @@ function computeCrossingAssignments(region, port1, port2) {
|
|
|
2327
2329
|
}
|
|
2328
2330
|
|
|
2329
2331
|
// lib/JumperGraphSolver/JumperGraphSolver.ts
|
|
2332
|
+
var JUMPER_GRAPH_SOLVER_DEFAULTS = {
|
|
2333
|
+
portUsagePenalty: 0.06393718451067248,
|
|
2334
|
+
portUsagePenaltySq: 0.06194817180037216,
|
|
2335
|
+
crossingPenalty: 6.0761550028071145,
|
|
2336
|
+
crossingPenaltySq: 0.1315528159128946,
|
|
2337
|
+
ripCost: 40.00702225250195,
|
|
2338
|
+
greedyMultiplier: 0.4316469416682083
|
|
2339
|
+
};
|
|
2330
2340
|
var JumperGraphSolver = class extends HyperGraphSolver {
|
|
2331
2341
|
UNIT_OF_COST = "distance";
|
|
2332
|
-
portUsagePenalty =
|
|
2333
|
-
portUsagePenaltySq =
|
|
2334
|
-
crossingPenalty =
|
|
2335
|
-
crossingPenaltySq =
|
|
2336
|
-
ripCost =
|
|
2342
|
+
portUsagePenalty = JUMPER_GRAPH_SOLVER_DEFAULTS.portUsagePenalty;
|
|
2343
|
+
portUsagePenaltySq = JUMPER_GRAPH_SOLVER_DEFAULTS.portUsagePenaltySq;
|
|
2344
|
+
crossingPenalty = JUMPER_GRAPH_SOLVER_DEFAULTS.crossingPenalty;
|
|
2345
|
+
crossingPenaltySq = JUMPER_GRAPH_SOLVER_DEFAULTS.crossingPenaltySq;
|
|
2346
|
+
ripCost = JUMPER_GRAPH_SOLVER_DEFAULTS.ripCost;
|
|
2337
2347
|
baseMaxIterations = 4e3;
|
|
2338
|
-
additionalMaxIterationsPerConnection =
|
|
2348
|
+
additionalMaxIterationsPerConnection = 4e3;
|
|
2339
2349
|
constructor(input) {
|
|
2340
2350
|
super({
|
|
2341
|
-
greedyMultiplier:
|
|
2351
|
+
greedyMultiplier: JUMPER_GRAPH_SOLVER_DEFAULTS.greedyMultiplier,
|
|
2342
2352
|
rippingEnabled: true,
|
|
2343
2353
|
...input
|
|
2344
2354
|
});
|
|
@@ -2348,9 +2358,39 @@ var JumperGraphSolver = class extends HyperGraphSolver {
|
|
|
2348
2358
|
this.baseMaxIterations = input.baseMaxIterations ?? this.baseMaxIterations;
|
|
2349
2359
|
this.additionalMaxIterationsPerConnection = input.additionalMaxIterationsPerConnection ?? this.additionalMaxIterationsPerConnection;
|
|
2350
2360
|
this.MAX_ITERATIONS = this.baseMaxIterations + input.inputConnections.length * this.additionalMaxIterationsPerConnection;
|
|
2361
|
+
this.populateDistanceToEndMaps();
|
|
2362
|
+
}
|
|
2363
|
+
populateDistanceToEndMaps() {
|
|
2364
|
+
const endRegions = new Set(this.connections.map((c) => c.endRegion));
|
|
2365
|
+
for (const endRegion of endRegions) {
|
|
2366
|
+
const regionDistanceMap = /* @__PURE__ */ new Map();
|
|
2367
|
+
const queue = [];
|
|
2368
|
+
regionDistanceMap.set(endRegion.regionId, 0);
|
|
2369
|
+
queue.push({ region: endRegion, distance: 0 });
|
|
2370
|
+
while (queue.length > 0) {
|
|
2371
|
+
const { region, distance: dist } = queue.shift();
|
|
2372
|
+
for (const port of region.ports) {
|
|
2373
|
+
const otherRegion = port.region1 === region ? port.region2 : port.region1;
|
|
2374
|
+
if (!regionDistanceMap.has(otherRegion.regionId)) {
|
|
2375
|
+
regionDistanceMap.set(otherRegion.regionId, dist + 1);
|
|
2376
|
+
queue.push({ region: otherRegion, distance: dist + 1 });
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2380
|
+
for (const port of this.graph.ports) {
|
|
2381
|
+
if (!port.distanceToEndMap) {
|
|
2382
|
+
port.distanceToEndMap = {};
|
|
2383
|
+
}
|
|
2384
|
+
const d1 = regionDistanceMap.get(port.region1.regionId) ?? Infinity;
|
|
2385
|
+
const d2 = regionDistanceMap.get(port.region2.regionId) ?? Infinity;
|
|
2386
|
+
port.distanceToEndMap[endRegion.regionId] = Math.min(d1, d2);
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2351
2389
|
}
|
|
2352
2390
|
estimateCostToEnd(port) {
|
|
2353
|
-
|
|
2391
|
+
const endRegionId = this.currentEndRegion.regionId;
|
|
2392
|
+
const hopDistance = port.distanceToEndMap[endRegionId];
|
|
2393
|
+
return hopDistance;
|
|
2354
2394
|
}
|
|
2355
2395
|
getPortUsagePenalty(port) {
|
|
2356
2396
|
const ripCount = port.ripCount ?? 0;
|
|
@@ -2368,12 +2408,15 @@ var JumperGraphSolver = class extends HyperGraphSolver {
|
|
|
2368
2408
|
}
|
|
2369
2409
|
routeSolvedHook(solvedRoute) {
|
|
2370
2410
|
}
|
|
2411
|
+
routeStartedHook(connection) {
|
|
2412
|
+
}
|
|
2371
2413
|
visualize() {
|
|
2372
2414
|
return visualizeJumperGraphSolver(this);
|
|
2373
2415
|
}
|
|
2374
2416
|
};
|
|
2375
2417
|
export {
|
|
2376
2418
|
HyperGraphSolver,
|
|
2419
|
+
JUMPER_GRAPH_SOLVER_DEFAULTS,
|
|
2377
2420
|
JumperGraphSolver,
|
|
2378
2421
|
applyTransformToGraph,
|
|
2379
2422
|
createGraphWithConnectionsFromBaseGraph,
|