@solvice.io/node-onroute-client
v0.0.4
Published
OnRoute API Client in Node ==========================
Downloads
4
Readme
OnRoute API Client in Node
Based on the documentation in https://docs2.solvice.io/onroute
We have a hand-crafted API client (@solvice.io/node-onroute-client
) for the OnRoute route optimisation API that is more memory efficient e.g. for large instances than autogenerated client based on openapi.
Installation
npm install @solvice.io/node-onroute-client --save
Usage
Define the client
const api: OnRouteApi = new OnRouteApi({ apiKey: "<api key>" });
VRP
Define a solve job to send to the solve endpoint. Look at the VRP model for more details.
const vrp: VRP = {
solver: Solver.Vrp,
locations: [
{ name: "depot", latitude: 51.21112, longitude: 4.093 },
{ name: "l1", latitude: 50.721112, longitude: 4.893 },
{ name: "l2", latitude: 50.42342, longitude: 4.693 },
],
fleet: [
{ name: "bert", startlocation: "depot", shiftstart: 500, shiftend: 700 }
],
orders: [
{ name: "o1", location: "l1", duration: 10 },
{ name: "o2", location: "l2", duration: 15 }
],
options: { traffic: 1 }
}
Send VRP to the solver and fetch the solution.
// send to solver
const job: Job = await api.solve(vrp, 60);
// job has started solving
const startedSolving: Job = await api.pollSolving(job.id);
// job is solved. return solution
const solution: RoutingSolution = await api.pollSolved(job.id) as RoutingSolution;
PVRP
Define the Periodic VRP and add a planning period.
const vrp: PVRP = {
solver: Solver.Pvrp,
period: {
start: Date.now(),
end: Date.now()
},
locations: [
{ name: "depot", latitude: 51.21112, longitude: 4.093 },
{ name: "l1", latitude: 50.721112, longitude: 4.893 },
{ name: "l2", latitude: 50.42342, longitude: 4.693 },],
fleet: [
{ name: "bert", startlocation: "depot", shiftstart: 500, shiftend: 700 }
],
orders: [
{ name: "o1", location: "l1", duration: 10 },
{ name: "o2", location: "l2", duration: 15 }
],
options: { traffic: 1 }
}
// send to solver
const job: Job = await api.solve(vrp, 60);
// job has started solving
const startedSolving: Job = await api.pollSolving(job.id);
// job is solved. return solution
const solution: PeriodicRoutingSolution = await api.pollSolved(job.id) as PeriodicRoutingSolution;