Unlisted
Edited
Feb 20
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
assets = FileAttachment("assets.json").json()
Insert cell
Insert cell
dumps = FileAttachment("dumps_geocode (1).csv").csv()
Insert cell
Insert cell
Insert cell
drivers = FileAttachment("drivers (1)-1.json").json()
Insert cell
Insert cell
Insert cell
mutable inputData_a = null
Insert cell
objectives = [
{ name: "Minimize Time", value: "duration" },
{ name: "Minimize Distance", value: "distance" }
]
Insert cell
inputs = {
const offset = new Date().getTimezoneOffset();
let newBase = new Date(new Date().getTime() + 86400 * 1000);
const inputString = "05/07/2024 03:00";
const tmrwStart = parseDateStringWithOffset(inputString, 240);

const endString = "05/07/2024 13:00";
const tmrwEnd = parseDateStringWithOffset(endString, 240);
const inputs = {
shiftStart: Inputs.datetime({
label: "Shift Start",
value: tmrwStart.toISOString().slice(0, -1)
}),
shiftEnd: Inputs.datetime({
label: "Shift End",
value: `${tmrwEnd.toISOString().slice(0, -1)}`
}),
objectiveFunction: Inputs.select(objectives, {
label: "Objective Function",
format: (x) => x.name,
value: objectives.find((t) => t.name === "Minimize Time")
}),
shiftHours: Inputs.text({
label: "Shift duration in hours",
value: "10"
}),
serviceTime: Inputs.text({
label: "Service Time at Each Stop",
value: "900"
})
};
return inputs;
}
Insert cell
function parseDateStringWithOffset(dateString, offsetMinutes) {
const [datePart, timePart] = dateString.split(" ");
const [day, month, year] = datePart.split("/").map(Number);
const [hours, minutes] = timePart.split(":").map(Number);

// Create a Date object in the local time zone
const localDate = new Date(year, month - 1, day, hours, minutes);

// Convert local time to UTC
const utcDate = new Date(
localDate.getTime() - localDate.getTimezoneOffset() * 60000
);

// Apply the desired offset
const offsetDate = new Date(utcDate.getTime() + offsetMinutes * 60000);

return offsetDate;
}
Insert cell
routesGeoJson = {
let routesGeoJson = {
type: "FeatureCollection",
features: []
};

// we create a geojson object to send to our mapview elements
// It will be a feature collection of all the route polylines
let bestRoute = -1;

mvrpID.forEach((sol, idx) => {
sol.result.routes.forEach((rte, idx) => {
console.log(rte);
let feature = {
type: "Feature",
properties: {
id: rte.vehicle,
vin: rte.description
},
geometry: {
coordinates: nextbillion.utils.polyline
.decode(rte.geometry, 5)
.map((c) => c.reverse()),
type: "LineString"
}
};
routesGeoJson.features.push(feature);
rte.steps.forEach((st, stIdx) => {
let stop = {
type: "Feature",
properties: {
id: rte.vehicle,
vin: rte.description,
description: st.description,
address: (st.type == "start") | (st.type == "end") ? "" : "",
customer: (st.type == "start") | (st.type == "end") ? "" : "",
stop_idx: stIdx,
arrival: st.arrival,
type: st.type,
pointType: (st.type == "start") | (st.type == "end") ? 16 : 255
},
geometry: {
coordinates: [st.location[1], st.location[0]],
type: "Point"
}
};
routesGeoJson.features.push(stop);
});
});
});

return routesGeoJson;
}
Insert cell
Insert cell
turf = require("https://unpkg.com/@turf/turf@6/turf.min.js")
Insert cell
Insert cell
import { toc } from "@nebrius/indented-toc" // This component generates the Table of Contents
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more