Ejemplo n.º 1
0
        private static int?SearchForDriver(ScheduleState state, int day, int lineNum)
        {
            Random random    = new Random((int)DateTime.Now.Ticks);
            int    driverMax = 11;

            int driver = random.Next(0, driverMax);

            int iterationToFind = 0;

            while ((
                       state.IsTodayDayOff((byte)(driver + 1), (byte)(day + 1)) == true
                       ||
                       state.IsDriverCanDriveLine((byte)(driver + 1), (byte)(lineNum + 1)) == false
                       ||
                       state.IsDriverBusyToday(day, driver) == true
                       )
                   &&
                   iterationToFind < 1000
                   )
            {
                driver = random.Next(0, driverMax);
                iterationToFind++;
            }

            if (
                state.IsTodayDayOff((byte)(driver + 1), (byte)(day + 1)) == false
                &&
                state.IsDriverCanDriveLine((byte)(driver + 1), (byte)(lineNum + 1)) == true
                &&
                state.IsDriverBusyToday(day, driver) == false
                )
            {
                return(driver);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        static void PrintSchedule(ScheduleState state)
        {
            Console.WriteLine("Schedule");
            for (int j = 0; j < 11; j++)
            {
                Console.Write("Driver " + (int)(j + 1) + ": ");
                if (j + 1 < 10)
                {
                    Console.Write(" ");
                }
                for (int i = 0; i < 14; i++)
                {
                    for (int k = 0; k < 2; k++)
                    {
                        if (state.IsTodayDayOff((byte)(j + 1), (byte)(i + 1)))
                        {
                            Console.BackgroundColor = ConsoleColor.Gray;
                            Console.ForegroundColor = ConsoleColor.Black;
                            Console.Write("x ");
                            Console.BackgroundColor = ConsoleColor.Black;
                            Console.ForegroundColor = ConsoleColor.Gray;
                        }
                        else
                        {
                            if (state.Schedule[i, j, k] != 0)
                            {
                                Console.ForegroundColor = ConsoleColor.White;
                            }
                            if (state.IsPrefToWork((byte)(j + 1), (byte)(i + 1), (byte)k))
                            {
                                Console.BackgroundColor = ConsoleColor.Yellow;
                                Console.ForegroundColor = ConsoleColor.Black;
                            }

                            Console.Write(state.Schedule[i, j, k] + " ");

                            Console.BackgroundColor = ConsoleColor.Black;
                            Console.ForegroundColor = ConsoleColor.Gray;
                        }
                    }
                    Console.Write(" ");
                }
                Console.WriteLine();
            }
        }