Exemplo n.º 1
0
 private static bool isInZone(IList<double[]> image, IntervalsGoal goal, int index)
 {
     for (int i = 0; i < image.Count; i++)
     {
         if (image[i][index] < goal.Intervals[i][0] ||
             image[i][index] > goal.Intervals[i][1])
         {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 2
0
        private static Result calculateActivityZoneGoal(IActivity activity, IntervalsGoal goal, 
            ActInfo act, double[] domain, IList<double[]> image)
        {
            bool foundAny = false;
            int back = 0, front = 0;
            int bestBack = 0, bestFront = 0;
            
            double best;
            if (goal.UpperBound) best = double.MinValue;
            else best = double.MaxValue;

            int length = act.Length;

            while (front < length)
            {
                bool inWindow = true;
                for (int i = 0; i < image.Count; i++)
                {
                    if (image[i][back] < goal.Intervals[i][0] ||
                        image[i][front] > goal.Intervals[i][1])
                    {
                        inWindow = false;
                        break;
                    }
                }
                if (inWindow)
                {
                    double domainDiff = domain[front] - domain[back];
                    int upperBound = goal.UpperBound ? 1 : -1;
                    if (upperBound*best < upperBound*domainDiff &&
                        (goal.Domain == GoalParameter.Elevation ||
                        act.validElevation && (act.aElevation[front] - act.aElevation[back]) / (act.aDistance[front] - act.aDistance[back]) >= Settings.MinGrade))
                    {
                        foundAny = true;
                        best = domainDiff;
                        bestBack = back;
                        bestFront = front;
                    }
                    if (back == front || 
                        (front < length - 1 && isInZone(image, goal, front + 1))) 
                        front++;
                    else back++;
                }
                else
                {
                    if (back == front)
                    {
                        if (front < length - 1 && !isInZone(image, goal, front + 1)) 
                            back++;
                        front++;
                    }
                    else back++;
                }
            }

            if (foundAny)
            {
                return new Result(goal, activity, act.Pauses, domain[bestBack], domain[bestFront], act.aTime[bestBack], act.aTime[bestFront],
                    act.aDistance[bestBack], act.aDistance[bestFront], act.aElevation[bestBack], act.aElevation[bestFront],
                    act.aDateTime[bestBack], act.aDateTime[bestFront]);
            }
            return null;
        }