@jetta/cargo-stabilizer 0.1.0-10
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/CHANGELOG.md +39 -0
- package/README.md +144 -0
- package/build/core/adapters/axle_adapter.d.ts +16 -0
- package/build/core/adapters/axle_adapter.d.ts.map +1 -0
- package/build/core/adapters/axle_adapter.js +35 -0
- package/build/core/adapters/build_axle_request.d.ts +15 -0
- package/build/core/adapters/build_axle_request.d.ts.map +1 -0
- package/build/core/adapters/build_axle_request.js +39 -0
- package/build/core/adapters/coordinate_mapper.d.ts +36 -0
- package/build/core/adapters/coordinate_mapper.d.ts.map +1 -0
- package/build/core/adapters/coordinate_mapper.js +40 -0
- package/build/core/adapters/empty_space_adapter.d.ts +10 -0
- package/build/core/adapters/empty_space_adapter.d.ts.map +1 -0
- package/build/core/adapters/empty_space_adapter.js +24 -0
- package/build/core/adapters/map_item_to_positioned_cube.d.ts +9 -0
- package/build/core/adapters/map_item_to_positioned_cube.d.ts.map +1 -0
- package/build/core/adapters/map_item_to_positioned_cube.js +16 -0
- package/build/core/adapters/run_axle_calculator.d.ts +16 -0
- package/build/core/adapters/run_axle_calculator.d.ts.map +1 -0
- package/build/core/adapters/run_axle_calculator.js +32 -0
- package/build/core/adapters/stability_adapter.d.ts +36 -0
- package/build/core/adapters/stability_adapter.d.ts.map +1 -0
- package/build/core/adapters/stability_adapter.js +61 -0
- package/build/core/candidates/build_candidate_context.d.ts +13 -0
- package/build/core/candidates/build_candidate_context.d.ts.map +1 -0
- package/build/core/candidates/build_candidate_context.js +17 -0
- package/build/core/candidates/candidate_context.d.ts +13 -0
- package/build/core/candidates/candidate_context.d.ts.map +1 -0
- package/build/core/candidates/candidate_context.js +1 -0
- package/build/core/candidates/candidate_generator.d.ts +9 -0
- package/build/core/candidates/candidate_generator.d.ts.map +1 -0
- package/build/core/candidates/candidate_generator.js +42 -0
- package/build/core/candidates/candidate_validation.d.ts +14 -0
- package/build/core/candidates/candidate_validation.d.ts.map +1 -0
- package/build/core/candidates/candidate_validation.js +72 -0
- package/build/core/candidates/collect_container_slots.d.ts +16 -0
- package/build/core/candidates/collect_container_slots.d.ts.map +1 -0
- package/build/core/candidates/collect_container_slots.js +20 -0
- package/build/core/candidates/enumerate_empty_space_slots.d.ts +15 -0
- package/build/core/candidates/enumerate_empty_space_slots.d.ts.map +1 -0
- package/build/core/candidates/enumerate_empty_space_slots.js +44 -0
- package/build/core/candidates/enumerate_supporter_top_slots.d.ts +11 -0
- package/build/core/candidates/enumerate_supporter_top_slots.d.ts.map +1 -0
- package/build/core/candidates/enumerate_supporter_top_slots.js +36 -0
- package/build/core/candidates/is_elevated_on_supporter_origin.d.ts +14 -0
- package/build/core/candidates/is_elevated_on_supporter_origin.d.ts.map +1 -0
- package/build/core/candidates/is_elevated_on_supporter_origin.js +28 -0
- package/build/core/candidates/rank_candidates.d.ts +9 -0
- package/build/core/candidates/rank_candidates.d.ts.map +1 -0
- package/build/core/candidates/rank_candidates.js +22 -0
- package/build/core/constants/ReorderStrategy.d.ts +11 -0
- package/build/core/constants/ReorderStrategy.d.ts.map +1 -0
- package/build/core/constants/ReorderStrategy.js +9 -0
- package/build/core/constants/TieRatioOrientation.d.ts +6 -0
- package/build/core/constants/TieRatioOrientation.d.ts.map +1 -0
- package/build/core/constants/TieRatioOrientation.js +5 -0
- package/build/core/evaluation/compute_reorder_objective.d.ts +13 -0
- package/build/core/evaluation/compute_reorder_objective.d.ts.map +1 -0
- package/build/core/evaluation/compute_reorder_objective.js +13 -0
- package/build/core/evaluation/evaluation_context.d.ts +14 -0
- package/build/core/evaluation/evaluation_context.d.ts.map +1 -0
- package/build/core/evaluation/evaluation_context.js +1 -0
- package/build/core/evaluation/state_evaluator.d.ts +50 -0
- package/build/core/evaluation/state_evaluator.d.ts.map +1 -0
- package/build/core/evaluation/state_evaluator.js +95 -0
- package/build/core/exceptions/AxleCalculationError.d.ts +4 -0
- package/build/core/exceptions/AxleCalculationError.d.ts.map +1 -0
- package/build/core/exceptions/AxleCalculationError.js +6 -0
- package/build/core/exceptions/InvalidStabilizerInputError.d.ts +4 -0
- package/build/core/exceptions/InvalidStabilizerInputError.d.ts.map +1 -0
- package/build/core/exceptions/InvalidStabilizerInputError.js +6 -0
- package/build/core/exceptions/InvalidStabilizerOutputError.d.ts +4 -0
- package/build/core/exceptions/InvalidStabilizerOutputError.d.ts.map +1 -0
- package/build/core/exceptions/InvalidStabilizerOutputError.js +6 -0
- package/build/core/exceptions/MixedWaypointIdError.d.ts +4 -0
- package/build/core/exceptions/MixedWaypointIdError.d.ts.map +1 -0
- package/build/core/exceptions/MixedWaypointIdError.js +6 -0
- package/build/core/exceptions/UnknownReorderStrategyError.d.ts +4 -0
- package/build/core/exceptions/UnknownReorderStrategyError.d.ts.map +1 -0
- package/build/core/exceptions/UnknownReorderStrategyError.js +6 -0
- package/build/core/factory/read_stabilizer_config.d.ts +10 -0
- package/build/core/factory/read_stabilizer_config.d.ts.map +1 -0
- package/build/core/factory/read_stabilizer_config.js +26 -0
- package/build/core/factory/read_stabilizer_config_helpers.d.ts +29 -0
- package/build/core/factory/read_stabilizer_config_helpers.d.ts.map +1 -0
- package/build/core/factory/read_stabilizer_config_helpers.js +73 -0
- package/build/core/factory/strategy_factory.d.ts +9 -0
- package/build/core/factory/strategy_factory.d.ts.map +1 -0
- package/build/core/factory/strategy_factory.js +29 -0
- package/build/core/filters/collect_movable_items.d.ts +18 -0
- package/build/core/filters/collect_movable_items.d.ts.map +1 -0
- package/build/core/filters/collect_movable_items.js +72 -0
- package/build/core/filters/loose_item_filter.d.ts +20 -0
- package/build/core/filters/loose_item_filter.d.ts.map +1 -0
- package/build/core/filters/loose_item_filter.js +28 -0
- package/build/core/geometry/box_geometry.d.ts +48 -0
- package/build/core/geometry/box_geometry.d.ts.map +1 -0
- package/build/core/geometry/box_geometry.js +98 -0
- package/build/core/logging/stabilizer_logger.d.ts +3 -0
- package/build/core/logging/stabilizer_logger.d.ts.map +1 -0
- package/build/core/logging/stabilizer_logger.js +2 -0
- package/build/core/move/apply_move.d.ts +26 -0
- package/build/core/move/apply_move.d.ts.map +1 -0
- package/build/core/move/apply_move.js +26 -0
- package/build/core/orchestration/StabilizerFlow.d.ts +15 -0
- package/build/core/orchestration/StabilizerFlow.d.ts.map +1 -0
- package/build/core/orchestration/StabilizerFlow.js +29 -0
- package/build/core/orchestration/build_milkrun_bands_from_config.d.ts +13 -0
- package/build/core/orchestration/build_milkrun_bands_from_config.d.ts.map +1 -0
- package/build/core/orchestration/build_milkrun_bands_from_config.js +14 -0
- package/build/core/orchestration/build_reorder_context.d.ts +11 -0
- package/build/core/orchestration/build_reorder_context.d.ts.map +1 -0
- package/build/core/orchestration/build_reorder_context.js +27 -0
- package/build/core/orchestration/read_primary_env.d.ts +9 -0
- package/build/core/orchestration/read_primary_env.d.ts.map +1 -0
- package/build/core/orchestration/read_primary_env.js +13 -0
- package/build/core/strategies/reorder/BeamSearchReorder.d.ts +9 -0
- package/build/core/strategies/reorder/BeamSearchReorder.d.ts.map +1 -0
- package/build/core/strategies/reorder/BeamSearchReorder.js +68 -0
- package/build/core/strategies/reorder/GeneticReorder.d.ts +9 -0
- package/build/core/strategies/reorder/GeneticReorder.d.ts.map +1 -0
- package/build/core/strategies/reorder/GeneticReorder.js +43 -0
- package/build/core/strategies/reorder/GravityCompaction.d.ts +9 -0
- package/build/core/strategies/reorder/GravityCompaction.d.ts.map +1 -0
- package/build/core/strategies/reorder/GravityCompaction.js +48 -0
- package/build/core/strategies/reorder/GreedyReorder.d.ts +9 -0
- package/build/core/strategies/reorder/GreedyReorder.d.ts.map +1 -0
- package/build/core/strategies/reorder/GreedyReorder.js +20 -0
- package/build/core/strategies/reorder/ReorderStrategy.d.ts +19 -0
- package/build/core/strategies/reorder/ReorderStrategy.d.ts.map +1 -0
- package/build/core/strategies/reorder/ReorderStrategy.js +1 -0
- package/build/core/strategies/reorder/SimulatedAnnealingReorder.d.ts +9 -0
- package/build/core/strategies/reorder/SimulatedAnnealingReorder.d.ts.map +1 -0
- package/build/core/strategies/reorder/SimulatedAnnealingReorder.js +61 -0
- package/build/core/strategies/reorder/anneal_helpers.d.ts +18 -0
- package/build/core/strategies/reorder/anneal_helpers.d.ts.map +1 -0
- package/build/core/strategies/reorder/anneal_helpers.js +39 -0
- package/build/core/strategies/reorder/apply_if_gates_pass.d.ts +12 -0
- package/build/core/strategies/reorder/apply_if_gates_pass.d.ts.map +1 -0
- package/build/core/strategies/reorder/apply_if_gates_pass.js +19 -0
- package/build/core/strategies/reorder/beam_context.d.ts +16 -0
- package/build/core/strategies/reorder/beam_context.d.ts.map +1 -0
- package/build/core/strategies/reorder/beam_context.js +1 -0
- package/build/core/strategies/reorder/genetic/Chromosome.d.ts +39 -0
- package/build/core/strategies/reorder/genetic/Chromosome.d.ts.map +1 -0
- package/build/core/strategies/reorder/genetic/Chromosome.js +84 -0
- package/build/core/strategies/reorder/greedy_improvement.d.ts +12 -0
- package/build/core/strategies/reorder/greedy_improvement.d.ts.map +1 -0
- package/build/core/strategies/reorder/greedy_improvement.js +63 -0
- package/build/core/strategies/reorder/select_beam_expansion_candidates.d.ts +9 -0
- package/build/core/strategies/reorder/select_beam_expansion_candidates.d.ts.map +1 -0
- package/build/core/strategies/reorder/select_beam_expansion_candidates.js +28 -0
- package/build/core/validation/contract/cargo_movement_wire_field_map.d.ts +37 -0
- package/build/core/validation/contract/cargo_movement_wire_field_map.d.ts.map +1 -0
- package/build/core/validation/contract/cargo_movement_wire_field_map.js +43 -0
- package/build/core/validation/contract/cargo_movement_wire_mapper.d.ts +14 -0
- package/build/core/validation/contract/cargo_movement_wire_mapper.d.ts.map +1 -0
- package/build/core/validation/contract/cargo_movement_wire_mapper.js +34 -0
- package/build/core/validation/contract/format_zod_error.d.ts +8 -0
- package/build/core/validation/contract/format_zod_error.d.ts.map +1 -0
- package/build/core/validation/contract/format_zod_error.js +11 -0
- package/build/core/validation/contract/index.d.ts +9 -0
- package/build/core/validation/contract/index.d.ts.map +1 -0
- package/build/core/validation/contract/index.js +8 -0
- package/build/core/validation/contract/map_contract_to_wire_shape.d.ts +3 -0
- package/build/core/validation/contract/map_contract_to_wire_shape.d.ts.map +1 -0
- package/build/core/validation/contract/map_contract_to_wire_shape.js +42 -0
- package/build/core/validation/contract/map_wire_input_to_contract_shape.d.ts +2 -0
- package/build/core/validation/contract/map_wire_input_to_contract_shape.d.ts.map +1 -0
- package/build/core/validation/contract/map_wire_input_to_contract_shape.js +60 -0
- package/build/core/validation/contract/map_wire_item_to_contract.d.ts +12 -0
- package/build/core/validation/contract/map_wire_item_to_contract.d.ts.map +1 -0
- package/build/core/validation/contract/map_wire_item_to_contract.js +49 -0
- package/build/core/validation/contract/parse_stabilizer_input.d.ts +48 -0
- package/build/core/validation/contract/parse_stabilizer_input.d.ts.map +1 -0
- package/build/core/validation/contract/parse_stabilizer_input.js +26 -0
- package/build/core/validation/contract/parse_stabilizer_output.d.ts +50 -0
- package/build/core/validation/contract/parse_stabilizer_output.d.ts.map +1 -0
- package/build/core/validation/contract/parse_stabilizer_output.js +24 -0
- package/build/core/validation/contract/stabilizer_domain_schema.d.ts +101 -0
- package/build/core/validation/contract/stabilizer_domain_schema.d.ts.map +1 -0
- package/build/core/validation/contract/stabilizer_domain_schema.js +64 -0
- package/build/core/validation/contract/stabilizer_input_schema.d.ts +36 -0
- package/build/core/validation/contract/stabilizer_input_schema.d.ts.map +1 -0
- package/build/core/validation/contract/stabilizer_input_schema.js +11 -0
- package/build/core/validation/contract/stabilizer_output_schema.d.ts +76 -0
- package/build/core/validation/contract/stabilizer_output_schema.d.ts.map +1 -0
- package/build/core/validation/contract/stabilizer_output_schema.js +16 -0
- package/build/core/validation/contract/wire_mapper_record_utils.d.ts +34 -0
- package/build/core/validation/contract/wire_mapper_record_utils.d.ts.map +1 -0
- package/build/core/validation/contract/wire_mapper_record_utils.js +66 -0
- package/build/core/validation/schemas/stabilizer_config_schema.d.ts +20 -0
- package/build/core/validation/schemas/stabilizer_config_schema.d.ts.map +1 -0
- package/build/core/validation/schemas/stabilizer_config_schema.js +17 -0
- package/build/core/waypoint/WaypointMode.d.ts +16 -0
- package/build/core/waypoint/WaypointMode.d.ts.map +1 -0
- package/build/core/waypoint/WaypointMode.js +1 -0
- package/build/core/waypoint/build_waypoint_zones.d.ts +21 -0
- package/build/core/waypoint/build_waypoint_zones.d.ts.map +1 -0
- package/build/core/waypoint/build_waypoint_zones.js +48 -0
- package/build/core/waypoint/milkrun_wall_reservation.d.ts +24 -0
- package/build/core/waypoint/milkrun_wall_reservation.d.ts.map +1 -0
- package/build/core/waypoint/milkrun_wall_reservation.js +57 -0
- package/build/core/waypoint/milkrun_wall_reservation_helpers.d.ts +15 -0
- package/build/core/waypoint/milkrun_wall_reservation_helpers.d.ts.map +1 -0
- package/build/core/waypoint/milkrun_wall_reservation_helpers.js +48 -0
- package/build/core/waypoint/milkrun_wall_reservation_types.d.ts +16 -0
- package/build/core/waypoint/milkrun_wall_reservation_types.d.ts.map +1 -0
- package/build/core/waypoint/milkrun_wall_reservation_types.js +1 -0
- package/build/core/waypoint/preserves_waypoint_order.d.ts +24 -0
- package/build/core/waypoint/preserves_waypoint_order.d.ts.map +1 -0
- package/build/core/waypoint/preserves_waypoint_order.js +49 -0
- package/build/core/waypoint/validate_waypoint_ids.d.ts +16 -0
- package/build/core/waypoint/validate_waypoint_ids.d.ts.map +1 -0
- package/build/core/waypoint/validate_waypoint_ids.js +30 -0
- package/build/index.d.ts +27 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +75 -0
- package/package.json +51 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { apply_move, clone_containers } from '../../move/apply_move.js';
|
|
2
|
+
import { evaluate_trial_layout, evaluation_context_from_reorder } from '../../evaluation/state_evaluator.js';
|
|
3
|
+
import { accept_move, propose_neighbor } from './anneal_helpers.js';
|
|
4
|
+
/**
|
|
5
|
+
* Simulated annealing reorder with hard gate rejection on invalid neighbors.
|
|
6
|
+
*/
|
|
7
|
+
export class SimulatedAnnealingReorder {
|
|
8
|
+
run(context) {
|
|
9
|
+
const eval_context = evaluation_context_from_reorder(context);
|
|
10
|
+
const state = {
|
|
11
|
+
working: clone_containers(context.containers),
|
|
12
|
+
best: clone_containers(context.containers),
|
|
13
|
+
best_energy: energy(context.containers, eval_context)
|
|
14
|
+
};
|
|
15
|
+
let temperature = 1.0;
|
|
16
|
+
const cooling_rate = 0.995;
|
|
17
|
+
const steps = context.config.max_iteration * 10;
|
|
18
|
+
for (let step = 0; step < steps; step++) {
|
|
19
|
+
anneal_step({ reorder: context, evaluation: eval_context, state, temperature });
|
|
20
|
+
temperature *= cooling_rate;
|
|
21
|
+
}
|
|
22
|
+
context.containers.splice(0, context.containers.length, ...state.best);
|
|
23
|
+
return state.best;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function anneal_step(step_context) {
|
|
27
|
+
const neighbor = propose_neighbor(step_context.reorder, step_context.state.working);
|
|
28
|
+
if (!neighbor) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const trial_energy = evaluate_neighbor(step_context, neighbor);
|
|
32
|
+
if (trial_energy === undefined) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
apply_accepted_neighbor(step_context, neighbor, trial_energy);
|
|
36
|
+
}
|
|
37
|
+
function evaluate_neighbor(step_context, neighbor) {
|
|
38
|
+
const trial = clone_containers(step_context.state.working);
|
|
39
|
+
apply_move(trial, neighbor);
|
|
40
|
+
const evaluation = evaluate_trial_layout(trial, step_context.evaluation);
|
|
41
|
+
if (!evaluation.all_gates_pass) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const trial_energy = -evaluation.objective;
|
|
45
|
+
const delta = trial_energy - energy(step_context.state.working, step_context.evaluation);
|
|
46
|
+
if (!accept_move(delta, step_context.temperature)) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
return trial_energy;
|
|
50
|
+
}
|
|
51
|
+
function apply_accepted_neighbor(step_context, neighbor, trial_energy) {
|
|
52
|
+
apply_move(step_context.state.working, neighbor);
|
|
53
|
+
if (trial_energy >= step_context.state.best_energy) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
step_context.state.best = clone_containers(step_context.state.working);
|
|
57
|
+
step_context.state.best_energy = trial_energy;
|
|
58
|
+
}
|
|
59
|
+
function energy(containers, eval_context) {
|
|
60
|
+
return -evaluate_trial_layout(containers, eval_context).objective;
|
|
61
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ReorderContext } from './ReorderStrategy.js';
|
|
2
|
+
import type { StabilizerContainer } from '../../validation/contract/stabilizer_domain_schema.js';
|
|
3
|
+
import type { MoveCandidate } from '../../move/apply_move.js';
|
|
4
|
+
/**
|
|
5
|
+
* Proposes a random valid neighbor move for simulated annealing.
|
|
6
|
+
* @param context - Reorder context.
|
|
7
|
+
* @param working - Current working layout.
|
|
8
|
+
* @returns Random candidate or undefined.
|
|
9
|
+
*/
|
|
10
|
+
export declare function propose_neighbor(context: ReorderContext, working: StabilizerContainer[]): MoveCandidate | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Metropolis acceptance rule for simulated annealing.
|
|
13
|
+
* @param delta - Energy delta.
|
|
14
|
+
* @param temperature - Current temperature.
|
|
15
|
+
* @returns True when move is accepted.
|
|
16
|
+
*/
|
|
17
|
+
export declare function accept_move(delta: number, temperature: number): boolean;
|
|
18
|
+
//# sourceMappingURL=anneal_helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anneal_helpers.d.ts","sourceRoot":"","sources":["../../../../src/core/strategies/reorder/anneal_helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uDAAuD,CAAA;AAChG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAI7D;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC5B,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,mBAAmB,EAAE,GAC/B,aAAa,GAAG,SAAS,CAgB3B;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAWvE"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { generate_candidates } from '../../candidates/candidate_generator.js';
|
|
2
|
+
import { candidate_context_for_loose } from '../../candidates/build_candidate_context.js';
|
|
3
|
+
/**
|
|
4
|
+
* Proposes a random valid neighbor move for simulated annealing.
|
|
5
|
+
* @param context - Reorder context.
|
|
6
|
+
* @param working - Current working layout.
|
|
7
|
+
* @returns Random candidate or undefined.
|
|
8
|
+
*/
|
|
9
|
+
export function propose_neighbor(context, working) {
|
|
10
|
+
if (context.loose_items.length === 0) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
const index = Math.floor(Math.random() * context.loose_items.length);
|
|
14
|
+
const loose = { ...context.loose_items[index] };
|
|
15
|
+
loose.container_index = find_container_index(working, loose.item_id);
|
|
16
|
+
const candidates = generate_candidates(candidate_context_for_loose(context, working, loose));
|
|
17
|
+
if (candidates.length === 0) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
return candidates[Math.floor(Math.random() * candidates.length)];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Metropolis acceptance rule for simulated annealing.
|
|
24
|
+
* @param delta - Energy delta.
|
|
25
|
+
* @param temperature - Current temperature.
|
|
26
|
+
* @returns True when move is accepted.
|
|
27
|
+
*/
|
|
28
|
+
export function accept_move(delta, temperature) {
|
|
29
|
+
if (delta < 0) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
if (temperature <= 1e-6) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return Math.random() < Math.exp(-delta / temperature);
|
|
36
|
+
}
|
|
37
|
+
function find_container_index(containers, item_id) {
|
|
38
|
+
return containers.findIndex(container => container.items.some(item => item.item_id === item_id));
|
|
39
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { StabilizerContainer } from '../../validation/contract/stabilizer_domain_schema.js';
|
|
2
|
+
import type { ReorderContext } from './ReorderStrategy.js';
|
|
3
|
+
import type { MoveCandidate } from '../../move/apply_move.js';
|
|
4
|
+
/**
|
|
5
|
+
* Applies a candidate when all gates pass.
|
|
6
|
+
* @param context - Reorder context.
|
|
7
|
+
* @param working - Working container layout.
|
|
8
|
+
* @param candidate - Move candidate.
|
|
9
|
+
* @returns True when move was applied.
|
|
10
|
+
*/
|
|
11
|
+
export declare function apply_if_gates_pass(context: ReorderContext, working: StabilizerContainer[], candidate: MoveCandidate): boolean;
|
|
12
|
+
//# sourceMappingURL=apply_if_gates_pass.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply_if_gates_pass.d.ts","sourceRoot":"","sources":["../../../../src/core/strategies/reorder/apply_if_gates_pass.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uDAAuD,CAAA;AAChG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAO7D;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAC/B,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,mBAAmB,EAAE,EAC9B,SAAS,EAAE,aAAa,GACzB,OAAO,CAWT"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { apply_move, clone_containers } from '../../move/apply_move.js';
|
|
2
|
+
import { evaluate_trial_layout, evaluation_context_from_reorder } from '../../evaluation/state_evaluator.js';
|
|
3
|
+
/**
|
|
4
|
+
* Applies a candidate when all gates pass.
|
|
5
|
+
* @param context - Reorder context.
|
|
6
|
+
* @param working - Working container layout.
|
|
7
|
+
* @param candidate - Move candidate.
|
|
8
|
+
* @returns True when move was applied.
|
|
9
|
+
*/
|
|
10
|
+
export function apply_if_gates_pass(context, working, candidate) {
|
|
11
|
+
const trial = clone_containers(working);
|
|
12
|
+
apply_move(trial, candidate);
|
|
13
|
+
const evaluation = evaluate_trial_layout(trial, evaluation_context_from_reorder(context));
|
|
14
|
+
if (!evaluation.all_gates_pass) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
apply_move(working, candidate);
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ReorderContext } from './ReorderStrategy.js';
|
|
2
|
+
import type { StabilizerContainer } from '../../validation/contract/stabilizer_domain_schema.js';
|
|
3
|
+
import type { LooseItemRef } from '../../filters/loose_item_filter.js';
|
|
4
|
+
import type { StateEvaluationContext } from '../../evaluation/evaluation_context.js';
|
|
5
|
+
export interface BeamExpansionContext {
|
|
6
|
+
reorder: ReorderContext;
|
|
7
|
+
evaluation: StateEvaluationContext;
|
|
8
|
+
expanded: BeamState[];
|
|
9
|
+
state: BeamState;
|
|
10
|
+
loose: LooseItemRef;
|
|
11
|
+
}
|
|
12
|
+
export interface BeamState {
|
|
13
|
+
containers: StabilizerContainer[];
|
|
14
|
+
objective: number;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=beam_context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"beam_context.d.ts","sourceRoot":"","sources":["../../../../src/core/strategies/reorder/beam_context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uDAAuD,CAAA;AAChG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAA;AACtE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAA;AAEpF,MAAM,WAAW,oBAAoB;IAEjC,OAAO,EAAE,cAAc,CAAA;IACvB,UAAU,EAAE,sBAAsB,CAAA;IAClC,QAAQ,EAAE,SAAS,EAAE,CAAA;IACrB,KAAK,EAAE,SAAS,CAAA;IAChB,KAAK,EAAE,YAAY,CAAA;CACtB;AAED,MAAM,WAAW,SAAS;IAEtB,UAAU,EAAE,mBAAmB,EAAE,CAAA;IACjC,SAAS,EAAE,MAAM,CAAA;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { MoveCandidate } from '../../../move/apply_move.js';
|
|
2
|
+
import type { ReorderContext } from '../ReorderStrategy.js';
|
|
3
|
+
import type { StabilizerContainer } from '../../../validation/contract/stabilizer_domain_schema.js';
|
|
4
|
+
export interface ChromosomeGene {
|
|
5
|
+
item_id: string;
|
|
6
|
+
candidate: MoveCandidate;
|
|
7
|
+
}
|
|
8
|
+
export interface GeneticOrganism {
|
|
9
|
+
genes: ChromosomeGene[];
|
|
10
|
+
fitness: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Builds initial population from random valid gene assignments.
|
|
14
|
+
* @param context - Reorder context.
|
|
15
|
+
* @param population_size - Population count.
|
|
16
|
+
* @returns Initial organisms.
|
|
17
|
+
*/
|
|
18
|
+
export declare function build_initial_population(context: ReorderContext, population_size: number): GeneticOrganism[];
|
|
19
|
+
/**
|
|
20
|
+
* @param left - First organism.
|
|
21
|
+
* @param right - Second organism.
|
|
22
|
+
* @returns Child organism via uniform crossover.
|
|
23
|
+
*/
|
|
24
|
+
export declare function crossover_organisms(left: GeneticOrganism, right: GeneticOrganism): GeneticOrganism;
|
|
25
|
+
/**
|
|
26
|
+
* Mutates one gene in-place when mutation triggers.
|
|
27
|
+
* @param organism - Organism to mutate.
|
|
28
|
+
* @param context - Reorder context.
|
|
29
|
+
* @param mutation_rate - Probability per gene.
|
|
30
|
+
*/
|
|
31
|
+
export declare function mutate_organism(organism: GeneticOrganism, context: ReorderContext, mutation_rate: number): void;
|
|
32
|
+
/**
|
|
33
|
+
* Materializes organism genes onto container layout.
|
|
34
|
+
* @param baseline - Baseline containers.
|
|
35
|
+
* @param organism - Organism with genes.
|
|
36
|
+
* @returns New container layout.
|
|
37
|
+
*/
|
|
38
|
+
export declare function materialize_organism(baseline: StabilizerContainer[], organism: GeneticOrganism): StabilizerContainer[];
|
|
39
|
+
//# sourceMappingURL=Chromosome.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Chromosome.d.ts","sourceRoot":"","sources":["../../../../../src/core/strategies/reorder/genetic/Chromosome.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0DAA0D,CAAA;AAEnG,MAAM,WAAW,cAAc;IAE3B,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,aAAa,CAAA;CAC3B;AAED,MAAM,WAAW,eAAe;IAE5B,KAAK,EAAE,cAAc,EAAE,CAAA;IACvB,OAAO,EAAE,MAAM,CAAA;CAClB;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACpC,OAAO,EAAE,cAAc,EACvB,eAAe,EAAE,MAAM,GACxB,eAAe,EAAE,CAQnB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,eAAe,GAAG,eAAe,CAMlG;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC3B,QAAQ,EAAE,eAAe,EACzB,OAAO,EAAE,cAAc,EACvB,aAAa,EAAE,MAAM,GACtB,IAAI,CAeN;AAsBD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAChC,QAAQ,EAAE,mBAAmB,EAAE,EAC/B,QAAQ,EAAE,eAAe,GAC1B,mBAAmB,EAAE,CAgBvB"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds initial population from random valid gene assignments.
|
|
3
|
+
* @param context - Reorder context.
|
|
4
|
+
* @param population_size - Population count.
|
|
5
|
+
* @returns Initial organisms.
|
|
6
|
+
*/
|
|
7
|
+
export function build_initial_population(context, population_size) {
|
|
8
|
+
const organisms = [];
|
|
9
|
+
for (let index = 0; index < population_size; index++) {
|
|
10
|
+
organisms.push(build_random_organism(context));
|
|
11
|
+
}
|
|
12
|
+
return organisms;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @param left - First organism.
|
|
16
|
+
* @param right - Second organism.
|
|
17
|
+
* @returns Child organism via uniform crossover.
|
|
18
|
+
*/
|
|
19
|
+
export function crossover_organisms(left, right) {
|
|
20
|
+
const genes = left.genes.map((gene, index) => Math.random() < 0.5 ? gene : right.genes[index] ?? gene);
|
|
21
|
+
return { genes, fitness: Number.NEGATIVE_INFINITY };
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Mutates one gene in-place when mutation triggers.
|
|
25
|
+
* @param organism - Organism to mutate.
|
|
26
|
+
* @param context - Reorder context.
|
|
27
|
+
* @param mutation_rate - Probability per gene.
|
|
28
|
+
*/
|
|
29
|
+
export function mutate_organism(organism, context, mutation_rate) {
|
|
30
|
+
if (organism.genes.length === 0) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const gene_index = Math.floor(Math.random() * organism.genes.length);
|
|
34
|
+
if (Math.random() > mutation_rate) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const replacement = build_random_organism(context);
|
|
38
|
+
organism.genes[gene_index] = replacement.genes[gene_index] ?? organism.genes[gene_index];
|
|
39
|
+
}
|
|
40
|
+
function build_random_organism(context) {
|
|
41
|
+
const genes = [];
|
|
42
|
+
for (const loose of context.loose_items) {
|
|
43
|
+
genes.push({ item_id: loose.item_id, candidate: build_identity_candidate(loose) });
|
|
44
|
+
}
|
|
45
|
+
return { genes, fitness: Number.NEGATIVE_INFINITY };
|
|
46
|
+
}
|
|
47
|
+
function build_identity_candidate(loose) {
|
|
48
|
+
return {
|
|
49
|
+
item_id: loose.item_id,
|
|
50
|
+
source_container_index: loose.container_index,
|
|
51
|
+
target_container_index: loose.container_index,
|
|
52
|
+
new_position: { x: loose.item.x, y: loose.item.y, z: loose.item.z }
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Materializes organism genes onto container layout.
|
|
57
|
+
* @param baseline - Baseline containers.
|
|
58
|
+
* @param organism - Organism with genes.
|
|
59
|
+
* @returns New container layout.
|
|
60
|
+
*/
|
|
61
|
+
export function materialize_organism(baseline, organism) {
|
|
62
|
+
const working = structuredClone(baseline);
|
|
63
|
+
for (const gene of organism.genes) {
|
|
64
|
+
const source_index = working.findIndex(container => container.items.some(item => item.item_id === gene.item_id));
|
|
65
|
+
if (source_index < 0) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
gene.candidate.source_container_index = source_index;
|
|
69
|
+
apply_gene(working, gene.candidate);
|
|
70
|
+
}
|
|
71
|
+
return working;
|
|
72
|
+
}
|
|
73
|
+
function apply_gene(containers, candidate) {
|
|
74
|
+
const source = containers[candidate.source_container_index];
|
|
75
|
+
const item_index = source.items.findIndex(item => item.item_id === candidate.item_id);
|
|
76
|
+
if (item_index < 0) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const [item] = source.items.splice(item_index, 1);
|
|
80
|
+
item.x = candidate.new_position.x;
|
|
81
|
+
item.y = candidate.new_position.y;
|
|
82
|
+
item.z = candidate.new_position.z;
|
|
83
|
+
containers[candidate.target_container_index].items.push(item);
|
|
84
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ReorderContext } from './ReorderStrategy.js';
|
|
2
|
+
import type { StabilizerContainer } from '../../validation/contract/stabilizer_domain_schema.js';
|
|
3
|
+
import type { StateEvaluationContext } from '../../evaluation/evaluation_context.js';
|
|
4
|
+
/**
|
|
5
|
+
* Attempts one greedy improvement on the worst loose item.
|
|
6
|
+
* @param context - Reorder context.
|
|
7
|
+
* @param working - Working layout.
|
|
8
|
+
* @param eval_context - Evaluation context.
|
|
9
|
+
* @returns True when layout improved.
|
|
10
|
+
*/
|
|
11
|
+
export declare function improve_worst_loose(context: ReorderContext, working: StabilizerContainer[], eval_context: StateEvaluationContext): boolean;
|
|
12
|
+
//# sourceMappingURL=greedy_improvement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"greedy_improvement.d.ts","sourceRoot":"","sources":["../../../../src/core/strategies/reorder/greedy_improvement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uDAAuD,CAAA;AAEhG,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAA;AAepF;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAC/B,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,mBAAmB,EAAE,EAC9B,YAAY,EAAE,sBAAsB,GACrC,OAAO,CAiBT"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { generate_candidates } from '../../candidates/candidate_generator.js';
|
|
2
|
+
import { candidate_context_for_loose } from '../../candidates/build_candidate_context.js';
|
|
3
|
+
import { apply_move, clone_containers } from '../../move/apply_move.js';
|
|
4
|
+
import { evaluate_trial_layout } from '../../evaluation/state_evaluator.js';
|
|
5
|
+
/**
|
|
6
|
+
* Attempts one greedy improvement on the worst loose item.
|
|
7
|
+
* @param context - Reorder context.
|
|
8
|
+
* @param working - Working layout.
|
|
9
|
+
* @param eval_context - Evaluation context.
|
|
10
|
+
* @returns True when layout improved.
|
|
11
|
+
*/
|
|
12
|
+
export function improve_worst_loose(context, working, eval_context) {
|
|
13
|
+
const current_eval = evaluate_trial_layout(working, eval_context);
|
|
14
|
+
const worst = find_worst_loose(context, working, current_eval.stability.item_scores);
|
|
15
|
+
if (!worst) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
worst.container_index = find_container_index(working, worst.item_id);
|
|
19
|
+
return try_candidate_moves({
|
|
20
|
+
reorder: context,
|
|
21
|
+
working,
|
|
22
|
+
evaluation: eval_context,
|
|
23
|
+
loose: worst,
|
|
24
|
+
baseline_objective: current_eval.objective
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function try_candidate_moves(move_context) {
|
|
28
|
+
const candidates = generate_candidates(candidate_context_for_loose(move_context.reorder, move_context.working, move_context.loose));
|
|
29
|
+
for (const candidate of candidates) {
|
|
30
|
+
if (apply_improving_candidate(move_context, candidate)) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
function apply_improving_candidate(move_context, candidate) {
|
|
37
|
+
const trial = clone_containers(move_context.working);
|
|
38
|
+
apply_move(trial, candidate);
|
|
39
|
+
const trial_eval = evaluate_trial_layout(trial, move_context.evaluation);
|
|
40
|
+
if (!trial_eval.all_gates_pass || trial_eval.objective <= move_context.baseline_objective) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
apply_move(move_context.working, candidate);
|
|
44
|
+
move_context.loose.container_index = candidate.target_container_index;
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
function find_worst_loose(context, containers, item_scores) {
|
|
48
|
+
let worst;
|
|
49
|
+
let worst_score = Number.POSITIVE_INFINITY;
|
|
50
|
+
for (const loose of context.loose_items) {
|
|
51
|
+
const item_index = containers[loose.container_index].items
|
|
52
|
+
.findIndex(item => item.item_id === loose.item_id);
|
|
53
|
+
const score = item_scores[loose.container_index]?.[item_index] ?? 0;
|
|
54
|
+
if (score < worst_score) {
|
|
55
|
+
worst_score = score;
|
|
56
|
+
worst = loose;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return worst;
|
|
60
|
+
}
|
|
61
|
+
function find_container_index(containers, item_id) {
|
|
62
|
+
return containers.findIndex(container => container.items.some(item => item.item_id === item_id));
|
|
63
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MoveCandidate } from '../../move/apply_move.js';
|
|
2
|
+
/**
|
|
3
|
+
* Selects beam expansions: ranked top_k plus every supporter-top slot.
|
|
4
|
+
* @param ranked - Candidates already ranked floor-first.
|
|
5
|
+
* @param top_k - Beam top-k from config.
|
|
6
|
+
* @returns Candidates for trial evaluation.
|
|
7
|
+
*/
|
|
8
|
+
export declare function select_beam_expansion_candidates(ranked: MoveCandidate[], top_k: number): MoveCandidate[];
|
|
9
|
+
//# sourceMappingURL=select_beam_expansion_candidates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select_beam_expansion_candidates.d.ts","sourceRoot":"","sources":["../../../../src/core/strategies/reorder/select_beam_expansion_candidates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAE7D;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC5C,MAAM,EAAE,aAAa,EAAE,EACvB,KAAK,EAAE,MAAM,GACd,aAAa,EAAE,CAKjB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Selects beam expansions: ranked top_k plus every supporter-top slot.
|
|
3
|
+
* @param ranked - Candidates already ranked floor-first.
|
|
4
|
+
* @param top_k - Beam top-k from config.
|
|
5
|
+
* @returns Candidates for trial evaluation.
|
|
6
|
+
*/
|
|
7
|
+
export function select_beam_expansion_candidates(ranked, top_k) {
|
|
8
|
+
const leading = ranked.slice(0, top_k);
|
|
9
|
+
const supporter_top = ranked.filter(candidate => candidate.slot_kind === 'supporter_top');
|
|
10
|
+
return unique_move_positions([...leading, ...supporter_top]);
|
|
11
|
+
}
|
|
12
|
+
function unique_move_positions(candidates) {
|
|
13
|
+
const seen = new Set();
|
|
14
|
+
const unique = [];
|
|
15
|
+
for (const candidate of candidates) {
|
|
16
|
+
const key = position_key(candidate);
|
|
17
|
+
if (seen.has(key)) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
seen.add(key);
|
|
21
|
+
unique.push(candidate);
|
|
22
|
+
}
|
|
23
|
+
return unique;
|
|
24
|
+
}
|
|
25
|
+
function position_key(candidate) {
|
|
26
|
+
const position = candidate.new_position;
|
|
27
|
+
return `${position.x}:${position.y}:${position.z}:${candidate.target_container_index}`;
|
|
28
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare const ITEM_WIRE_TO_CONTRACT: {
|
|
2
|
+
readonly _id: "item_id";
|
|
3
|
+
readonly groupId: "group_id";
|
|
4
|
+
readonly w: "width";
|
|
5
|
+
readonly h: "height";
|
|
6
|
+
readonly d: "depth";
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Cargo-movement wire keys feeding each contract item field, in precedence
|
|
10
|
+
* order. Items are read-only for the stabilizer apart from their position, so
|
|
11
|
+
* these keys are read rather than renamed: the original wire record is
|
|
12
|
+
* retained in `attributes` and is what gets emitted back.
|
|
13
|
+
*/
|
|
14
|
+
export declare const ITEM_CONTRACT_WIRE_KEYS: Readonly<{
|
|
15
|
+
item_id: string[];
|
|
16
|
+
group_id: string[];
|
|
17
|
+
waypoint_id: string[];
|
|
18
|
+
width: string[];
|
|
19
|
+
height: string[];
|
|
20
|
+
depth: string[];
|
|
21
|
+
weight: string[];
|
|
22
|
+
}>;
|
|
23
|
+
/** Item fields the stabilizer mutates, and therefore must emit itself. */
|
|
24
|
+
export declare const ITEM_POSITION_KEYS: string[];
|
|
25
|
+
export declare const CONTAINER_WIRE_TO_CONTRACT: {
|
|
26
|
+
readonly sequencia: "sequence";
|
|
27
|
+
readonly largura: "width";
|
|
28
|
+
readonly altura: "height";
|
|
29
|
+
readonly comprimento: "length";
|
|
30
|
+
};
|
|
31
|
+
export declare const ENV_WIRE_TO_CONTRACT: {
|
|
32
|
+
readonly eixos: "axles";
|
|
33
|
+
};
|
|
34
|
+
export declare const CONTRACT_TO_ITEM_WIRE: Record<string, string>;
|
|
35
|
+
export declare const CONTRACT_TO_CONTAINER_WIRE: Record<string, string>;
|
|
36
|
+
export declare const CONTRACT_TO_ENV_WIRE: Record<string, string>;
|
|
37
|
+
//# sourceMappingURL=cargo_movement_wire_field_map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cargo_movement_wire_field_map.d.ts","sourceRoot":"","sources":["../../../../src/core/validation/contract/cargo_movement_wire_field_map.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB;;;;;;CAMxB,CAAA;AAEV;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;EAQlC,CAAA;AAEF,0EAA0E;AAC1E,eAAO,MAAM,kBAAkB,UAAkB,CAAA;AAEjD,eAAO,MAAM,0BAA0B;;;;;CAK7B,CAAA;AAEV,eAAO,MAAM,oBAAoB;;CAEvB,CAAA;AAEV,eAAO,MAAM,qBAAqB,wBAAoC,CAAA;AACtE,eAAO,MAAM,0BAA0B,wBAAyC,CAAA;AAChF,eAAO,MAAM,oBAAoB,wBAAmC,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export const ITEM_WIRE_TO_CONTRACT = {
|
|
2
|
+
_id: 'item_id',
|
|
3
|
+
groupId: 'group_id',
|
|
4
|
+
w: 'width',
|
|
5
|
+
h: 'height',
|
|
6
|
+
d: 'depth'
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Cargo-movement wire keys feeding each contract item field, in precedence
|
|
10
|
+
* order. Items are read-only for the stabilizer apart from their position, so
|
|
11
|
+
* these keys are read rather than renamed: the original wire record is
|
|
12
|
+
* retained in `attributes` and is what gets emitted back.
|
|
13
|
+
*/
|
|
14
|
+
export const ITEM_CONTRACT_WIRE_KEYS = Object.freeze({
|
|
15
|
+
item_id: ['item_id', '_id'],
|
|
16
|
+
group_id: ['groupId', 'group_id'],
|
|
17
|
+
waypoint_id: ['waypoint_id'],
|
|
18
|
+
width: ['w', 'width'],
|
|
19
|
+
height: ['h', 'height'],
|
|
20
|
+
depth: ['d', 'depth'],
|
|
21
|
+
weight: ['wg', 'peso', 'weight']
|
|
22
|
+
});
|
|
23
|
+
/** Item fields the stabilizer mutates, and therefore must emit itself. */
|
|
24
|
+
export const ITEM_POSITION_KEYS = ['x', 'y', 'z'];
|
|
25
|
+
export const CONTAINER_WIRE_TO_CONTRACT = {
|
|
26
|
+
sequencia: 'sequence',
|
|
27
|
+
largura: 'width',
|
|
28
|
+
altura: 'height',
|
|
29
|
+
comprimento: 'length'
|
|
30
|
+
};
|
|
31
|
+
export const ENV_WIRE_TO_CONTRACT = {
|
|
32
|
+
eixos: 'axles'
|
|
33
|
+
};
|
|
34
|
+
export const CONTRACT_TO_ITEM_WIRE = invert_map(ITEM_WIRE_TO_CONTRACT);
|
|
35
|
+
export const CONTRACT_TO_CONTAINER_WIRE = invert_map(CONTAINER_WIRE_TO_CONTRACT);
|
|
36
|
+
export const CONTRACT_TO_ENV_WIRE = invert_map(ENV_WIRE_TO_CONTRACT);
|
|
37
|
+
function invert_map(source) {
|
|
38
|
+
const inverted = {};
|
|
39
|
+
for (const [wire_key, contract_key] of Object.entries(source)) {
|
|
40
|
+
inverted[contract_key] = wire_key;
|
|
41
|
+
}
|
|
42
|
+
return inverted;
|
|
43
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { StabilizerCargoState } from './stabilizer_domain_schema.js';
|
|
2
|
+
/**
|
|
3
|
+
* Maps a cargo-movement wire payload to the English contract shape.
|
|
4
|
+
* @param input_data - Unknown CM wire payload.
|
|
5
|
+
* @returns Object ready for strict contract parsing.
|
|
6
|
+
*/
|
|
7
|
+
export declare function map_wire_input_to_contract(input_data: unknown): unknown;
|
|
8
|
+
/**
|
|
9
|
+
* Maps an English contract cargo state back to cargo-movement wire shape.
|
|
10
|
+
* @param cargo_state - English contract cargo state.
|
|
11
|
+
* @returns CM wire cargo state.
|
|
12
|
+
*/
|
|
13
|
+
export declare function map_contract_to_wire_output(cargo_state: StabilizerCargoState): unknown;
|
|
14
|
+
//# sourceMappingURL=cargo_movement_wire_mapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cargo_movement_wire_mapper.d.ts","sourceRoot":"","sources":["../../../../src/core/validation/contract/cargo_movement_wire_mapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAA;AAOzE;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAsBvE;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,oBAAoB,GAAG,OAAO,CAGtF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { map_cargo_state_to_wire } from './map_contract_to_wire_shape.js';
|
|
2
|
+
import { map_cargo_state_to_contract } from './map_wire_input_to_contract_shape.js';
|
|
3
|
+
import { is_record } from './wire_mapper_record_utils.js';
|
|
4
|
+
const INPUT_ENVELOPE_KEYS = new Set(['id', 'company', 'cargo_state', 'config', 'original_input']);
|
|
5
|
+
/**
|
|
6
|
+
* Maps a cargo-movement wire payload to the English contract shape.
|
|
7
|
+
* @param input_data - Unknown CM wire payload.
|
|
8
|
+
* @returns Object ready for strict contract parsing.
|
|
9
|
+
*/
|
|
10
|
+
export function map_wire_input_to_contract(input_data) {
|
|
11
|
+
if (!is_record(input_data)) {
|
|
12
|
+
return input_data;
|
|
13
|
+
}
|
|
14
|
+
const mapped = {};
|
|
15
|
+
for (const [key, value] of Object.entries(input_data)) {
|
|
16
|
+
if (!INPUT_ENVELOPE_KEYS.has(key)) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (key === 'cargo_state') {
|
|
20
|
+
mapped.cargo_state = map_cargo_state_to_contract(value);
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
mapped[key] = value;
|
|
24
|
+
}
|
|
25
|
+
return mapped;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Maps an English contract cargo state back to cargo-movement wire shape.
|
|
29
|
+
* @param cargo_state - English contract cargo state.
|
|
30
|
+
* @returns CM wire cargo state.
|
|
31
|
+
*/
|
|
32
|
+
export function map_contract_to_wire_output(cargo_state) {
|
|
33
|
+
return map_cargo_state_to_wire(cargo_state);
|
|
34
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ZodError } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Formats Zod validation issues into a single human-readable string.
|
|
4
|
+
* @param error - Zod validation error.
|
|
5
|
+
* @returns Semicolon-separated path messages.
|
|
6
|
+
*/
|
|
7
|
+
export declare function format_zod_error(error: ZodError): string;
|
|
8
|
+
//# sourceMappingURL=format_zod_error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format_zod_error.d.ts","sourceRoot":"","sources":["../../../../src/core/validation/contract/format_zod_error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAA;AAEnC;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAOxD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats Zod validation issues into a single human-readable string.
|
|
3
|
+
* @param error - Zod validation error.
|
|
4
|
+
* @returns Semicolon-separated path messages.
|
|
5
|
+
*/
|
|
6
|
+
export function format_zod_error(error) {
|
|
7
|
+
return error.issues.map(issue => {
|
|
8
|
+
const path = issue.path.length > 0 ? issue.path.join('.') : '(root)';
|
|
9
|
+
return `${path}: ${issue.message}`;
|
|
10
|
+
}).join('; ');
|
|
11
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { format_zod_error } from './format_zod_error.js';
|
|
2
|
+
export { ITEM_WIRE_TO_CONTRACT, CONTAINER_WIRE_TO_CONTRACT, ENV_WIRE_TO_CONTRACT, CONTRACT_TO_ITEM_WIRE, CONTRACT_TO_CONTAINER_WIRE, CONTRACT_TO_ENV_WIRE } from './cargo_movement_wire_field_map.js';
|
|
3
|
+
export { map_wire_input_to_contract, map_contract_to_wire_output } from './cargo_movement_wire_mapper.js';
|
|
4
|
+
export { stabilizer_item_schema, stabilizer_container_schema, stabilizer_env_schema, stabilizer_cargo_state_schema, validate_primary_env_waypoints, type StabilizerItem, type StabilizerContainer, type StabilizerEnv, type StabilizerCargoState } from './stabilizer_domain_schema.js';
|
|
5
|
+
export { stabilizer_input_schema, type StabilizerInput } from './stabilizer_input_schema.js';
|
|
6
|
+
export { stabilizer_response_schema, stabilizer_success_response_schema, stabilizer_error_response_schema, type StabilizerResponse, type StabilizerSuccessResponse, type StabilizerErrorResponse } from './stabilizer_output_schema.js';
|
|
7
|
+
export { parse_stabilizer_input, safe_parse_stabilizer_input } from './parse_stabilizer_input.js';
|
|
8
|
+
export { parse_stabilizer_output, safe_parse_stabilizer_output } from './parse_stabilizer_output.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/validation/contract/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EACH,qBAAqB,EACrB,0BAA0B,EAC1B,oBAAoB,EACpB,qBAAqB,EACrB,0BAA0B,EAC1B,oBAAoB,EACvB,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EACH,0BAA0B,EAC1B,2BAA2B,EAC9B,MAAM,iCAAiC,CAAA;AACxC,OAAO,EACH,sBAAsB,EACtB,2BAA2B,EAC3B,qBAAqB,EACrB,6BAA6B,EAC7B,8BAA8B,EAC9B,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EAC5B,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,uBAAuB,EAAE,KAAK,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAC5F,OAAO,EACH,0BAA0B,EAC1B,kCAAkC,EAClC,gCAAgC,EAChC,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAC/B,MAAM,+BAA+B,CAAA;AACtC,OAAO,EACH,sBAAsB,EACtB,2BAA2B,EAC9B,MAAM,6BAA6B,CAAA;AACpC,OAAO,EACH,uBAAuB,EACvB,4BAA4B,EAC/B,MAAM,8BAA8B,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { format_zod_error } from './format_zod_error.js';
|
|
2
|
+
export { ITEM_WIRE_TO_CONTRACT, CONTAINER_WIRE_TO_CONTRACT, ENV_WIRE_TO_CONTRACT, CONTRACT_TO_ITEM_WIRE, CONTRACT_TO_CONTAINER_WIRE, CONTRACT_TO_ENV_WIRE } from './cargo_movement_wire_field_map.js';
|
|
3
|
+
export { map_wire_input_to_contract, map_contract_to_wire_output } from './cargo_movement_wire_mapper.js';
|
|
4
|
+
export { stabilizer_item_schema, stabilizer_container_schema, stabilizer_env_schema, stabilizer_cargo_state_schema, validate_primary_env_waypoints } from './stabilizer_domain_schema.js';
|
|
5
|
+
export { stabilizer_input_schema } from './stabilizer_input_schema.js';
|
|
6
|
+
export { stabilizer_response_schema, stabilizer_success_response_schema, stabilizer_error_response_schema } from './stabilizer_output_schema.js';
|
|
7
|
+
export { parse_stabilizer_input, safe_parse_stabilizer_input } from './parse_stabilizer_input.js';
|
|
8
|
+
export { parse_stabilizer_output, safe_parse_stabilizer_output } from './parse_stabilizer_output.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map_contract_to_wire_shape.d.ts","sourceRoot":"","sources":["../../../../src/core/validation/contract/map_contract_to_wire_shape.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAA;AAGzE,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,oBAAoB,GAAG,OAAO,CAUlF"}
|