Skip to main content

OptimizationMgr (React Native)

Contents

Note: All React Native methods are async functions.

OptimizationMgr

A native module representing the Advanced Optimization module within CoPilot.
React Native
>=10.14
Type
Native Module

Methods

Method Name Return Type Description
start()
OptStatus
Starts the Optimization process for given stops.
stop()
boolean
Stops the optimization process.

Hooks and Callbacks

Hooks and Callbacks related to Optimization can be found below.

OptimizationListener
onOptimizationProgress
onOptimizationError
onOptimizationStopError
onOptimizationStopGeocode
onOptimizationResult

OptimizationMgr.start

Starts the optimization process for given stops.
React Native
>=10.14
Type
Method

Syntax

constant start(optInHeader, optStopList)

Parameters

optInHeader - A JSON object containing header information.

optStopList - An array of OptStopList JSON objects, which are the input stops and break stops you are sending for optimization.

Return Value

Returns an OptimizationStatus detailing the result of the optimization.

Sample Code

const OptimizationMgr = NativeModules.OptimizationMgr;
const OptimizationStatus = NativeModules.OptimizationStatus;
const OptimizationDeliveryType = NativeModules.OptimizationDeliveryType;

var optInHeader = {};
optInHeader.startTime = 480;
optInHeader.isETACalculation = false;
optInHeader.timeout = 3000;
optInHeader.optDeliveryType =
  OptimizationDeliveryType.OPT_WITH_SINGLE_TIMEWINDOW;
optInHeader.startStopLatLon = {};
optInHeader.startStopLatLon.latitude = 40.36184;
optInHeader.startStopLatLon.longitude = -74.600032;
optInHeader.endStopLatLon = {};
optInHeader.endStopLatLon.latitude = 40.488265;
optInHeader.endStopLatLon.longitude = -74.445962;

var optStopList = [];

var stop1 = {};
stop1.stopNo = 1;
stop1.zip = "08540";
stop1.stateOrCountry = "NJ";
stop1.timeWindowStart = 360;
stop1.timeWindowEnd = 1024;
stop1.waitTime = 150;

var stop2 = {};
stop2.stopNo = 2;
stop2.zip = "08541";
stop2.stateOrCountry = "NJ";
stop2.timeWindowStart = 360;
stop2.timeWindowEnd = 1024;
stop2.waitTime = 150;

var stop3 = {};
stop3.stopNo = 3;
stop3.zip = "08542";
stop3.stateOrCountry = "NJ";
stop3.timeWindowStart = 360;
stop3.timeWindowEnd = 1024;
stop3.waitTime = 150;

var stop4 = {};
stop4.stopNo = 4;
stop4.zip = "08543";
stop4.stateOrCountry = "NJ";
stop4.timeWindowStart = 360;
stop4.timeWindowEnd = 1024;
stop4.waitTime = 150;

var stop5 = {};
stop5.stopNo = 5;
stop5.zip = "08544";
stop5.stateOrCountry = "NJ";
stop5.timeWindowStart = 360;
stop5.timeWindowEnd = 1024;
stop5.waitTime = 150;

optStopList.push(stop1);
optStopList.push(stop2);
optStopList.push(stop3);
optStopList.push(stop4);
optStopList.push(stop5);

var status = await OptimizationMgr.start(optInHeader, optStopList);

OptimizationMgr.stop

Stops the optimization process.
React Native
>=10.14
Type
Method

Syntax

bool stop()

Parameters

None

Return Value

Returns true to indicate that a request is being made for optimization to stop.

Returns false to indicate that optimization is already stopped.

Sample Code

const OptimizationMgr = NativeModules.OptimizationMgr;
var result = await OptimizationMgr.stop();
Last updated January 10, 2024.
Contents