@tscircuit/capacity-autorouter 0.0.62 → 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 +135 -1
- package/dist/index.js +584 -136
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1247,6 +1247,8 @@ interface CacheProvider {
|
|
|
1247
1247
|
isSyncCache: boolean;
|
|
1248
1248
|
cacheHits: number;
|
|
1249
1249
|
cacheMisses: number;
|
|
1250
|
+
cacheHitsByPrefix: Record<string, number>;
|
|
1251
|
+
cacheMissesByPrefix: Record<string, number>;
|
|
1250
1252
|
getCachedSolutionSync(cacheKey: string): any;
|
|
1251
1253
|
getCachedSolution(cacheKey: string): Promise<any>;
|
|
1252
1254
|
setCachedSolutionSync(cacheKey: string, cachedSolution: any): void;
|
|
@@ -1254,6 +1256,29 @@ interface CacheProvider {
|
|
|
1254
1256
|
getAllCacheKeys(): string[];
|
|
1255
1257
|
clearCache(): void;
|
|
1256
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
|
+
}
|
|
1257
1282
|
|
|
1258
1283
|
declare class UnravelMultiSectionSolver extends BaseSolver {
|
|
1259
1284
|
nodeMap: Map<CapacityMeshNodeId, CapacityMeshNode>;
|
|
@@ -1416,6 +1441,7 @@ interface CapacityPathingSingleSectionPathingSolverParams {
|
|
|
1416
1441
|
}>;
|
|
1417
1442
|
colorMap?: Record<string, string>;
|
|
1418
1443
|
centerNodeId: string;
|
|
1444
|
+
nodeMap?: Map<CapacityMeshNodeId, CapacityMeshNode>;
|
|
1419
1445
|
nodeEdgeMap?: Map<CapacityMeshNodeId, CapacityMeshEdge[]>;
|
|
1420
1446
|
hyperParameters?: CpssPathingSolverHyperParameters;
|
|
1421
1447
|
}
|
|
@@ -1433,7 +1459,9 @@ declare class CapacityPathingSingleSectionSolver extends BaseSolver {
|
|
|
1433
1459
|
nodeEdgeMap: Map<CapacityMeshNodeId, CapacityMeshEdge[]>;
|
|
1434
1460
|
colorMap: Record<string, string>;
|
|
1435
1461
|
usedNodeCapacityMap: Map<CapacityMeshNodeId, number>;
|
|
1462
|
+
totalNodeCapacityMap: Map<CapacityMeshNodeId, number>;
|
|
1436
1463
|
centerNodeId: string;
|
|
1464
|
+
private currentSectionScore;
|
|
1437
1465
|
MAX_CANDIDATES_IN_MEMORY: number;
|
|
1438
1466
|
currentConnectionIndex: number;
|
|
1439
1467
|
candidates?: Array<Candidate> | null;
|
|
@@ -1458,6 +1486,7 @@ declare class CapacityPathingSingleSectionSolver extends BaseSolver {
|
|
|
1458
1486
|
isConnectedToEndGoal(node: CapacityMeshNode, endGoal: CapacityMeshNode): boolean;
|
|
1459
1487
|
doesNodeHaveCapacityForTrace(node: CapacityMeshNode, prevNode: CapacityMeshNode | null): boolean;
|
|
1460
1488
|
reduceCapacityAlongPath(path: CapacityMeshNode[]): void;
|
|
1489
|
+
getSolvedSectionScore(): number;
|
|
1461
1490
|
_step(): void;
|
|
1462
1491
|
computeProgress(): number;
|
|
1463
1492
|
private _setupAStar;
|
|
@@ -1516,8 +1545,10 @@ declare class CapacityPathingMultiSectionSolver extends BaseSolver {
|
|
|
1516
1545
|
connectionsWithNodes: Array<ConnectionPathWithNodes>;
|
|
1517
1546
|
colorMap: Record<string, string>;
|
|
1518
1547
|
initialSolver: CapacityPathingGreedySolver;
|
|
1548
|
+
cacheProvider?: CacheProvider | null;
|
|
1519
1549
|
stage: "initialization" | "section-optimization";
|
|
1520
1550
|
nodeMap: Map<CapacityMeshNodeId, CapacityMeshNode>;
|
|
1551
|
+
allNodeIdsSet: Set<CapacityMeshNodeId>;
|
|
1521
1552
|
usedNodeCapacityMap: Map<CapacityMeshNodeId, number>;
|
|
1522
1553
|
totalNodeCapacityMap: Map<CapacityMeshNodeId, number>;
|
|
1523
1554
|
nodeCapacityPercentMap: Map<CapacityMeshNodeId, number>;
|
|
@@ -1529,6 +1560,7 @@ declare class CapacityPathingMultiSectionSolver extends BaseSolver {
|
|
|
1529
1560
|
successfulOptimizations: number;
|
|
1530
1561
|
failedOptimizations: number;
|
|
1531
1562
|
failedSectionSolvers: number;
|
|
1563
|
+
startingScore: number;
|
|
1532
1564
|
scheduleScores: Array<{
|
|
1533
1565
|
maxExpansionDegrees: number;
|
|
1534
1566
|
sectionAttempts: number;
|
|
@@ -1548,6 +1580,7 @@ declare class CapacityPathingMultiSectionSolver extends BaseSolver {
|
|
|
1548
1580
|
};
|
|
1549
1581
|
constructor(params: ConstructorParameters<typeof CapacityPathingSolver>[0] & {
|
|
1550
1582
|
initialPathingSolver?: CapacityPathingGreedySolver;
|
|
1583
|
+
cacheProvider?: CacheProvider | null;
|
|
1551
1584
|
});
|
|
1552
1585
|
_stepInitialization(): void;
|
|
1553
1586
|
_getNextNodeToOptimize(): CapacityMeshNodeId | null;
|
|
@@ -1893,4 +1926,105 @@ declare const getTunedTotalCapacity1: (nodeOrWidth: CapacityMeshNode | {
|
|
|
1893
1926
|
*/
|
|
1894
1927
|
declare const calculateOptimalCapacityDepth: (initialWidth: number, targetMinCapacity?: number, maxDepth?: number) => number;
|
|
1895
1928
|
|
|
1896
|
-
|
|
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 };
|