Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SimulationEngine"/> class.
        /// </summary>
        /// <param name="stationCount">The station count.</param>
        /// <param name="highwayLength">Length of the highway.</param>
        /// <param name="replications">The replications.</param>
        /// <param name="channels">The channels.</param>
        /// <param name="reserved">The reserved.</param>
        /// <param name="report">The report.</param>
        /// <param name="randomFactory">The random factory.</param>
        /// <param name="replicationFactory">The replication factory.</param>
        /// <param name="threadCount">The thread count. Create this many parallel threads to run concurrent replications in.</param>
        public SimulationEngine(
            uint stationCount,
            uint highwayLength,
            uint replications,
            uint channels,
            uint reserved,
            Action <object> report,
            IRandomFactory randomFactory,
            IReplicationFactory replicationFactory,
            uint threadCount
            )
        {
            if (threadCount == 0)
            {
                throw new ArgumentException(Messages.CantRunWithNoWorkerThreads, "threadCount");
            }

            _randomFactory      = randomFactory;
            _replicationFactory = replicationFactory;
            _threadCount        = threadCount;
            _stationCount       = stationCount;
            _highwayLength      = highwayLength;
            _replications       = replications;
            _channels           = channels;
            _reserved           = reserved;
            _report             = report;
            _bagOfTasks         = new Dictionary <uint, Action <uint> >((int)replications);
            _totalCollectedData = new DataGatherer(0);
        }
Esempio n. 2
0
        void CreateAndRunReplication(uint replicationId)
        {
            // setup simulation run
            IReplication r = _replicationFactory.Create(
                new DataGatherer(replicationId),
                new EventQueueFactory(
                    _randomFactory.Create(),
                    _stationCount,
                    _highwayLength,
                    _channels,
                    _reserved)
                );

            // run simulation and measure how long it takes
            long before = DateTime.Now.Ticks;

            r.Run();
            long after = DateTime.Now.Ticks;

            // Collect and print required data
            _totalCollectedData += r.ReplicationData;
            _report(r.ReplicationData);
            Debug.WriteLine(
                string.Format("took {0}", new TimeSpan(after - before)));
        }