@tscircuit/capacity-autorouter 0.0.62 → 0.0.64

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 CHANGED
@@ -978,7 +978,7 @@ declare class SingleHighDensityRouteStitchSolver extends BaseSolver {
978
978
  };
979
979
  colorMap: Record<string, string>;
980
980
  constructor(opts: {
981
- connectionName?: string;
981
+ connectionName: string;
982
982
  hdRoutes: HighDensityIntraNodeRoute$1[];
983
983
  start: {
984
984
  x: number;
@@ -991,6 +991,8 @@ declare class SingleHighDensityRouteStitchSolver extends BaseSolver {
991
991
  z: number;
992
992
  };
993
993
  colorMap?: Record<string, string>;
994
+ defaultTraceThickness?: number;
995
+ defaultViaDiameter?: number;
994
996
  });
995
997
  /**
996
998
  * Scan `remainingHdRoutes` and find a route that has **one** end that is not
@@ -1025,6 +1027,8 @@ declare class MultipleHighDensityRouteStitchSolver extends BaseSolver {
1025
1027
  activeSolver: SingleHighDensityRouteStitchSolver | null;
1026
1028
  mergedHdRoutes: HighDensityIntraNodeRoute$1[];
1027
1029
  colorMap: Record<string, string>;
1030
+ defaultTraceThickness: number;
1031
+ defaultViaDiameter: number;
1028
1032
  constructor(opts: {
1029
1033
  connections: SimpleRouteConnection[];
1030
1034
  hdRoutes: HighDensityIntraNodeRoute$1[];
@@ -1247,6 +1251,8 @@ interface CacheProvider {
1247
1251
  isSyncCache: boolean;
1248
1252
  cacheHits: number;
1249
1253
  cacheMisses: number;
1254
+ cacheHitsByPrefix: Record<string, number>;
1255
+ cacheMissesByPrefix: Record<string, number>;
1250
1256
  getCachedSolutionSync(cacheKey: string): any;
1251
1257
  getCachedSolution(cacheKey: string): Promise<any>;
1252
1258
  setCachedSolutionSync(cacheKey: string, cachedSolution: any): void;
@@ -1254,6 +1260,29 @@ interface CacheProvider {
1254
1260
  getAllCacheKeys(): string[];
1255
1261
  clearCache(): void;
1256
1262
  }
1263
+ interface CachableSolver<CacheToSolveSpaceTransform = any, CachedSolution = any> {
1264
+ cacheHit: boolean;
1265
+ hasAttemptedToUseCache: boolean;
1266
+ cacheProvider: CacheProvider | null;
1267
+ cacheKey?: string;
1268
+ cacheToSolveSpaceTransform?: CacheToSolveSpaceTransform;
1269
+ /**
1270
+ * Processes solver inputs and constructs a cacheKey and a cacheToSolveSpaceTransform
1271
+ * which gives the necessary information to convert a cached solution into a valid
1272
+ * solution for this solver. For example, the cacheKey may be translation-invariant, so
1273
+ * any cachedSolution would not be translated properly for this solver. The cacheToSolveSpaceTransform
1274
+ * tells you how to convert from the cache space (translation-invarant) to the correct
1275
+ * space for this solver. It can also contain information about how cache ids map to
1276
+ * ids for the solver
1277
+ **/
1278
+ computeCacheKeyAndTransform(): {
1279
+ cacheKey: string;
1280
+ cacheToSolveSpaceTransform: CacheToSolveSpaceTransform;
1281
+ };
1282
+ applyCachedSolution(cachedSolution: CachedSolution): void;
1283
+ attemptToUseCacheSync(): boolean;
1284
+ saveToCacheSync(): void;
1285
+ }
1257
1286
 
1258
1287
  declare class UnravelMultiSectionSolver extends BaseSolver {
1259
1288
  nodeMap: Map<CapacityMeshNodeId, CapacityMeshNode>;
@@ -1416,6 +1445,7 @@ interface CapacityPathingSingleSectionPathingSolverParams {
1416
1445
  }>;
1417
1446
  colorMap?: Record<string, string>;
1418
1447
  centerNodeId: string;
1448
+ nodeMap?: Map<CapacityMeshNodeId, CapacityMeshNode>;
1419
1449
  nodeEdgeMap?: Map<CapacityMeshNodeId, CapacityMeshEdge[]>;
1420
1450
  hyperParameters?: CpssPathingSolverHyperParameters;
1421
1451
  }
@@ -1433,7 +1463,9 @@ declare class CapacityPathingSingleSectionSolver extends BaseSolver {
1433
1463
  nodeEdgeMap: Map<CapacityMeshNodeId, CapacityMeshEdge[]>;
1434
1464
  colorMap: Record<string, string>;
1435
1465
  usedNodeCapacityMap: Map<CapacityMeshNodeId, number>;
1466
+ totalNodeCapacityMap: Map<CapacityMeshNodeId, number>;
1436
1467
  centerNodeId: string;
1468
+ private currentSectionScore;
1437
1469
  MAX_CANDIDATES_IN_MEMORY: number;
1438
1470
  currentConnectionIndex: number;
1439
1471
  candidates?: Array<Candidate> | null;
@@ -1458,6 +1490,7 @@ declare class CapacityPathingSingleSectionSolver extends BaseSolver {
1458
1490
  isConnectedToEndGoal(node: CapacityMeshNode, endGoal: CapacityMeshNode): boolean;
1459
1491
  doesNodeHaveCapacityForTrace(node: CapacityMeshNode, prevNode: CapacityMeshNode | null): boolean;
1460
1492
  reduceCapacityAlongPath(path: CapacityMeshNode[]): void;
1493
+ getSolvedSectionScore(): number;
1461
1494
  _step(): void;
1462
1495
  computeProgress(): number;
1463
1496
  private _setupAStar;
@@ -1516,8 +1549,10 @@ declare class CapacityPathingMultiSectionSolver extends BaseSolver {
1516
1549
  connectionsWithNodes: Array<ConnectionPathWithNodes>;
1517
1550
  colorMap: Record<string, string>;
1518
1551
  initialSolver: CapacityPathingGreedySolver;
1552
+ cacheProvider?: CacheProvider | null;
1519
1553
  stage: "initialization" | "section-optimization";
1520
1554
  nodeMap: Map<CapacityMeshNodeId, CapacityMeshNode>;
1555
+ allNodeIdsSet: Set<CapacityMeshNodeId>;
1521
1556
  usedNodeCapacityMap: Map<CapacityMeshNodeId, number>;
1522
1557
  totalNodeCapacityMap: Map<CapacityMeshNodeId, number>;
1523
1558
  nodeCapacityPercentMap: Map<CapacityMeshNodeId, number>;
@@ -1529,6 +1564,7 @@ declare class CapacityPathingMultiSectionSolver extends BaseSolver {
1529
1564
  successfulOptimizations: number;
1530
1565
  failedOptimizations: number;
1531
1566
  failedSectionSolvers: number;
1567
+ startingScore: number;
1532
1568
  scheduleScores: Array<{
1533
1569
  maxExpansionDegrees: number;
1534
1570
  sectionAttempts: number;
@@ -1548,6 +1584,7 @@ declare class CapacityPathingMultiSectionSolver extends BaseSolver {
1548
1584
  };
1549
1585
  constructor(params: ConstructorParameters<typeof CapacityPathingSolver>[0] & {
1550
1586
  initialPathingSolver?: CapacityPathingGreedySolver;
1587
+ cacheProvider?: CacheProvider | null;
1551
1588
  });
1552
1589
  _stepInitialization(): void;
1553
1590
  _getNextNodeToOptimize(): CapacityMeshNodeId | null;
@@ -1893,4 +1930,105 @@ declare const getTunedTotalCapacity1: (nodeOrWidth: CapacityMeshNode | {
1893
1930
  */
1894
1931
  declare const calculateOptimalCapacityDepth: (initialWidth: number, targetMinCapacity?: number, maxDepth?: number) => number;
1895
1932
 
1896
- export { CapacityMeshSolver, calculateOptimalCapacityDepth, getTunedTotalCapacity1 };
1933
+ /**
1934
+ * An in-memory implementation of the CacheProvider interface.
1935
+ * Useful for testing or scenarios where persistence is not required.
1936
+ */
1937
+ declare class InMemoryCache implements CacheProvider {
1938
+ cacheHitsByPrefix: Record<string, number>;
1939
+ cacheMissesByPrefix: Record<string, number>;
1940
+ isSyncCache: boolean;
1941
+ cacheHits: number;
1942
+ cacheMisses: number;
1943
+ cache: Map<string, any>;
1944
+ /**
1945
+ * Retrieves a cached solution synchronously based on the cache key.
1946
+ * Increments cache hit/miss counters.
1947
+ * @param cacheKey The key to look up in the cache.
1948
+ * @returns The cached solution if found, otherwise undefined.
1949
+ */
1950
+ getCachedSolutionSync(cacheKey: string): any;
1951
+ /**
1952
+ * Retrieves a cached solution asynchronously. Wraps the synchronous method.
1953
+ * @param cacheKey The key to look up in the cache.
1954
+ * @returns A promise that resolves with the cached solution or undefined.
1955
+ */
1956
+ getCachedSolution(cacheKey: string): Promise<any>;
1957
+ /**
1958
+ * Stores a solution in the cache synchronously.
1959
+ * Uses structured cloning to store a copy, preventing external modifications.
1960
+ * @param cacheKey The key under which to store the solution.
1961
+ * @param cachedSolution The solution data to cache.
1962
+ */
1963
+ setCachedSolutionSync(cacheKey: string, cachedSolution: any): void;
1964
+ /**
1965
+ * Stores a solution in the cache asynchronously. Wraps the synchronous method.
1966
+ * @param cacheKey The key under which to store the solution.
1967
+ * @param cachedSolution The solution data to cache.
1968
+ * @returns A promise that resolves when the solution is cached.
1969
+ */
1970
+ setCachedSolution(cacheKey: string, cachedSolution: any): Promise<void>;
1971
+ /**
1972
+ * Clears the entire cache and resets hit/miss counters.
1973
+ */
1974
+ clearCache(): void;
1975
+ getAllCacheKeys(): string[];
1976
+ }
1977
+
1978
+ /**
1979
+ * A CacheProvider implementation using the browser's localStorage.
1980
+ * Note: localStorage has size limits (typically 5-10MB) and stores data as strings.
1981
+ * Complex objects will be JSON serialized/deserialized.
1982
+ */
1983
+ declare class LocalStorageCache implements CacheProvider {
1984
+ isSyncCache: boolean;
1985
+ cacheHits: number;
1986
+ cacheMisses: number;
1987
+ cacheHitsByPrefix: Record<string, number>;
1988
+ cacheMissesByPrefix: Record<string, number>;
1989
+ constructor();
1990
+ private getKey;
1991
+ /**
1992
+ * Retrieves a cached solution synchronously from localStorage.
1993
+ * Increments cache hit/miss counters.
1994
+ * @param cacheKey The key to look up in the cache.
1995
+ * @returns The cached solution if found and parsed correctly, otherwise undefined.
1996
+ */
1997
+ getCachedSolutionSync(cacheKey: string): any;
1998
+ /**
1999
+ * Retrieves a cached solution asynchronously. Wraps the synchronous method.
2000
+ * @param cacheKey The key to look up in the cache.
2001
+ * @returns A promise that resolves with the cached solution or undefined.
2002
+ */
2003
+ getCachedSolution(cacheKey: string): Promise<any>;
2004
+ /**
2005
+ * Stores a solution in localStorage synchronously.
2006
+ * The solution is JSON stringified before storing.
2007
+ * @param cacheKey The key under which to store the solution.
2008
+ * @param cachedSolution The solution data to cache.
2009
+ */
2010
+ setCachedSolutionSync(cacheKey: string, cachedSolution: any): void;
2011
+ /**
2012
+ * Stores a solution in the cache asynchronously. Wraps the synchronous method.
2013
+ * @param cacheKey The key under which to store the solution.
2014
+ * @param cachedSolution The solution data to cache.
2015
+ * @returns A promise that resolves when the solution is cached.
2016
+ */
2017
+ setCachedSolution(cacheKey: string, cachedSolution: any): Promise<void>;
2018
+ /**
2019
+ * Clears all cache entries created by this instance from localStorage
2020
+ * and resets hit/miss counters.
2021
+ */
2022
+ clearCache(): void;
2023
+ getAllCacheKeys(): string[];
2024
+ }
2025
+
2026
+ declare global {
2027
+ var TSCIRCUIT_AUTOROUTER_LOCAL_STORAGE_CACHE: LocalStorageCache;
2028
+ var TSCIRCUIT_AUTOROUTER_IN_MEMORY_CACHE: InMemoryCache;
2029
+ }
2030
+ declare function getGlobalLocalStorageCache(): LocalStorageCache;
2031
+ declare function getGlobalInMemoryCache(): InMemoryCache;
2032
+ declare function setupGlobalCaches(): void;
2033
+
2034
+ export { type CachableSolver, type CacheProvider, CapacityMeshSolver, InMemoryCache, LocalStorageCache, calculateOptimalCapacityDepth, getGlobalInMemoryCache, getGlobalLocalStorageCache, getTunedTotalCapacity1, setupGlobalCaches };