Ejemplo n.º 1
0
        /*static Connection getNthConnection(int stA, int stB, int n)
         * {
         *  int counter = 0;
         *  foreach (Connection con in allConnections)
         *  {
         *      if (con.StationA == stA && con.StationB == stB) counter++;
         *      if (counter == n) return con;
         *  }
         *  return null;
         * }*/

        static MyTime getPathTime(Path input)
        {
            MyTime start = new MyTime()
            {
                hour = startingtime.Hour, minute = startingtime.Minute
            };
            int    first  = input[input.Length - 1].Number;               //получили id первой станции
            int    second = input[input.Length - 2].Number;               //получили id второй станции
            int    minutes;
            Bus    between = getBusBetwenTwo(first, second, out minutes); //первый автобус, который нужен
            MyTime now     = new MyTime()
            {
                hour = startingtime.Hour, minute = startingtime.Minute
            };

            waitingforbus(getStationByNum(first + 1), between, start, out now);
            //Console.WriteLine($" time betwen {first + 1} and {second + 1} = {minutes}");
            //Console.WriteLine($"Transfer from {first + 1} to {second + 1} on {between.Name} for {minutes} minutes");
            now = now.addMinutes(minutes);
            //Console.WriteLine($"Transfer from {first + 1} to {second + 1} is done");
            Bus previous = between;

            for (int i = input.Length - 2; i >= 1; i--)
            {
                first   = input[i].Number;
                second  = input[i - 1].Number;
                minutes = 0;
                between = getBusBetwenTwo(first, second, out minutes);
                //Console.WriteLine($"Transfer from {first + 1} to {second + 1} on {between.Name} for {minutes} minutes");
                //$" previous = {previous.Name}");
                if (between != previous)
                {
                    //Console.WriteLine($"New bus!");
                    waitingforbus(getStationByNum(first + 1), between, (MyTime)now.Clone(), out now);
                    now = now.addMinutes(getMinutesBetweenTwo(first + 1, second + 1));
                }
                else
                {
                    now = now.addMinutes(getMinutesBetweenTwo(first + 1, second + 1));
                    //Console.WriteLine($"Just going next from {first + 1} to {second + 1} now: {now.getString()}");
                }
                previous = between;
            }
            return(now);
        }
Ejemplo n.º 2
0
        static void waitingforbus(Station where, Bus targetbus, MyTime now, out MyTime rezult)
        { //возвращает в rezult время прибытия автобуса
            //Console.WriteLine($"Begin wait on {where.num} for {targetbus.Name}. Now: {now.getString()}:");
            rezult = (MyTime)now.Clone();
            Station temp     = targetbus.getFirstStation();
            MyTime  busstart = new MyTime()
            {
                hour = targetbus.start.Hour, minute = targetbus.start.Minute
            };

            rezult = (MyTime)busstart.Clone();
            //Console.WriteLine($"first station: {temp.num} Busstart: {rezult.getString()} WHERE: {where.num}");
            if (where.num == temp.num && now.gettotal() <= busstart.gettotal())
            {
                //rezult = now;
            }
            else if (where.num == temp.num)
            {
                while (true)
                {
                    //Console.WriteLine("waitingfrobus");
                    int minutes = 0;
                    temp   = getNextStation(temp, targetbus, out minutes);
                    rezult = rezult.addMinutes(minutes);
                    //Console.WriteLine($"Transmissed to {temp.num}. rezult: {rezult.getString()}");
                    if (temp.num == where.num && rezult.gettotal() >= now.gettotal())
                    {
                        break;
                    }
                }
            }
            else
            {
                if (now.gettotal() <= busstart.gettotal())
                {
                    while (true)
                    {
                        //Console.WriteLine("waitingfrobus else");
                        int minutes = 0;
                        temp   = getNextStation(temp, targetbus, out minutes);
                        rezult = rezult.addMinutes(minutes);
                        //Console.WriteLine($"Transmissed to {temp.num}. rezult: {rezult.getString()}");
                        if (temp.num == where.num && rezult.gettotal() >= now.gettotal())
                        {
                            break;
                        }
                    }
                }
                else
                {
                    while (true)
                    {
                        //Console.WriteLine("waitingfrobus else else");
                        int minutes = 0;
                        temp   = getNextStation(temp, targetbus, out minutes);
                        rezult = rezult.addMinutes(minutes);
                        //Console.WriteLine($"Transmissed to {temp.num}. rezult: {rezult.getString()}" +
                        //$"Needed time: {now.getString()}");
                        if (temp.num != where.num && rezult.gettotal() >= now.gettotal())
                        {
                            break;
                        }
                    }
                }
            }
            //Console.WriteLine($"Wait finished, now: {rezult.getString()}");
        }