This document is archived and information here might be outdated.  Recommended version.


Statements - Set Solver Properties Snippet (ArcObjects .NET 10.5 SDK)
ArcObjects Library Reference

Statements - Set Solver Properties Snippet

Set generic solver parameters.

[C#]
//<-- Snippet Start -->
// DESCRIPTION:

// Set generic solver parameters, including...
ESRI.ArcGIS.NetworkAnalyst.INASolverSettings2 naSolverSettings=naSolver as ESRI.ArcGIS.NetworkAnalyst.INASolverSettings2;

// ...impedance attribute
naSolverSettings.ImpedanceAttributeName="Minutes";

// ...restriction attributes
ESRI.ArcGIS.esriSystem.IStringArray restrictionAttributes=naSolverSettings.RestrictionAttributeNames;
restrictionAttributes.Add("HeightRestriction");
naSolverSettings.RestrictionAttributeNames=restrictionAttributes;                           

// ...attribute parameters
naSolverSettings.set_AttributeParameterValue("HeightRestriction", "VehicleHeight", 10);

// ...accumulated attributes
ESRI.ArcGIS.esriSystem.IStringArray accumulateAttributes=naSolverSettings.AccumulateAttributeNames;              
accumulateAttributes.Add("Distance");                                                     
naSolverSettings.AccumulateAttributeNames=accumulateAttributes;                           

// ...hierarchies
naSolverSettings.UseHierarchy=true;
naSolverSettings.HierarchyAttributeName="Hierarchy";

// ...UTurn policy
naSolverSettings.RestrictUTurns=ESRI.ArcGIS.Geodatabase.esriNetworkForwardStarBacktrack.esriNFSBAllowBacktrack;

// ...invalid location handling
naSolverSettings.IgnoreInvalidLocations=true;

//<-- Snippet End -->
[Visual Basic .NET]
'<-- Snippet Start -->
' DESCRIPTION:

' Set generic solver parameters, including...
Dim naSolverSettings As ESRI.ArcGIS.NetworkAnalyst.INASolverSettings2=CType(naSolver, ESRI.ArcGIS.NetworkAnalyst.INASolverSettings2)

' ...impedance attribute
naSolverSettings.ImpedanceAttributeName="Minutes"

' ...restriction attributes
Dim restrictionAttributes As ESRI.ArcGIS.esriSystem.IStringArray=naSolverSettings.RestrictionAttributeNames
restrictionAttributes.Add("HeightRestriction")
naSolverSettings.RestrictionAttributeNames=restrictionAttributes

' ...attribute parameters
naSolverSettings.AttributeParameterValue("HeightRestriction", "VehicleHeight")=10

' ...accumulated attributes
Dim accumulateAttributes As ESRI.ArcGIS.esriSystem.IStringArray=naSolverSettings.AccumulateAttributeNames
accumulateAttributes.Add("Distance")
naSolverSettings.AccumulateAttributeNames=accumulateAttributes

' ...hierarchies
naSolverSettings.UseHierarchy=True
naSolverSettings.HierarchyAttributeName="Hierarchy"

' ...UTurn policy
naSolverSettings.RestrictUTurns=ESRI.ArcGIS.Geodatabase.esriNetworkForwardStarBacktrack.esriNFSBAllowBacktrack
naSolverSettings.IgnoreInvalidLocations=True

'<-- Snippet End -->

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Geodatabase
  • ESRI.ArcGIS.NetworkAnalyst
  • ESRI.ArcGIS.System