Skip to main content

MPT

Generate MPT Problem

Usually, you will generate your problem from your current Axioroute State. You can do this with:

let myProblem = MPTJobTools.getProblem(myCurrentState);

This will return a MPT problem that you can send to the Axioroute API. By default the Action on this State will be COMPUTE_ROUTES. You can see all available actions within Axioroute MPT API reference.

To pass a custom action just do:

let action = {
type: 'UNSCHEDULE_EXISTING_ROUTES' //remove routes from your state
routes: ['myRouteToDeleteID']
}
let myProblem = MPTJobTools.getProblem(myCurrentState, action)

Verify the Problem

Before sending your message you can check if your problem is valid with:

let isMyProblemValid = MPTJobTools.isVerified(myProblem);

If not you can see what's missing with:

let errors = MPTJobTools.verify(myProblem); //will return a list of error statuses if not verified, ['OK'] if verified

Send the Problem

You can send your MPT problem with:

const job = await ARRequestClient.instance().sendMPTProblem(myProblem);
let myJobId = job.id; //this is the id of your job, you can use it to track your request

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.

Updating your State

once you received the solution to your problem you wan't to reflect it in your current State. This can be achieved by:

ARRequestClient.instance().subscribe("RECEIVED", (mptRequest) => {
//we check that the request is for our job, and we ignore any other request
if (mptRequest.id !== myJobId) return;

//We create our next State from the previous State merged with our MPT Solution
let myNewState = MPTJobTools.updateState(
myPreviousState,
mptRequest.job.solution
);
});