MCI
Generate MCI Problem
From an existing route
You can generate the MCI Problem Definition from an existing route in your current State.
let myMCIProblem = MCIJobTools.getProblem("myRouteId", myCurrentState);
You can get the list of available routeIds with: Route.getAllRouteIds(myCurrentState)
From scratch
MCI Problem are not always related to an existing route. Hence MCI Problem definition can also be done from scratch by following Axioroute MCI API reference.
Here is a minimal example:
let myMCIProblem = {
sitePoints: [
{
id: "START",
longitude: -0.561642,
latitude: 47.462544,
},
{
id: "END",
longitude: -0.345602,
latitude: 48.597481,
},
],
};
Send the Problem
You can send your MPT problem with:
let job = await ARRequestClient.instance().sendMCIProblem(myMCIProblem);
let jobId = job.id; //this is the id of your job, you can use it to track your request
Update your State
Also to keep track of links between routes from your Axioroute state and MCI Jobs you need to explicitly link them with:
let myNewState = MCIJobTools.addLinkedMCIjob(
job,
"myRouteId", //the routeId of the route we want to link with the MCI Problem
previousState
);
Get the Solution
To get your solution and/or the current progress you'll need to subscribe to events as explained in Listening to Request Events.
Update your State
If you've generated your MCI Problem from an existing route, you can update your State with the solution (also work with LOADING
event) like this:
ARRequestClient.instance().subscribe("RECEIVED", (request) => {
//we check that the request is for our job, and we ignore any other request
if (request.id !== myJobId) return;
//If you have already linked your MCI Problem to an existng route, you can update your state with:
let myNewState = MCIJobTools.updateLinkedMCIjob(job, previousState);
});
MCI Problem / Solution not linked to a route will not be reflected in your Axioroute State.
You have to store them within your application state if you want to keep track of them.