How to speed up VRP solves


Speeding up VRP solves

The OD Cost Matrix internal to a Vehicle Routing Problem (VRP) can be configured to be reused on subsequent solves of the same VRP. This reduces the time it takes to solve a VRP.
To speed up solving VRPs by reusing previous results on subsequent solves, perform the following steps:
  1. Retrieve the internal OD Cost Matrix Result object.
  2. Set the result to save its matrix when persisting the VRP layer.
  3. Set the internal OD result of the VRP layer to only update for added/removed orders or depots.
These steps are shown in the following code:
[C#]
public void SetVRPLayerToSaveODInUpdateMode(ESRI.ArcGIS.NetworkAnalyst.INALayer
    vrpLayer)
{
    // Retrieve the internal OD cost matrix result object.
    var vrpResult = vrpLayer.Context.Result as
        ESRI.ArcGIS.NetworkAnalyst.INAVRPResult;
    var odResult = vrpResult.InternalODCostMatrix as
        ESRI.ArcGIS.NetworkAnalyst.INAODCostMatrixResult;

    // Set the result to save its matrix when persisting the VRP layer.
    odResult.SaveMatrixOnPersist = true;

    // Set the internal OD result of the VRP layer to only update for added/removed orders or depots.
    var vrpSolverSettings = vrpLayer.Context.Solver as
        ESRI.ArcGIS.NetworkAnalyst.INAVRPSolver;
    vrpSolverSettings.InternalODCostMatrixType =
        ESRI.ArcGIS.NetworkAnalyst.esriNAODCostMatrixType.esriNAODCostMatrixUpdate;
}
[VB.NET]
Public Sub SetVRPLayerToSaveODInUpdateMode(ByVal vrpLayer As ESRI.ArcGIS.NetworkAnalyst.INALayer)
    ' Retrieve the internal OD cost matrix result object.
    Dim vrpResult = TryCast(vrpLayer.Context.Result, ESRI.ArcGIS.NetworkAnalyst.INAVRPResult)
    Dim odResult = TryCast(vrpResult.InternalODCostMatrix, ESRI.ArcGIS.NetworkAnalyst.INAODCostMatrixResult)
    
    ' Set the result to save its matrix when persisting the VRP layer.
    odResult.SaveMatrixOnPersist = True
    
    ' Set the internal OD result of the VRP layer to only update for added/removed orders or depots.
    Dim vrpSolverSettings = TryCast(vrpLayer.Context.Solver, ESRI.ArcGIS.NetworkAnalyst.INAVRPSolver)
    vrpSolverSettings.InternalODCostMatrixType = ESRI.ArcGIS.NetworkAnalyst.esriNAODCostMatrixType.esriNAODCostMatrixUpdate
End Sub


See Also:

Sample: Vehicle routing problem solver
What is ArcGIS Network Analyst extension?
About the ArcGIS Network Analyst extension Tutorial
Essential ArcGIS Network Analyst extension vocabulary
NetworkAnalyst
ArcGIS Network Analyst extension Object Model Diagram




To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
Engine Developer Kit Engine: Network Analyst
ArcGIS for Desktop Advanced: Network Analyst ArcGIS for Desktop Advanced: Network Analyst
ArcGIS for Desktop Standard: Network Analyst ArcGIS for Desktop Standard: Network Analyst
ArcGIS for Desktop Basic: Network Analyst ArcGIS for Desktop Basic: Network Analyst