ArcGIS Pro 3.6 API Reference Guide
ArcGIS.Core.Data.Knowledge.Analytics Namespace / KnowledgeGraphFilteredFindPathsResults Class / MaterializePath Method
The index of the path (0 <= pathIndex < CountPaths).
Example

In This Topic
    MaterializePath Method
    In This Topic
    Returns a materialization of a result path, or null if the path is invalid, i.e some entities or relationships of the path have been deleted during pathfinding.
    Syntax
    public Nullable<ResultPath> MaterializePath( 
       long pathIndex
    )
    Public Function MaterializePath( _
       ByVal pathIndex As Long _
    ) As Nullable(Of ResultPath)

    Parameters

    pathIndex
    The index of the path (0 <= pathIndex < CountPaths).
    Exceptions
    ExceptionDescription
    When the index is out of range.
    Remarks
    If you are only interested in the entities and relationships of the paths, (not the paths themselves) refer to ExtractPathsEntitiesAndRelationships which will result in more efficient code. Indexes of paths within the FFP results, ordered by min cost, max cost, or path length, that can also be used with MaterializePath, can be retrieved from PathIndicesOrderedByIncreasingMinPathCost, PathIndicesOrderedByIncreasingMaxPathCost and PathIndicesOrderedByIncreasingPathLength respectively
    Example
    List out FFP Results by Path Length, Min Cost, Max Cost
        //using ArcGIS.Core.Data.Knowledge.Extensions;
    
        await QueuedTask.Run(async () =>
        {
            var ffp_config = new CIMFilteredFindPathsConfiguration();
            ffp_config.Name = "List out FFP Results by Path Length, Min Cost, Max Cost";
            //set up config
            //...
    
            var results = kg.RunFilteredFindPaths(ffp_config);
    
            if (results.CountPaths == 0)
            {
                System.Diagnostics.Debug.WriteLine("FFP returned no paths");
                return;
            }
    
            //print out paths by increasing length, min cost, max cost
            var path_by_len_indices = (IEnumerable<long>)results.PathIndicesOrderedByIncreasingPathLength
                                .Select(idx => idx.index);
            var path_by_min_cost = (IEnumerable<long>)results.PathIndicesOrderedByIncreasingMinPathCost
                                .Select(idx => idx.index);
    var path_by_max_cost = (IEnumerable<long>)results.PathIndicesOrderedByIncreasingMaxPathCost
                                                            .Select(idx => idx.index);
    
    var x = 0;
            StringBuilder sb = new StringBuilder();
    
            foreach (var path_indeces in new List<IEnumerable<long>> {
      path_by_len_indices,
      path_by_min_cost,
      path_by_max_cost})
    {
      if (x == 0)
                    sb.AppendLine($"Paths by length: {path_by_len_indices.Count()}");
                else if (x == 1)
                    sb.AppendLine($"Paths by min cost: {path_by_min_cost.Count()}");
                else if (x == 2)
                    sb.AppendLine($"Paths by max cost: {path_by_max_cost.Count()}");
      x++;
                foreach (var path_idx in path_indeces)
      {
                        var path = (ResultPath)results.MaterializePath(path_idx);
                        sb.AppendLine(
              $"Path[{path_idx}] length: {path.Length}, min: {path.MinCost} max: {path.MaxCost}");
                    var g = 0;
                    foreach (var rel_group in path.RelationshipGroups)
                    {
                        var first_entity = $"({rel_group.FirstEntity.TypeName}:{rel_group.FirstEntity.Uid})";
                        var second_entity = $"({rel_group.SecondEntity.TypeName}:{rel_group.SecondEntity.Uid})";
    
                        foreach (var relation in rel_group.Relationships)
                        {
                            sb.Append($"  [{g++}] ");
                            var arrow = relation.SameDirectionAsPath ? "->" : "<-";
                            var rel_uid = FormatID(relation.Relationship.Uid.ToString());
                            sb.Append($"{first_entity} '\r\n\t{relation.Relationship.TypeName}:{rel_uid}' {arrow}\r\n" +
                                $"\t\t{second_entity}");
                            sb.Append($" cost: {relation.Relationship.Cost}\r\n");
                        }
                    }
                }
            }
    
        });
    
        string FormatID(string id)
        {
            id = id.ToUpperInvariant();
            if (!id.StartsWith('{'))
                id = '{' + id;
            if (!id.EndsWith('}'))
                id += '}';
            return id;
        }
    List out FFP Results Origin, Destination, Other Entities
    //using ArcGIS.Core.Data.Knowledge.Extensions;
    
    await QueuedTask.Run(async () =>
    {
        var ffp_config = new CIMFilteredFindPathsConfiguration();
        ffp_config.Name = "List out FFP Results Origin, Destination, Other Entities";
        //set up config
        //...
    
        var results = kg.RunFilteredFindPaths(ffp_config);
    
        if (results.CountPaths == 0)
        {
            System.Diagnostics.Debug.WriteLine("FFP returned no paths");
            return;
        }
    
        //print out paths by increasing length, min cost, max cost
        var path_by_len_indices = (IEnumerable<long>)results.PathIndicesOrderedByIncreasingPathLength
                                                                .Select(idx => idx.index);
        var path_by_min_cost = (IEnumerable<long>)results.PathIndicesOrderedByIncreasingMinPathCost
                                                                .Select(idx => idx.index);
        var path_by_max_cost = (IEnumerable<long>)results.PathIndicesOrderedByIncreasingMaxPathCost
                                                                .Select(idx => idx.index);
    
        var x = 0;
        StringBuilder sb = new StringBuilder();
    
        foreach (var path_indeces in new List<IEnumerable<long>> {
            path_by_len_indices,
            path_by_min_cost,
            path_by_max_cost})
        {
            if (x == 0)
                sb.AppendLine($"Entities by length: {path_by_len_indices.Count()}");
            else if (x == 1)
                sb.AppendLine($"Entities by min cost: {path_by_min_cost.Count()}");
            else if (x == 2)
                sb.AppendLine($"Entities by max cost: {path_by_max_cost.Count()}");
            x++;
            foreach (var path_idx in path_indeces)
            {
                var path = (ResultPath)results.MaterializePath(path_idx);
                sb.AppendLine(
                    $"Path[{path_idx}] length: {path.Length}, min: {path.MinCost} max: {path.MaxCost}");
    
                var sorted_set = new SortedSet<ulong>();
                sorted_set.Add((ulong)path_idx);
                var per = results.ExtractPathsEntitiesAndRelationships(sorted_set);
    
                var origin_dest_uids = new List<string>();
                var sep = "";
    
                sb.Append(" Origin EntitiesUIDs: ");
                foreach (var idx in per.PathsOriginEntitiesUIDsIndexes)
                {
                    //See 'List out FFP Results by Path Length, Min Cost, Max Cost' for
      //FormatID method above
                    var uid = FormatID(per.EntitiesUIDs[idx].ToString());
                    origin_dest_uids.Add(uid);
    
                    var origin =
                        $"{sep}{per.EntityTypeNames[per.EntityTypes[idx]]}:{uid}";
                    sep = ", ";
                    sb.Append($"{origin}");
                }
                sb.AppendLine("");
    
                sep = "";
                sb.Append(" Destination EntitiesUIDs: ");
                foreach (var idx in per.PathsDestinationEntitiesUIDsIndexes)
                {
                    var uid = FormatID(per.EntitiesUIDs[idx].ToString());
                    origin_dest_uids.Add(uid);
    
                    var dest =
                        $"{sep}{per.EntityTypeNames[per.EntityTypes[idx]]}:{uid}";
                    sep = ", ";
                    sb.Append($"{dest}");
                }
                sb.AppendLine("");
    
                sep = "";
                var idx2 = 0;
                sb.Append(" Other EntitiesUIDs: ");
                bool wereAnyOthers = false;
                foreach (var raw_uid in per.EntitiesUIDs)
                {
                    var uid = FormatID(raw_uid.ToString());
                    if (!origin_dest_uids.Contains(uid))
                    {
                        var other =
                        $"{sep}{per.EntityTypeNames[per.EntityTypes[idx2]]}:{uid}";
                        sep = ", ";
                        sb.Append($"{other}");
                        wereAnyOthers = true;
                    }
                    idx2++;
                }
                if (!wereAnyOthers)
                    sb.Append(" <<none>>");
    
                //sb.AppendLine("");
    
                var entity_str = sb.ToString();
                System.Diagnostics.Debug.WriteLine(entity_str);
    
                sb.Clear();
                sep = "";
            }
        }
    
    });
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.6 or higher.
    See Also