Esempio n. 1
0
 private static int ComparePaths(PathMetric commonA, Path pathA, PathMetric commonB, Path pathB)
 {
     if (pathA.DeadEnd && !pathB.DeadEnd)
     {
         return(1);
     }
     if (!pathA.DeadEnd && pathB.DeadEnd)
     {
         return(-1);
     }
     return((commonA + pathA.Metric).CompareTo(commonB + pathB.Metric));
 }
Esempio n. 2
0
        public void Merge(SearchResult other)
        {
            if (other.Best == null)
            {
                return;
            }

            if (Best == null)
            {
                CommonMetric = other.CommonMetric;
                Best         = other.Best;
                Second       = other.Second;
            }
            else if (ComparePaths(other.CommonMetric, other.Best, CommonMetric, Best) > 0)
            {
                if (other.Second != null && ComparePaths(new PathMetric(), other.Second, other.CommonMetric + CommonMetric, Best) > 0)
                {
                    CommonMetric = other.CommonMetric;
                    Best         = other.Best;
                    Second       = other.Second;
                }
                else
                {
                    Best.Metric       += CommonMetric;
                    other.Best.Metric += other.CommonMetric;
                    CommonMetric       = new PathMetric();

                    Second = Best;
                    Best   = other.Best;
                }
            }
            else if (Second == null || ComparePaths(CommonMetric + other.CommonMetric, other.Best, new PathMetric(), Second) > 0)
            {
                Best.Metric       += CommonMetric;
                other.Best.Metric += other.CommonMetric;
                CommonMetric       = new PathMetric();

                Second = other.Best;
            }
        }