Exemple #1
0
        public void Simulate()
        {
            //Initialize all simulation threads
            Thread[] workers   = new Thread[THREADCOUNT];
            int      sliceSize = GAMECOUNT / THREADCOUNT;

            progress = new int[THREADCOUNT];
            Console.WriteLine("Using {0} threads", THREADCOUNT);
            for (int i = 0; i < THREADCOUNT; i++)
            {
                int games = sliceSize;
                if (i == THREADCOUNT - 1)
                {
                    games = GAMECOUNT - (i * sliceSize);
                }
                SimulationWorker worker = new SimulationWorker(i, progress, PLAYERCOUNT, games, SUITS, CARDSPERSUIT, gameLengths, i * sliceSize, VERBOSE);
                Thread           thread = new Thread(new ThreadStart(worker.Simulate));
                workers[i] = thread;
                thread.Start();
            }

            //Wait for all threads to finish, periodically polling for progress information to print
            var watch = new System.Diagnostics.Stopwatch();

            watch.Start();
            bool finished = false;

            int[] prevProgress = new int[THREADCOUNT];
            while (!finished)
            {
                finished = true;
                for (int i = 0; i < THREADCOUNT; i++)
                {
                    if (!workers[i].Join(1))
                    {
                        finished = false;
                    }
                }
                if (!finished)
                {
                    Thread.Sleep(1000);
                    int gamesSinceLast = 0;
                    int totalProgress  = 0;
                    for (int i = 0; i < THREADCOUNT; i++)
                    {
                        int tProg = progress[i];
                        gamesSinceLast += tProg - prevProgress[i];
                        prevProgress[i] = tProg;
                        totalProgress  += tProg;
                    }

                    long gPerS = 1000 * gamesSinceLast / watch.ElapsedMilliseconds;
                    Console.Write("{0}% progress ({1} games/s)\r", Math.Round((double)(100 * totalProgress / GAMECOUNT), 1), gPerS);
                    watch.Restart();
                }
            }
            Console.WriteLine("Simulation completed");
        }
Exemple #2
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            SimulationWorker.Start();

            //if (Simulation is IShufflable shufflable)
            //{
            //    CreateMenu(this.toolStripContainer1, menu => menu.AddButton("&Shuffle", shufflable.Shuffle));
            //}

            Simulation.Initialise();
        }
Exemple #3
0
        /// <summary>
        /// Using the SimulationWorker to run a simulation
        /// <para>
        /// The worker takes care of error messages, summary files etc,
        /// and you get exactly the same as if running the simulation from the
        /// MIKE HYDRO, MIKE URBAN or MIKE 11 user interfaces or by using the
        /// DHI.Mike1D.Application.exe.
        /// </para>
        /// </summary>
        /// <param name="setupFilepath">Path to setup file (.sim11, .mdb or .m1dx)</param>
        public static void WorkerRun(string setupFilepath)
        {
            SimulationWorker worker = new SimulationWorker(new FilePath(setupFilepath))
            {
                SimulationParameters = new SimulationParameters()
            };

            // Load setup
            worker.Load();
            // Now the setup is available
            Mike1DData mike1DData = worker.Mike1DData;

            // Run simulation
            worker.Run();
        }