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:
- Retrieve the internal OD Cost Matrix Result object.
- Set the result to save its matrix when persisting the VRP layer.
- 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 solverWhat is Network Analyst?
About the Network Analyst Tutorial
Essential Network Analyst vocabulary
NetworkAnalyst
Network Analyst 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 Runtime: Network |
ArcInfo: Network Analyst | ArcInfo: Network Analyst |
ArcEditor: Network Analyst | ArcEditor: Network Analyst |
ArcView: Network Analyst | ArcView: Network Analyst |