ArcObjects Library Reference

Set Solver Properties Snippet

Set generic solver parameters.

[C#]

///<summary>Set generic solver parameters.</summary>
/// 
///<param name="naSolver">An INASolver interface.</param>
///<param name="impedanceAttributeName">A System.String that is the name of the impedance attribute that you wish to minimize. Ex: "Minutes"</param>
///<param name="restrictionAttributeName">A System.String that is the name of one the restriction attribute that you wish to honor. Ex: "HeightRestriction"</param>
///<param name="attributeName">A System.String that is the name of the attribute whose parameter value you wish to change. Ex: "HeightRestriction"</param>
///<param name="paramName">A System.String that is the name of the parameter whose value you wish to change. Ex: "VehicleHeight"</param>
///<param name="parameterValue">A System.Int32 that is value of the parameter. Ex: 10</param>
///<param name="accumulateAttribute">A System.String that is the one name of the impedance attribute that you wish to accumulate. Ex: "Distance"</param>
///<param name="hierarchyAttributeName">A System.String that is the name of the hierarchy attribute that you wish to use. Ex: "Hierarchy"</param>
/// 
///<returns>An INASolverSettings2 interface.</returns>
/// 
///<remarks></remarks>
public ESRI.ArcGIS.NetworkAnalyst.INASolverSettings2 SetSolverProperties(ESRI.ArcGIS.NetworkAnalyst.INASolver naSolver, System.String impedanceAttributeName, System.String restrictionAttributeName, System.String attributeName, System.String paramName, System.Int32 parameterValue, System.String accumulateAttribute, System.String hierarchyAttributeName)
{

  // Set generic solver parameters, including...
  ESRI.ArcGIS.NetworkAnalyst.INASolverSettings2 naSolverSettings2 = (ESRI.ArcGIS.NetworkAnalyst.INASolverSettings2)naSolver;

  // ...impedance attribute
  naSolverSettings2.ImpedanceAttributeName = impedanceAttributeName;

  // ...restriction attributes
  ESRI.ArcGIS.esriSystem.IStringArray stringArrayRestrictionAttributes = naSolverSettings2.RestrictionAttributeNames;
  stringArrayRestrictionAttributes.Add(restrictionAttributeName);
  naSolverSettings2.RestrictionAttributeNames = stringArrayRestrictionAttributes;

  // ...attribute parameters
  naSolverSettings2.set_AttributeParameterValue(attributeName, paramName, parameterValue);

  // ...accumulated attributes
  ESRI.ArcGIS.esriSystem.IStringArray stringArrayAccumulateAttributes = naSolverSettings2.AccumulateAttributeNames;
  stringArrayAccumulateAttributes.Add(accumulateAttribute);
  naSolverSettings2.AccumulateAttributeNames = stringArrayAccumulateAttributes;

  // ...hierarchies
  naSolverSettings2.UseHierarchy = true;
  naSolverSettings2.HierarchyAttributeName = hierarchyAttributeName;

  // ...UTurn policy
  naSolverSettings2.RestrictUTurns = ESRI.ArcGIS.Geodatabase.esriNetworkForwardStarBacktrack.esriNFSBAllowBacktrack;
  naSolverSettings2.IgnoreInvalidLocations = true;

  return naSolverSettings2;

}
[Visual Basic .NET]

'''<summary>Set generic solver parameters.</summary>
''' 
'''<param name="naSolver">An INASolver interface.</param>
'''<param name="impedanceAttributeName">A System.String that is the name of the impedance attribute that you wish to minimize. Ex: "Minutes"</param>
'''<param name="restrictionAttributeName">A System.String that is the name of one the restriction attribute that you wish to honor. Ex: "HeightRestriction"</param>
'''<param name="attributeName">A System.String that is the name of the attribute whose parameter value you wish to change. Ex: "HeightRestriction"</param>
'''<param name="paramName">A System.String that is the name of the parameter whose value you wish to change. Ex: "VehicleHeight"</param>
'''<param name="parameterValue">A System.Int32 that is value of the parameter. Ex: 10</param>
'''<param name="accumulateAttribute">A System.String that is the one name of the impedance attribute that you wish to accumulate. Ex: "Distance"</param>
'''<param name="hierarchyAttributeName">A System.String that is the name of the hierarchy attribute that you wish to use. Ex: "Hierarchy"</param>
''' 
'''<returns>An INASolverSettings2 interface.</returns>
''' 
'''<remarks></remarks>
Public Function SetSolverProperties(ByVal naSolver As ESRI.ArcGIS.NetworkAnalyst.INASolver, ByVal impedanceAttributeName As System.String, ByVal restrictionAttributeName As System.String, ByVal attributeName As System.String, ByVal paramName As System.String, ByVal parameterValue As System.Int32, ByVal accumulateAttribute As System.String, ByVal hierarchyAttributeName As System.String) As ESRI.ArcGIS.NetworkAnalyst.INASolverSettings2

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

  ' ...impedance attribute
  naSolverSettings2.ImpedanceAttributeName = impedanceAttributeName

  ' ...restriction attributes
  Dim stringArrayRestrictionAttributes As ESRI.ArcGIS.esriSystem.IStringArray = naSolverSettings2.RestrictionAttributeNames
  stringArrayRestrictionAttributes.Add(restrictionAttributeName)
  naSolverSettings2.RestrictionAttributeNames = stringArrayRestrictionAttributes

  ' ...attribute parameters
  naSolverSettings2.AttributeParameterValue(attributeName, paramName) = parameterValue

  ' ...accumulated attributes
  Dim stringArrayAccumulateAttributes As ESRI.ArcGIS.esriSystem.IStringArray = naSolverSettings2.AccumulateAttributeNames
  stringArrayAccumulateAttributes.Add(accumulateAttribute)
  naSolverSettings2.AccumulateAttributeNames = stringArrayAccumulateAttributes

  ' ...hierarchies
  naSolverSettings2.UseHierarchy = True
  naSolverSettings2.HierarchyAttributeName = hierarchyAttributeName

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

  Return naSolverSettings2

End Function


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