Пример #1
0
        static Path getFastestPath()
        {
            Path   rez      = null;
            int    rezid    = 0;
            MyTime fromhome = new MyTime()
            {
                hour = startingtime.Hour, minute = startingtime.Minute
            };
            MyTime rezrezult = getPathTime(Paths[0]);

            Console.WriteLine("[   ]");
            if (counter == 1)
            {
                rez = Paths[0];
                MyTime pathrezult = rezrezult;
                //Console.WriteLine(rezrezult.getString() + " " + fromhome.getString());
                if (pathrezult.gettotal() >= 24 * 60)
                {
                    Console.WriteLine($"[!] There are only one path from {rez[rez.Length - 1].Number + 1} to {rez[0].Number + 1} and it is too late. Wasted time: {(rezrezult - fromhome).getString()}. Way complete at {rezrezult.getString()}");
                }
                else
                {
                    Console.WriteLine($"[!] There are only one path from {rez[rez.Length - 1].Number + 1} to {rez[0].Number + 1}, wasted time: {(rezrezult - fromhome).getString()}. Way complete at {rezrezult.getString()}");
                }
                Paths[rezid].printRev();
            }
            else
            {
                for (int j = 0; j < counter; j++)
                {
                    if (rez == null)
                    {
                        rez = Paths[j];
                    }
                    //Console.WriteLine($" [ ] Checking {j + 1}");
                    MyTime pathrezult = getPathTime(Paths[j]);
                    if (pathrezult.gettotal() >= 24 * 60)
                    {
                        Console.WriteLine($" [ ] Too late for Path {j + 1}, wasted time: {(pathrezult - fromhome).getString()}. Way complete at {pathrezult.getString()}");
                    }
                    else if (pathrezult != null)
                    {
                        //rezrezult = getPathTime(rez);

                        Console.WriteLine($" [ ] Path {j + 1} rezult: {pathrezult.getString()}");

                        int first  = Paths[j][Paths[j].Length - 1].Number;
                        int second = Paths[j][Paths[j].Length - 2].Number;

                        Bus    pathstartBus  = getBusBetwenTwo(first, second);
                        MyTime startbusstart = new MyTime()
                        {
                            hour = pathstartBus.start.Hour, minute = pathstartBus.start.Minute
                        };
                        Console.WriteLine($" [ ] Wasted time for Path {j + 1} = {(pathrezult - fromhome).getString()}");
                        if (pathrezult <= rezrezult)
                        {
                            rez = Paths[j]; rezid = j; rezrezult = pathrezult;
                        }
                    }
                }
                Console.WriteLine($"[!] The fastest path is {rezid + 1}, wasted time: {(rezrezult - fromhome).getString()}. Way complete at {rezrezult.getString()}");
                Paths[rezid].printRev();
            }
            return(rez);
        }
Пример #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()}");
        }