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

49 lines (48 loc) 2.81 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 { PreserveOrderJobHelper } from "../preserve-order/helpers/preserve-order-job-helper"; import { RouteViolationValidator } from "../../validations"; import { JobRemovePreserveOrderStrategy } from "./job-remove-preserve-order-strategy"; import { JobRemoveReoptimizeStrategy } from "./job-remove-reoptimize-strategy"; /** * Strategy that inserts jobs while preserving the order of existing stops. * * Behavior: * - append: true → Appends 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 point */ export class JobAssignPreserveOrderStrategy { execute(context, agentIndex, jobIndexes, options) { return __awaiter(this, void 0, void 0, function* () { yield this.removeJobsFromCurrentAgents(context, jobIndexes, options); for (let i = 0; i < jobIndexes.length; i++) { const insertPosition = yield PreserveOrderJobHelper.determineInsertPosition(context, agentIndex, jobIndexes[i], options); WaypointBuilder.insertJobWaypoint(context, agentIndex, jobIndexes[i], insertPosition); yield AgentPlanRecalculator.recalculate(context, agentIndex); } RouteViolationValidator.validate(context, agentIndex); return true; }); } removeJobsFromCurrentAgents(context, jobIndexes, 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 JobRemoveReoptimizeStrategy() : new JobRemovePreserveOrderStrategy(); const removeOptions = { strategy: removeStrategyType }; yield removeStrategy.execute(context, jobIndexes, removeOptions); }); } }