<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Help with Custom Evaluators in ArcGIS Pro 3.2 in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/help-with-custom-evaluators-in-arcgis-pro-3-2/m-p/1362747#M76558</link>
    <description>&lt;P&gt;Hello, I need some help understanding how best to use&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/network-analyst/custom-evaluators.htm#" target="_blank"&gt;Custom evaluators—ArcGIS Pro | Documentation&lt;/A&gt;&amp;nbsp;with ArcGIS Pro 3.2. I am attempting to create a custom evaluator class that will mimic the behavior of adding a strong restriction or preference for routes based on an attribute value. However, I have a list of many different attribute values I need to create routes for to demonstrate how the route solver output changes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think my trouble is that this class might only be accessing the cost attribute of the Edge and not actually looking at when Edge != Priority_Type.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anybody have advice?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;class EdgeCustomizer(arcpy.nax.AttributeEvaluator, Priority_Type):
    def attach(self, network_query: arcpy.nax.NetworkQuery) -&amp;gt; bool:
        """Connect to and validate the network dataset."""
        # Do additional validation checks before returning Boolean
        return True

    def refresh(self) -&amp;gt; None:
        """Reset internal state before solve."""
        # Reset internal state in this method as needed
        pass
    
    def edgeValue(self, edge: arcpy.nax.Edge, Priority_Type):
        # Get the value of the "Field_Type" attribute for the current edge
        field_type_value = self.networkQuery.attributeValue(edge, "Field_Type")
        # Check if the value is not equal to Priority_Type
        if field_type_value != Priority_Type:
            base_value = self.networkQuery.attributeValue(edge, self.attribute)
            base_multiplier = 10
            return base_value * base_multiplier
        else:
            # Return the original cost if the value is Priority_Type
            return self.networkQuery.attributeValue(edge, self.attribute)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Dec 2023 19:26:01 GMT</pubDate>
    <dc:creator>Gideon_Singer_Abt</dc:creator>
    <dc:date>2023-12-19T19:26:01Z</dc:date>
    <item>
      <title>Help with Custom Evaluators in ArcGIS Pro 3.2</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/help-with-custom-evaluators-in-arcgis-pro-3-2/m-p/1362747#M76558</link>
      <description>&lt;P&gt;Hello, I need some help understanding how best to use&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/network-analyst/custom-evaluators.htm#" target="_blank"&gt;Custom evaluators—ArcGIS Pro | Documentation&lt;/A&gt;&amp;nbsp;with ArcGIS Pro 3.2. I am attempting to create a custom evaluator class that will mimic the behavior of adding a strong restriction or preference for routes based on an attribute value. However, I have a list of many different attribute values I need to create routes for to demonstrate how the route solver output changes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think my trouble is that this class might only be accessing the cost attribute of the Edge and not actually looking at when Edge != Priority_Type.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anybody have advice?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;class EdgeCustomizer(arcpy.nax.AttributeEvaluator, Priority_Type):
    def attach(self, network_query: arcpy.nax.NetworkQuery) -&amp;gt; bool:
        """Connect to and validate the network dataset."""
        # Do additional validation checks before returning Boolean
        return True

    def refresh(self) -&amp;gt; None:
        """Reset internal state before solve."""
        # Reset internal state in this method as needed
        pass
    
    def edgeValue(self, edge: arcpy.nax.Edge, Priority_Type):
        # Get the value of the "Field_Type" attribute for the current edge
        field_type_value = self.networkQuery.attributeValue(edge, "Field_Type")
        # Check if the value is not equal to Priority_Type
        if field_type_value != Priority_Type:
            base_value = self.networkQuery.attributeValue(edge, self.attribute)
            base_multiplier = 10
            return base_value * base_multiplier
        else:
            # Return the original cost if the value is Priority_Type
            return self.networkQuery.attributeValue(edge, self.attribute)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 19:26:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/help-with-custom-evaluators-in-arcgis-pro-3-2/m-p/1362747#M76558</guid>
      <dc:creator>Gideon_Singer_Abt</dc:creator>
      <dc:date>2023-12-19T19:26:01Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Custom Evaluators in ArcGIS Pro 3.2</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/help-with-custom-evaluators-in-arcgis-pro-3-2/m-p/1362753#M76559</link>
      <description>&lt;P&gt;Also, what had me interested was the following quote: "Custom evaluators are implemented by creating a Python class that inherits from the arcpy.nax.AttributeEvaluator and associating the Python class with a particular network dataset. &lt;STRONG&gt;They can be associated with cost, restriction, or descriptor attributes.&lt;/STRONG&gt; They can &lt;STRONG&gt;update edges&lt;/STRONG&gt;, junctions, or turns for time-enabled solves as well as solves that are not time enabled. Depending on the changes made, the updates may alter the costs and paths found during analysis".&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am hoping to create a temporary cost/restriction that will be used to update edges during a route solve.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 19:32:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/help-with-custom-evaluators-in-arcgis-pro-3-2/m-p/1362753#M76559</guid>
      <dc:creator>Gideon_Singer_Abt</dc:creator>
      <dc:date>2023-12-19T19:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Custom Evaluators in ArcGIS Pro 3.2</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/help-with-custom-evaluators-in-arcgis-pro-3-2/m-p/1389788#M79644</link>
      <description>&lt;P&gt;Custom evaluators work on network elements (e.g. edges), as such source feature field values are not directly accessible, but a network descriptor attribute that accesses source feature field values can be used instead.&lt;/P&gt;&lt;P&gt;In your case it looks like you have an attribute called Field_Type that you want to use in the custom evaluator. And I think you want to be able to pass in a value to use as the priority type.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Step 1 - Update the network dataset&lt;/STRONG&gt;&lt;BR /&gt;- open the network dataset properties&lt;BR /&gt;- go to Travel Attribute &amp;gt; Descriptors&lt;BR /&gt;- add a descriptor attribute that reads the Field_Type attribute (e.g. naming it Field_Type_Descriptor)&lt;BR /&gt;- re-build the network&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Step 2 - Update the custom evaluator code&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;a) Add the init method with an argument for the priority type value&lt;/P&gt;&lt;PRE&gt;def __init__(self, attribute_name: str, Priority_Type: int): &lt;BR /&gt;   self.priority_type = Priority_Type &lt;BR /&gt;   super().__init__(attribute_name)&lt;/PRE&gt;&lt;P&gt;b) In the refresh method get the descriptor’s attribute index:&lt;/P&gt;&lt;PRE&gt;def refresh(self) -&amp;gt; None: &lt;BR /&gt;   self.field_type_descriptor = self.networkQuery.attribute("Field_Type_Descriptor")&lt;/PRE&gt;&lt;P&gt;c) In edgeValue use descriptor attribute index to get the field value:&lt;/P&gt;&lt;PRE&gt;def edgeValue(self, edge: arcpy.nax.Edge) : &lt;BR /&gt;   base_value = self.networkQuery.attributeValue(edge, self.attribute)&lt;BR /&gt;   field_type_value = self.networkQuery.attributeValue(edge, self.field_type_descriptor) &lt;BR /&gt;   if field_type_value != self.priority_type:&lt;BR /&gt;      base_multiplier = 10 &lt;BR /&gt;      return base_value * base_multiplier&lt;BR /&gt;   else: &lt;BR /&gt;      return base_value&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;Setup 3 - update the solving code&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;When creating an EdgeCustomizer object pass in the cost attribute name that will be update and the value of the priority to use.&lt;/P&gt;&lt;PRE&gt;priority_value = 5&lt;BR /&gt;# set the cost attribute to alter and the priority value to use &lt;BR /&gt;ce_list = [EdgeCustomizer("TravelTime", priority_value)] &lt;BR /&gt;network_dataset.customEvaluators = ce_list&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;I've also attached an example script with the above and gdb where I added a Field_Type to the streets and a descriptor to the network dataset (the data is a small subset of the San Fransisco data in the Network Analyst Pro Tutorial data).&lt;/P&gt;&lt;P&gt;Tell me if this helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Mar 2024 00:01:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/help-with-custom-evaluators-in-arcgis-pro-3-2/m-p/1389788#M79644</guid>
      <dc:creator>FrankKish</dc:creator>
      <dc:date>2024-03-02T00:01:05Z</dc:date>
    </item>
  </channel>
</rss>

