public ValueTuple<long,long>[] PathIndicesOrderedByIncreasingPathLength {get;}
Public ReadOnly Property PathIndicesOrderedByIncreasingPathLength As ValueTuple(Of Long,Long)()
public ValueTuple<long,long>[] PathIndicesOrderedByIncreasingPathLength {get;}
Public ReadOnly Property PathIndicesOrderedByIncreasingPathLength As ValueTuple(Of Long,Long)()
//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;
}
Target Platforms: Windows 11, Windows 10