Esempio n. 1
0
        public static float Run(IList<double> dp0, IList<IList<double>> dpc1)
        {
            IList<LocalPattern> lps1 = new List<LocalPattern>();
            lps1 = dpc1.Aggregate(lps1,
                (current, ts) => current.Concat(GetLocalPatterns(ts, WINDOW_SIZE)).ToList());

            IList<LocalPattern> lps0 = GetLocalPatterns(dp0, WINDOW_SIZE);
            BUCKET_SIZE = (int) (TOP_BUCKET_RATIO*dp0.Count);

            List<List<LocalPatternMatch>> lpmBuckets = GetLocalPatternMatchBuckets(lps0, lps1);

            var allLpms = new List<LocalPatternMatch>();
            foreach (var bucket in lpmBuckets)
            {
                foreach (LocalPatternMatch lpm in bucket)
                {
                    allLpms.Add(lpm);
                }
            }

            int numVertices = allLpms.Count + 2;
            var costMatrix = new int[numVertices, numVertices];

            for (int i = 0; i < allLpms.Count; i++)
            {
                int distToStart = LocalPatternMatch.DistanceToPs(allLpms[i], allLpms.Count, WINDOW_SIZE);
                int distToEnd = LocalPatternMatch.DistanceToPe(allLpms[i], allLpms.Count, WINDOW_SIZE);

                costMatrix[0, i + 1] = distToStart;
                costMatrix[i + 1, numVertices - 1] = distToEnd;
            }

            for (int row = 0; row < numVertices - 2; row++)
            {
                for (int col = 0; col < numVertices - 2; col++)
                {
                    if (row == col)
                        costMatrix[row + 1, col + 1] = 0;
                    else
                        costMatrix[row + 1, col + 1] = LocalPatternMatch.Distance(allLpms[row], allLpms[col],
                            allLpms.Count, WINDOW_SIZE);
                }
            }

            var dijkstra = new Dijkstra.Dijkstra();
            dijkstra.Run(costMatrix, 0);
            return dijkstra.StartToEndDistance;
        }