@tscircuit/capacity-autorouter 0.0.61 → 0.0.63

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
@@ -704,6 +704,7 @@ declare class HyperSingleIntraNodeSolver extends HyperParameterSupervisorSolver<
704
704
  constructorParams: ConstructorParameters<typeof IntraNodeRouteSolver>[0];
705
705
  solvedRoutes: HighDensityIntraNodeRoute$1[];
706
706
  nodeWithPortPoints: NodeWithPortPoints;
707
+ connMap?: ConnectivityMap;
707
708
  constructor(opts: ConstructorParameters<typeof IntraNodeRouteSolver>[0]);
708
709
  getCombinationDefs(): string[][];
709
710
  getHyperParameterDefs(): ({
@@ -1246,6 +1247,8 @@ interface CacheProvider {
1246
1247
  isSyncCache: boolean;
1247
1248
  cacheHits: number;
1248
1249
  cacheMisses: number;
1250
+ cacheHitsByPrefix: Record<string, number>;
1251
+ cacheMissesByPrefix: Record<string, number>;
1249
1252
  getCachedSolutionSync(cacheKey: string): any;
1250
1253
  getCachedSolution(cacheKey: string): Promise<any>;
1251
1254
  setCachedSolutionSync(cacheKey: string, cachedSolution: any): void;
@@ -1253,6 +1256,29 @@ interface CacheProvider {
1253
1256
  getAllCacheKeys(): string[];
1254
1257
  clearCache(): void;
1255
1258
  }
1259
+ interface CachableSolver<CacheToSolveSpaceTransform = any, CachedSolution = any> {
1260
+ cacheHit: boolean;
1261
+ hasAttemptedToUseCache: boolean;
1262
+ cacheProvider: CacheProvider | null;
1263
+ cacheKey?: string;
1264
+ cacheToSolveSpaceTransform?: CacheToSolveSpaceTransform;
1265
+ /**
1266
+ * Processes solver inputs and constructs a cacheKey and a cacheToSolveSpaceTransform
1267
+ * which gives the necessary information to convert a cached solution into a valid
1268
+ * solution for this solver. For example, the cacheKey may be translation-invariant, so
1269
+ * any cachedSolution would not be translated properly for this solver. The cacheToSolveSpaceTransform
1270
+ * tells you how to convert from the cache space (translation-invarant) to the correct
1271
+ * space for this solver. It can also contain information about how cache ids map to
1272
+ * ids for the solver
1273
+ **/
1274
+ computeCacheKeyAndTransform(): {
1275
+ cacheKey: string;
1276
+ cacheToSolveSpaceTransform: CacheToSolveSpaceTransform;
1277
+ };
1278
+ applyCachedSolution(cachedSolution: CachedSolution): void;
1279
+ attemptToUseCacheSync(): boolean;
1280
+ saveToCacheSync(): void;
1281
+ }
1256
1282
 
1257
1283
  declare class UnravelMultiSectionSolver extends BaseSolver {
1258
1284
  nodeMap: Map<CapacityMeshNodeId, CapacityMeshNode>;
@@ -1415,6 +1441,7 @@ interface CapacityPathingSingleSectionPathingSolverParams {
1415
1441
  }>;
1416
1442
  colorMap?: Record<string, string>;
1417
1443
  centerNodeId: string;
1444
+ nodeMap?: Map<CapacityMeshNodeId, CapacityMeshNode>;
1418
1445
  nodeEdgeMap?: Map<CapacityMeshNodeId, CapacityMeshEdge[]>;
1419
1446
  hyperParameters?: CpssPathingSolverHyperParameters;
1420
1447
  }
@@ -1432,7 +1459,9 @@ declare class CapacityPathingSingleSectionSolver extends BaseSolver {
1432
1459
  nodeEdgeMap: Map<CapacityMeshNodeId, CapacityMeshEdge[]>;
1433
1460
  colorMap: Record<string, string>;
1434
1461
  usedNodeCapacityMap: Map<CapacityMeshNodeId, number>;
1462
+ totalNodeCapacityMap: Map<CapacityMeshNodeId, number>;
1435
1463
  centerNodeId: string;
1464
+ private currentSectionScore;
1436
1465
  MAX_CANDIDATES_IN_MEMORY: number;
1437
1466
  currentConnectionIndex: number;
1438
1467
  candidates?: Array<Candidate> | null;
@@ -1457,6 +1486,7 @@ declare class CapacityPathingSingleSectionSolver extends BaseSolver {
1457
1486
  isConnectedToEndGoal(node: CapacityMeshNode, endGoal: CapacityMeshNode): boolean;
1458
1487
  doesNodeHaveCapacityForTrace(node: CapacityMeshNode, prevNode: CapacityMeshNode | null): boolean;
1459
1488
  reduceCapacityAlongPath(path: CapacityMeshNode[]): void;
1489
+ getSolvedSectionScore(): number;
1460
1490
  _step(): void;
1461
1491
  computeProgress(): number;
1462
1492
  private _setupAStar;
@@ -1515,8 +1545,10 @@ declare class CapacityPathingMultiSectionSolver extends BaseSolver {
1515
1545
  connectionsWithNodes: Array<ConnectionPathWithNodes>;
1516
1546
  colorMap: Record<string, string>;
1517
1547
  initialSolver: CapacityPathingGreedySolver;
1548
+ cacheProvider?: CacheProvider | null;
1518
1549
  stage: "initialization" | "section-optimization";
1519
1550
  nodeMap: Map<CapacityMeshNodeId, CapacityMeshNode>;
1551
+ allNodeIdsSet: Set<CapacityMeshNodeId>;
1520
1552
  usedNodeCapacityMap: Map<CapacityMeshNodeId, number>;
1521
1553
  totalNodeCapacityMap: Map<CapacityMeshNodeId, number>;
1522
1554
  nodeCapacityPercentMap: Map<CapacityMeshNodeId, number>;
@@ -1528,6 +1560,7 @@ declare class CapacityPathingMultiSectionSolver extends BaseSolver {
1528
1560
  successfulOptimizations: number;
1529
1561
  failedOptimizations: number;
1530
1562
  failedSectionSolvers: number;
1563
+ startingScore: number;
1531
1564
  scheduleScores: Array<{
1532
1565
  maxExpansionDegrees: number;
1533
1566
  sectionAttempts: number;
@@ -1547,6 +1580,7 @@ declare class CapacityPathingMultiSectionSolver extends BaseSolver {
1547
1580
  };
1548
1581
  constructor(params: ConstructorParameters<typeof CapacityPathingSolver>[0] & {
1549
1582
  initialPathingSolver?: CapacityPathingGreedySolver;
1583
+ cacheProvider?: CacheProvider | null;
1550
1584
  });
1551
1585
  _stepInitialization(): void;
1552
1586
  _getNextNodeToOptimize(): CapacityMeshNodeId | null;
@@ -1892,4 +1926,105 @@ declare const getTunedTotalCapacity1: (nodeOrWidth: CapacityMeshNode | {
1892
1926
  */
1893
1927
  declare const calculateOptimalCapacityDepth: (initialWidth: number, targetMinCapacity?: number, maxDepth?: number) => number;
1894
1928
 
1895
- export { CapacityMeshSolver, calculateOptimalCapacityDepth, getTunedTotalCapacity1 };
1929
+ /**
1930
+ * An in-memory implementation of the CacheProvider interface.
1931
+ * Useful for testing or scenarios where persistence is not required.
1932
+ */
1933
+ declare class InMemoryCache implements CacheProvider {
1934
+ cacheHitsByPrefix: Record<string, number>;
1935
+ cacheMissesByPrefix: Record<string, number>;
1936
+ isSyncCache: boolean;
1937
+ cacheHits: number;
1938
+ cacheMisses: number;
1939
+ cache: Map<string, any>;
1940
+ /**
1941
+ * Retrieves a cached solution synchronously based on the cache key.
1942
+ * Increments cache hit/miss counters.
1943
+ * @param cacheKey The key to look up in the cache.
1944
+ * @returns The cached solution if found, otherwise undefined.
1945
+ */
1946
+ getCachedSolutionSync(cacheKey: string): any;
1947
+ /**
1948
+ * Retrieves a cached solution asynchronously. Wraps the synchronous method.
1949
+ * @param cacheKey The key to look up in the cache.
1950
+ * @returns A promise that resolves with the cached solution or undefined.
1951
+ */
1952
+ getCachedSolution(cacheKey: string): Promise<any>;
1953
+ /**
1954
+ * Stores a solution in the cache synchronously.
1955
+ * Uses structured cloning to store a copy, preventing external modifications.
1956
+ * @param cacheKey The key under which to store the solution.
1957
+ * @param cachedSolution The solution data to cache.
1958
+ */
1959
+ setCachedSolutionSync(cacheKey: string, cachedSolution: any): void;
1960
+ /**
1961
+ * Stores a solution in the cache asynchronously. Wraps the synchronous method.
1962
+ * @param cacheKey The key under which to store the solution.
1963
+ * @param cachedSolution The solution data to cache.
1964
+ * @returns A promise that resolves when the solution is cached.
1965
+ */
1966
+ setCachedSolution(cacheKey: string, cachedSolution: any): Promise<void>;
1967
+ /**
1968
+ * Clears the entire cache and resets hit/miss counters.
1969
+ */
1970
+ clearCache(): void;
1971
+ getAllCacheKeys(): string[];
1972
+ }
1973
+
1974
+ /**
1975
+ * A CacheProvider implementation using the browser's localStorage.
1976
+ * Note: localStorage has size limits (typically 5-10MB) and stores data as strings.
1977
+ * Complex objects will be JSON serialized/deserialized.
1978
+ */
1979
+ declare class LocalStorageCache implements CacheProvider {
1980
+ isSyncCache: boolean;
1981
+ cacheHits: number;
1982
+ cacheMisses: number;
1983
+ cacheHitsByPrefix: Record<string, number>;
1984
+ cacheMissesByPrefix: Record<string, number>;
1985
+ constructor();
1986
+ private getKey;
1987
+ /**
1988
+ * Retrieves a cached solution synchronously from localStorage.
1989
+ * Increments cache hit/miss counters.
1990
+ * @param cacheKey The key to look up in the cache.
1991
+ * @returns The cached solution if found and parsed correctly, otherwise undefined.
1992
+ */
1993
+ getCachedSolutionSync(cacheKey: string): any;
1994
+ /**
1995
+ * Retrieves a cached solution asynchronously. Wraps the synchronous method.
1996
+ * @param cacheKey The key to look up in the cache.
1997
+ * @returns A promise that resolves with the cached solution or undefined.
1998
+ */
1999
+ getCachedSolution(cacheKey: string): Promise<any>;
2000
+ /**
2001
+ * Stores a solution in localStorage synchronously.
2002
+ * The solution is JSON stringified before storing.
2003
+ * @param cacheKey The key under which to store the solution.
2004
+ * @param cachedSolution The solution data to cache.
2005
+ */
2006
+ setCachedSolutionSync(cacheKey: string, cachedSolution: any): void;
2007
+ /**
2008
+ * Stores a solution in the cache asynchronously. Wraps the synchronous method.
2009
+ * @param cacheKey The key under which to store the solution.
2010
+ * @param cachedSolution The solution data to cache.
2011
+ * @returns A promise that resolves when the solution is cached.
2012
+ */
2013
+ setCachedSolution(cacheKey: string, cachedSolution: any): Promise<void>;
2014
+ /**
2015
+ * Clears all cache entries created by this instance from localStorage
2016
+ * and resets hit/miss counters.
2017
+ */
2018
+ clearCache(): void;
2019
+ getAllCacheKeys(): string[];
2020
+ }
2021
+
2022
+ declare global {
2023
+ var TSCIRCUIT_AUTOROUTER_LOCAL_STORAGE_CACHE: LocalStorageCache;
2024
+ var TSCIRCUIT_AUTOROUTER_IN_MEMORY_CACHE: InMemoryCache;
2025
+ }
2026
+ declare function getGlobalLocalStorageCache(): LocalStorageCache;
2027
+ declare function getGlobalInMemoryCache(): InMemoryCache;
2028
+ declare function setupGlobalCaches(): void;
2029
+
2030
+ export { type CachableSolver, type CacheProvider, CapacityMeshSolver, InMemoryCache, LocalStorageCache, calculateOptimalCapacityDepth, getGlobalInMemoryCache, getGlobalLocalStorageCache, getTunedTotalCapacity1, setupGlobalCaches };