UNPKG

@geoapify/route-planner-sdk

Version:

TypeScript SDK for the Geoapify Route Planner API. Supports route optimization, delivery planning, and timeline visualization in browser and Node.js

50 lines (49 loc) 3 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { PRESERVE_ORDER, REOPTIMIZE } from "../../../../models"; import { AgentPlanRecalculator, WaypointBuilder } from "../preserve-order"; import { PreserveOrderShipmentHelper } from "../preserve-order/helpers/preserve-order-shipment-helper"; import { RouteViolationValidator } from "../../validations"; import { ShipmentRemovePreserveOrderStrategy } from "./shipment-remove-preserve-order-strategy"; import { ShipmentRemoveReoptimizeStrategy } from "./shipment-remove-reoptimize-strategy"; /** * Strategy that inserts shipments while preserving the order of existing stops. * Considers pickup-delivery constraints (pickup must come before delivery). * * Behavior: * - append: true → Appends pickup and delivery to end of route (no API call) * - afterId/insertAtIndex → Inserts at specified position (no API call) * - No position params → Uses Route Matrix API to find optimal insertion points */ export class ShipmentAssignPreserveOrderStrategy { execute(context, agentIndex, shipmentIndexes, options) { return __awaiter(this, void 0, void 0, function* () { yield this.removeShipmentsFromCurrentAgents(context, shipmentIndexes, options); for (const shipmentIndex of shipmentIndexes) { const positions = yield PreserveOrderShipmentHelper.determineShipmentInsertPositions(context, agentIndex, shipmentIndex, options); WaypointBuilder.insertShipmentWaypoints(context, agentIndex, shipmentIndex, positions); yield AgentPlanRecalculator.recalculate(context, agentIndex); } RouteViolationValidator.validate(context, agentIndex); return true; }); } removeShipmentsFromCurrentAgents(context, shipmentIndexes, options) { var _a; return __awaiter(this, void 0, void 0, function* () { const removeStrategyType = (_a = options.removeStrategy) !== null && _a !== void 0 ? _a : PRESERVE_ORDER; const removeStrategy = removeStrategyType === REOPTIMIZE ? new ShipmentRemoveReoptimizeStrategy() : new ShipmentRemovePreserveOrderStrategy(); const removeOptions = { strategy: removeStrategyType }; yield removeStrategy.execute(context, shipmentIndexes, removeOptions); }); } }