Exemplo n.º 1
0
        public RoutePoint nextStop(RoutePoint curStop, int nextBus)
        {
            int lastLapTime = curStop.Time > this.startTime ?
                              curStop.Time - (curStop.Time - this.startTime) % RoundTime :
                              this.startTime;

            if (!busStops.Contains(curStop.Point))
            {
                return(new RoutePoint(-2, nextBus, -2, -2, curStop));
            }
            else
            {
                int i = 0;
                for (; lastLapTime < curStop.Time ||
                     (busStops[i % busStops.Count] != curStop.Point && TimeConverter.timeIsCorrect(lastLapTime));
                     )
                {
                    for (i = 0;
                         i < BusStops.Count &&
                         !(lastLapTime >= curStop.Time && busStops[i] == curStop.Point);
                         i++)
                    {
                        lastLapTime += intervals[i];
                    }
                }
                int curPointIndex = i;
                curStop.StartTime = lastLapTime;
                return(new RoutePoint(busStops[(curPointIndex + 1) % busStops.Count],
                                      nextBus,
                                      lastLapTime + intervals[curPointIndex % busStops.Count],
                                      Cost,
                                      curStop));
            }
        }
Exemplo n.º 2
0
        public bool NextPoint(List <int> avaliableBuses, RoutePoint curPoint, int stopsCnt)
        {
            bool result = false;

            if (curPoint.Point == endPoint)
            {
                if (TimeConverter.timeIsCorrect(curPoint.Time))
                {
                    if (fastRoute.Count == 0)
                    {
                        fastRoute = HistoryToList(curPoint);
                        result    = true;
                    }
                    else if (fastRoute[fastRoute.Count - 1].Time > curPoint.Time)
                    {
                        fastRoute = HistoryToList(curPoint);
                        result    = true;
                    }

                    if (cheapRoute.Count == 0)
                    {
                        cheapRoute = HistoryToList(curPoint);
                        result     = true;
                    }
                    else if (cheapRoute[cheapRoute.Count - 1].Cost > curPoint.Cost)
                    {
                        cheapRoute = HistoryToList(curPoint);
                        result     = true;
                    }
                }
            }
            else
            {
                if (curPoint.Point != startPoint)
                {
                    result |= NextPointThisBus(avaliableBuses, new RoutePoint(curPoint), stopsCnt - 1);
                }
                foreach (int bus in avaliableBuses)
                {
                    result |= NextPointAnotherBus(new List <int>(avaliableBuses), new RoutePoint(curPoint), bus);
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        public int nextArriving(int busStop, int time)
        {
            int lastLapTime = time - time % RoundTime;

            if (!busStops.Contains(busStop))
            {
                return(-2);
            }
            else
            {
                for (; lastLapTime < time;)
                {
                    for (int i = 0;
                         i < BusStops.Count &&
                         !(lastLapTime >= time && busStops[i] == busStop);
                         i++)
                    {
                        lastLapTime += intervals[i];
                    }
                }
                return(TimeConverter.timeIsCorrect(lastLapTime) ? lastLapTime : -1);
            }
        }