Ejemplo n.º 1
0
        public int NewSim(SimConfig cfg)
        {
            _simsMutex.WaitOne();
            _count = _count + 1;
            _logger.LogInformation("Creating new sim id#{1}", _count);

            Simulation s;

            if (cfg == null)
            {
                s = new Simulation();
            }
            else
            {
                s = new Simulation(cfg);
            }

            WebSimulationViewer w = new WebSimulationViewer();

            s.AddView(w);
            s.RegisterListener(w);

            _sims.Add(s);
            _views.Add(w);
            _simsMutex.ReleaseMutex();
            return(_count);
        }
Ejemplo n.º 2
0
        private void applyButton_Click(object sender, EventArgs e)
        {
            SimConfig config = GetSimConfig();

            if (config != null)
            {
                this.OnConfigChanged(GetSimConfig());
            }
        }
Ejemplo n.º 3
0
        public static void WriteToFile(this SimConfig config, string pathToSimulation)
        {
            var pathToPrivate = Path.Combine(pathToSimulation, PRIVATE_SUBDIRECTORY);

            if (!Directory.Exists(pathToPrivate))
            {
                Directory.CreateDirectory(pathToPrivate);
            }

            var pathToConfig = Path.Combine(pathToPrivate, CONFIG_FILE_NAME);
            var toToml       = ToToml(config);

            Toml.WriteFile(toToml, pathToConfig);
        }
Ejemplo n.º 4
0
        public void Bind(ISimStatsType stats, ISimConfigType config)
        {
            if (_binded)
            {
                return;
            }

            CheckBindings(stats, config);

            config.Config.OnChanged += cfg => _config = cfg;
            stats.State.OnChanged   += OnPublicStateChanged;
            ViewState.OnChanged     += OnViewStateChanged;

            _publicState = stats.State;

            _binded = true;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Build a SimConfig object from the GUI
        /// </summary>
        /// <returns>SimConfig as represented by the GUI elements</returns>
        private SimConfig GetSimConfig()
        {
            try
            {
                SimConfig config = new SimConfig()
                {
                    Days        = Convert.ToInt32(daysBox.Text),
                    RootCouples = Convert.ToInt32(couplesBox.Text)
                };

                return(config);
            }
            catch (Exception e)
            {
                MessageBox.Show("Could not create SimConfig: " + e.ToString());
                return(null);
            }
        }
Ejemplo n.º 6
0
        public static NumDataColumn[] TabulateTmplOutput(SimConfig config)
        {
            var tabulatedData = new List <NumDataColumn>();
            var instance      = REngine.GetInstance();

            foreach (var value in config.SimOutput.SimValues)
            {
                var sexp     = instance.GetSymbol(value.Name);
                var matrices = SexpToMatrices(sexp, value.Name);

                foreach (var matrix in matrices)
                {
                    var columnNames = matrix.ColumnNames;
                    var array       = matrix.Array;

                    if (null == columnNames)
                    {
                        var nColumns = array.GetLength(1);
                        RequireTrue(1 == nColumns, "Multi-column output has no column names");
                        columnNames = new[] { value.Name }; // output was R vector
                    }

                    var toTabulate = value.SimElements.Select(e => e.Name).ToArray();

                    var excludedColumnIndexes = columnNames
                                                .Select((cn, i) => new { cn, i })
                                                .Where(a => !toTabulate.Contains(a.cn))
                                                .Select(a => a.i)
                                                .ToArray();

                    var numDataColumns = MatrixToNumDataColumns(
                        array,
                        columnNames,
                        excludedColumnIndexes
                        );
                    tabulatedData.AddRange(numDataColumns);
                }
            }

            return(tabulatedData.ToArray());
        }
Ejemplo n.º 7
0
        private void LoadConfig()
        {
            var source = Application.persistentDataPath;
            var file   = $"{fileName}.json";

            if (!Directory.Exists(source))
            {
                throw new DirectoryNotFoundException(source);
            }

            var path = Path.Combine(source, file);

            if (!File.Exists(path))
            {
                throw new FileNotFoundException($"{file} in {source}");
            }

            var text = File.ReadAllText(path);

            _controlType.Config.Value = SimConfig.FromJson(text);

            _publicState.OnChanged -= ActivateOnState;
            _publicState.Value      = SimStateType.Setup;
        }
Ejemplo n.º 8
0
 /* Called when the SimConfig changes */
 private void OnSimConfigChanged(SimConfig newConfig)
 {
     this.simConfig = newConfig;
 }
Ejemplo n.º 9
0
 protected override void StartView()
 {
     ViewData.ViewConfig.OnChanged += cfg => _config = cfg;
     ViewData.ViewState.OnChanged  += state => _state = state;
 }
Ejemplo n.º 10
0
 public int NewSim(SimConfig cfg)
 {
     return(_mgr.NewSim(cfg));
 }