Esempio n. 1
0
        public async Task RunAkkaSimulation(Configuration configuration)
        {
            _configuration = configuration;
            _messageHub.SendToAllClients(msg: "Prepare in Memory model from DB for Simulation: "
                                         + _configuration.GetOption <SimulationId>().Value);

            _messageHub.SendToAllClients(msg: "Prepare Simulation");

            _agentSimulation = new AgentSimulation(DBContext: _context
                                                   , messageHub: _messageHub); // Defines the status output

            var simulation = await _agentSimulation.InitializeSimulation(configuration : _configuration);

            SimulationContext = simulation.SimulationContext;


            if (simulation.IsReady())
            {
                _messageHub.StartSimulation(simId: _configuration.GetOption <SimulationId>().Value.ToString()
                                            , simNumber: _configuration.GetOption <SimulationNumber>().Value.ToString());

                // Start simulation
                var sim = simulation.RunAsync();
                _agentSimulation.StateManager.ContinueExecution(simulation);
                await sim;
            }
            _messageHub.EndSimulation(msg: "Simulation Completed."
                                      , simId: _configuration.GetOption <SimulationId>().Value.ToString()
                                      , simNumber: _configuration.GetOption <SimulationNumber>().Value.ToString());
            return;
        }
Esempio n. 2
0
        public async Task AgentSimulatioAsync(int simulationConfigurationId)
        {
            // In-memory database only exists while the connection is open
            var connectionStringBuilder = new SqliteConnectionStringBuilder {
                DataSource = ":memory:"
            };
            var connection = new SqliteConnection(connectionStringBuilder.ToString());

            // create OptionsBuilder with InMemmory Context
            var builder = new DbContextOptionsBuilder <MasterDBContext>();

            builder.UseSqlite(connection);
            var simNumber = _evaluationContext.GetSimulationNumber(simulationConfigurationId, SimulationType.Decentral);

            using (var c = new InMemoryContext(builder.Options))
            {
                c.Database.OpenConnection();
                c.Database.EnsureCreated();
                InMemoryContext.LoadData(_evaluationContext, c);

                var sim = new AgentSimulation(c, _messageHub);
                await sim.RunSim(simulationConfigurationId, simNumber);

                CopyResults.Copy(c, _evaluationContext, simulationConfigurationId, simNumber, SimulationType.Decentral);
                CalculateKpis.MachineSattleTime(_evaluationContext, simulationConfigurationId, SimulationType.Decentral, simNumber);

                CalculateKpis.CalculateAllKpis(_evaluationContext, simulationConfigurationId, SimulationType.Decentral, simNumber, true);
            }
            connection.Close();
            _messageHub.EndSimulation("Simulation with Id:" + simulationConfigurationId + " Completed."
                                      , simulationConfigurationId.ToString()
                                      , simNumber.ToString());
        }
        public async Task RunAkkaSimulation(Configuration configuration)
        {
            _configuration = configuration;
            _messageHub.SendToAllClients(msg: "Prepare in Memory model from DB for Simulation: "
                                         + _configuration.GetOption <SimulationId>().Value.ToString()
                                         , msgType: MessageType.info);
            //In-memory database only exists while the connection is open
            //var _inMemory = InMemoryContext.CreateInMemoryContext();
            // InMemoryContext.LoadData(source: _context, target: _inMemory);
            //MasterDBInitializerSimple.DbInitialize(_inMemory);

            _messageHub.SendToAllClients(msg: "Prepare Simulation", msgType: MessageType.info);

            _agentSimulation = new AgentSimulation(DBContext: _context
                                                   , messageHub: _messageHub); // Defines the status output

            var simulation = _agentSimulation.InitializeSimulation(configuration: _configuration).Result;

            SimulationContext = simulation.SimulationContext;


            if (simulation.IsReady())
            {
                _messageHub.SendToAllClients(msg: "Start Simulation ...", msgType: MessageType.info);
                // Start simulation
                var sim = simulation.RunAsync();

                AgentSimulation.Continuation(inbox: _agentSimulation.SimulationConfig.Inbox
                                             , sim: simulation
                                             , collectors: new List <IActorRef> {
                    _agentSimulation.StorageCollector
                    , _agentSimulation.WorkCollector
                    , _agentSimulation.ContractCollector
                });
                await sim;
            }
            _messageHub.EndScheduler();
            _messageHub.EndSimulation(msg: "Simulation Completed."
                                      , simId: _configuration.GetOption <SimulationId>().Value.ToString()
                                      , simNumber: _configuration.GetOption <SimulationNumber>().Value.ToString());
            return;
        }