Ejemplo n.º 1
0
            public int GetHashCode(ClusterEdge <T> obj)
            {
                int code = 23;

                code = code * 31 + _clusterComparer.GetHashCode(obj.Source);
                code = code * 31 + _clusterComparer.GetHashCode(obj.Target);
                code = code * 31 + obj.Length.GetHashCode();
                return(code);
            }
Ejemplo n.º 2
0
        private static void GetMidpoint <T>(IUndirectedGraph <Cluster <T>, ClusterEdge <T> > tree, out ClusterEdge <T> midpointEdge, out double pointOnEdge, out Cluster <T> firstCluster)
        {
            Cluster <T> cluster1;
            IEnumerable <ClusterEdge <T> > path;

            GetLongestPath(tree, null, tree.Vertices.First(), 0, Enumerable.Empty <ClusterEdge <T> >(), out cluster1, out path);
            Cluster <T> cluster2;
            double      deepestLen = GetLongestPath(tree, null, cluster1, 0, Enumerable.Empty <ClusterEdge <T> >(), out cluster2, out path);
            double      midpoint   = deepestLen / 2;

            firstCluster = cluster1;
            double totalLen = 0;

            midpointEdge = null;
            foreach (ClusterEdge <T> edge in path)
            {
                totalLen += edge.Length;
                if (totalLen >= midpoint)
                {
                    midpointEdge = edge;
                    break;
                }
                firstCluster = edge.GetOtherVertex(firstCluster);
            }
            Debug.Assert(midpointEdge != null);

            double diff = totalLen - midpoint;

            pointOnEdge = midpointEdge.Length - diff;
        }
Ejemplo n.º 3
0
 public bool Equals(ClusterEdge <T> x, ClusterEdge <T> y)
 {
     return(_clusterComparer.Equals(x.Source, y.Source) && _clusterComparer.Equals(x.Target, y.Target) &&
            Math.Abs(x.Length - y.Length) < double.Epsilon);
 }
Ejemplo n.º 4
0
 public int GetHashCode(ClusterEdge <T> obj)
 {
     return(_clusterComparer.GetHashCode(obj.Source) ^ _clusterComparer.GetHashCode(obj.Target) ^ obj.Length.GetHashCode());
 }