Esempio n. 1
0
        public void Apply(Simulation simulation)
        {
            if (simulation == null)
            {
                throw new ArgumentNullException(nameof(simulation));
            }

            // Apply common updates
            simulation.BeforeSetup += (object sender, EventArgs args) =>
            {
                foreach (var pUpdate in CommonUpdates.ParameterUpdatesBeforeSetup)
                {
                    pUpdate.Update(simulation, Contexts);
                }
            };

            var biasingSimulation = simulation as BiasingSimulation;

            biasingSimulation.BeforeTemperature += (object sender, TemperatureStateEventArgs args) =>
            {
                foreach (var pUpdate in CommonUpdates.ParameterUpdatesBeforeTemperature)
                {
                    pUpdate.Update(simulation, Contexts);
                }
            };

            biasingSimulation.BeforeLoad += (object sender, LoadStateEventArgs args) =>
            {
                foreach (var pUpdate in CommonUpdates.ParameterUpdatesBeforeLoad)
                {
                    pUpdate.Update(simulation, Contexts);
                }
            };

            // Apply simulation specific updates
            if (SpecificUpdates.ContainsKey(simulation))
            {
                var update = SpecificUpdates[simulation];

                simulation.BeforeSetup += (object sender, EventArgs args) =>
                {
                    foreach (var pUpdate in update.ParameterUpdatesBeforeSetup)
                    {
                        pUpdate.Update(simulation, Contexts);
                    }
                };

                biasingSimulation.BeforeTemperature += (object sender, TemperatureStateEventArgs args) =>
                {
                    foreach (var pUpdate in update.ParameterUpdatesBeforeTemperature)
                    {
                        pUpdate.Update(simulation, Contexts);
                    }
                };
            }
        }
        public void AddBeforeSetup(BaseSimulation simulation, Action <BaseSimulation, SimulationEvaluationContexts> update)
        {
            if (simulation == null)
            {
                throw new ArgumentNullException(nameof(simulation));
            }

            if (!SpecificUpdates.ContainsKey(simulation))
            {
                SpecificUpdates[simulation] = new SimulationUpdates()
                {
                    Simulation = simulation
                };
            }

            SpecificUpdates[simulation].ParameterUpdatesBeforeSetup.Add(new SimulationUpdate()
            {
                Simulation = simulation, Update = update
            });
        }