@tscircuit/hypergraph 0.0.20 → 0.0.21

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
@@ -349,6 +349,23 @@ declare class HyperGraphSolver<RegionType extends Region = Region, RegionPortTyp
349
349
  * redundant.
350
350
  */
351
351
  selectCandidatesForEnteringRegion(candidates: Candidate[]): Candidate[];
352
+ /**
353
+ * OPTIONALLY OVERRIDE THIS
354
+ *
355
+ * Compute the full set of solved routes that must be ripped to accept
356
+ * `newlySolvedRoute`. By default this returns all conflicting routes
357
+ * (always-rip behavior)
358
+ *
359
+ * Override this to implement partial ripping, where only a subset of
360
+ * conflicting routes are removed.
361
+ */
362
+ computeRoutesToRip(newlySolvedRoute: SolvedRoute): Set<SolvedRoute>;
363
+ /**
364
+ * Returns solved routes that overlap ports with the newly solved route.
365
+ * Use this in computeRoutesToRip overrides to include port reuse rips.
366
+ */
367
+ computePortOverlapRoutes(newlySolvedRoute: SolvedRoute): Set<SolvedRoute>;
368
+ computeCrossingRoutes(newlySolvedRoute: SolvedRoute): Set<SolvedRoute>;
352
369
  getNextCandidates(currentCandidate: CandidateType): CandidateType[];
353
370
  processSolvedRoute(finalCandidate: CandidateType): void;
354
371
  /**
package/dist/index.js CHANGED
@@ -1915,6 +1915,52 @@ var HyperGraphSolver = class extends BaseSolver {
1915
1915
  selectCandidatesForEnteringRegion(candidates) {
1916
1916
  return candidates;
1917
1917
  }
1918
+ /**
1919
+ * OPTIONALLY OVERRIDE THIS
1920
+ *
1921
+ * Compute the full set of solved routes that must be ripped to accept
1922
+ * `newlySolvedRoute`. By default this returns all conflicting routes
1923
+ * (always-rip behavior)
1924
+ *
1925
+ * Override this to implement partial ripping, where only a subset of
1926
+ * conflicting routes are removed.
1927
+ */
1928
+ computeRoutesToRip(newlySolvedRoute) {
1929
+ const crossingRoutesToRip = this.computeCrossingRoutes(newlySolvedRoute);
1930
+ const portReuseRoutesToRip = this.computePortOverlapRoutes(newlySolvedRoute);
1931
+ return /* @__PURE__ */ new Set([
1932
+ ...crossingRoutesToRip,
1933
+ ...portReuseRoutesToRip
1934
+ ]);
1935
+ }
1936
+ /**
1937
+ * Returns solved routes that overlap ports with the newly solved route.
1938
+ * Use this in computeRoutesToRip overrides to include port reuse rips.
1939
+ */
1940
+ computePortOverlapRoutes(newlySolvedRoute) {
1941
+ const portReuseRoutesToRip = /* @__PURE__ */ new Set();
1942
+ for (const candidate of newlySolvedRoute.path) {
1943
+ if (candidate.port.assignment && candidate.port.assignment.connection.mutuallyConnectedNetworkId !== newlySolvedRoute.connection.mutuallyConnectedNetworkId) {
1944
+ portReuseRoutesToRip.add(candidate.port.assignment.solvedRoute);
1945
+ }
1946
+ }
1947
+ return portReuseRoutesToRip;
1948
+ }
1949
+ computeCrossingRoutes(newlySolvedRoute) {
1950
+ const crossingRoutesToRip = /* @__PURE__ */ new Set();
1951
+ for (const candidate of newlySolvedRoute.path) {
1952
+ if (!candidate.lastPort || !candidate.lastRegion) continue;
1953
+ const ripsRequired = this.getRipsRequiredForPortUsage(
1954
+ candidate.lastRegion,
1955
+ candidate.lastPort,
1956
+ candidate.port
1957
+ );
1958
+ for (const assignment of ripsRequired) {
1959
+ crossingRoutesToRip.add(assignment.solvedRoute);
1960
+ }
1961
+ }
1962
+ return crossingRoutesToRip;
1963
+ }
1918
1964
  getNextCandidates(currentCandidate) {
1919
1965
  const currentRegion = currentCandidate.nextRegion;
1920
1966
  const currentPort = currentCandidate.port;
@@ -1966,29 +2012,13 @@ var HyperGraphSolver = class extends BaseSolver {
1966
2012
  solvedRoute.path.unshift(cursorCandidate);
1967
2013
  cursorCandidate = cursorCandidate.parent;
1968
2014
  }
1969
- const routesToRip = /* @__PURE__ */ new Set();
1970
2015
  if (anyRipsRequired) {
1971
2016
  solvedRoute.requiredRip = true;
1972
- for (const candidate of solvedRoute.path) {
1973
- if (candidate.port.assignment && candidate.port.assignment.connection.mutuallyConnectedNetworkId !== this.currentConnection.mutuallyConnectedNetworkId) {
1974
- routesToRip.add(candidate.port.assignment.solvedRoute);
1975
- }
1976
- }
1977
- }
1978
- for (const candidate of solvedRoute.path) {
1979
- if (!candidate.lastPort || !candidate.lastRegion) continue;
1980
- const ripsRequired = this.getRipsRequiredForPortUsage(
1981
- candidate.lastRegion,
1982
- candidate.lastPort,
1983
- candidate.port
1984
- );
1985
- for (const assignment of ripsRequired) {
1986
- routesToRip.add(assignment.solvedRoute);
1987
- }
1988
2017
  }
1989
- if (routesToRip.size > 0) {
2018
+ const allRoutesToRip = this.computeRoutesToRip(solvedRoute);
2019
+ if (allRoutesToRip.size > 0) {
1990
2020
  solvedRoute.requiredRip = true;
1991
- for (const route of routesToRip) {
2021
+ for (const route of allRoutesToRip) {
1992
2022
  this.ripSolvedRoute(route);
1993
2023
  }
1994
2024
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/hypergraph",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.20",
4
+ "version": "0.0.21",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "start": "cosmos",