public static IEnumerable <T> GetAllDataObjects <T>(this IBidirectionalGraph <Cluster <T>, ClusterEdge <T> > tree, Cluster <T> cluster) { if (tree.IsOutEdgesEmpty(cluster)) { return(cluster.DataObjects); } return(tree.OutEdges(cluster).Aggregate((IEnumerable <T>)cluster.DataObjects, (res, edge) => res.Concat(tree.GetAllDataObjects(edge.Target)))); }
public bool Test([NotNull] TVertex vertex) { if (vertex == null) { throw new ArgumentNullException(nameof(vertex)); } return(_visitedGraph.IsInEdgesEmpty(vertex) && _visitedGraph.IsOutEdgesEmpty(vertex)); }
private double CalcSequenceWeights(IBidirectionalGraph <Cluster <TSeq>, ClusterEdge <TSeq> > tree, ClusterEdge <TSeq> edge, double curWeight, Stack <Cluster <TSeq> > nodeStack, Dictionary <Cluster <TSeq>, Profile <TSeq, TItem> > profiles) { double length = edge.Length; if (tree.IsOutEdgesEmpty(edge.Target)) { TSeq seq = edge.Target.DataObjects.First(); double weight = curWeight + length; profiles[edge.Target] = CreateProfile(seq, weight); return(weight); } nodeStack.Push(edge.Target); double lengthPart = length / tree.OutDegree(edge.Target); double maxWeight = double.MinValue; foreach (ClusterEdge <TSeq> childEdge in tree.OutEdges(edge.Target)) { maxWeight = Math.Max(maxWeight, CalcSequenceWeights(tree, childEdge, curWeight + lengthPart, nodeStack, profiles)); } return(maxWeight); }