Пример #1
0
        /// <summary>
        /// Creates new routes and saves them to the file
        /// </summary>
        public void CreateRoutes()
        {
            ReadWriteFile rwf       = new ReadWriteFile();
            Random        rng       = new Random();
            int           timeTaken = rng.Next(0, 3001);

            // Wait for manager to start
            waitHandle.WaitOne();
            Thread.Sleep(timeTaken);
            rwf.WriteToFile();

            // Manager can continue choosing the best routes
            waitHandle.Set();
        }
Пример #2
0
        /// <summary>
        /// Chooses the possible routes for the time given
        /// </summary>
        public void ChooseRoutes()
        {
            ReadWriteFile rwf = new ReadWriteFile();
            // Counting how long the manager waited for values to be created
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            Console.WriteLine("Manager waiting for routes to be created...");

            // Sleep max 3sec
            waitHandle.Set();
            waitHandle.WaitOne(3000);
            stopWatch.Stop();

            // Get the elapsed time as a TimeSpan value.
            TimeSpan ts          = stopWatch.Elapsed;
            int      elapsedTime = (ts.Seconds * 1000) + ts.Milliseconds;

            // Get all routes from the file
            rwf.ReadFile(allRoutes);

            if (elapsedTime > 3000)
            {
                Console.WriteLine("\nToo much time has passed, manager will choose from available routes.");
                // If too much time has passed get any 10 routes from the list
                for (int i = 0; i < allRoutes.Count; i++)
                {
                    truckRoutes.Add(allRoutes[i]);
                    if (truckRoutes.Count == 10)
                    {
                        break;
                    }
                }
                Console.Write("\nRoutes: ");
                ReadChosenRoutes();
            }
            else
            {
                Console.WriteLine("\nManager waited for {0} milliseconds for routes to be created.", elapsedTime);
                // Get best 10 routes
                BestRoutes();
            }
        }