@jetta/cargo-stabilizer 0.1.0 → 0.1.1

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.
@@ -0,0 +1,9 @@
1
+ import type { BeamState } from './beam_context.js';
2
+ /**
3
+ * Ranks beam states by score and a canonical layout key.
4
+ * @param left - Left beam state.
5
+ * @param right - Right beam state.
6
+ * @returns Negative when left ranks ahead of right.
7
+ */
8
+ export declare function compare_beam_states(left: BeamState, right: BeamState): number;
9
+ //# sourceMappingURL=compare_beam_states.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compare_beam_states.d.ts","sourceRoot":"","sources":["../../../../src/core/strategies/reorder/compare_beam_states.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAElD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,MAAM,CAQ7E"}
@@ -0,0 +1,26 @@
1
+ import { compare_search_states } from '../../evaluation/compare_search_states.js';
2
+ /**
3
+ * Ranks beam states by score and a canonical layout key.
4
+ * @param left - Left beam state.
5
+ * @param right - Right beam state.
6
+ * @returns Negative when left ranks ahead of right.
7
+ */
8
+ export function compare_beam_states(left, right) {
9
+ const score_order = compare_search_states(left, right);
10
+ if (score_order !== 0) {
11
+ return score_order;
12
+ }
13
+ return compare_keys(layout_key(left), layout_key(right));
14
+ }
15
+ function layout_key(state) {
16
+ return state.containers.map(container => container.items.map(item => `${item.item_id}:${item.x}:${item.y}:${item.z}`).sort().join('|')).join('||');
17
+ }
18
+ function compare_keys(left, right) {
19
+ if (left < right) {
20
+ return -1;
21
+ }
22
+ if (left > right) {
23
+ return 1;
24
+ }
25
+ return 0;
26
+ }
@@ -1,4 +1,4 @@
1
- import { compare_search_states } from '../../evaluation/compare_search_states.js';
1
+ import { compare_beam_states } from './compare_beam_states.js';
2
2
  /**
3
3
  * Keeps ranked expansions, or the parent beam when every trial failed admission.
4
4
  * Ranks by axle excess then stability objective.
@@ -8,6 +8,6 @@ import { compare_search_states } from '../../evaluation/compare_search_states.js
8
8
  * @returns Next beam, never empty when the parent beam had states.
9
9
  */
10
10
  export function select_surviving_beam(expanded, parent_beam, beam_width) {
11
- const ranked = [...parent_beam, ...expanded].sort(compare_search_states);
11
+ const ranked = [...parent_beam, ...expanded].sort(compare_beam_states);
12
12
  return ranked.slice(0, beam_width);
13
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetta/cargo-stabilizer",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Stable loose-item reorder library for cargo-movement (JET-2262)",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",