Run() public method

public Run ( int seed, int limit ) : bool
seed int
limit int
return bool
Esempio n. 1
0
        static void Main(string[] args)
        {
            Model model = new Model(
                new ErlangGenerator(0.25, 3),
                new PoissonGenerator(0.5),
                new NormalGenerator(14, 1.5),
                new ExponentialGenerator(3),
                new ModelTime()
            {
                Time = 500
            }
                );

            model.Run();

            model.Drain.DrainedTransacts.ForEach(t => Console.WriteLine(t));

            /*
             * AbstractGenerator generator = new NormalGenerator();
             *
             * var values = generator.Next(1000000);
             * Console.WriteLine("Max: {0}\nMin: {1}\nAverage: {2}",
             *  values.Max(), values.Min(), values.Average());
             *
             * Histogram hist = new Histogram(values, 50);
             * hist.Draw(DrawMode.SaveAndOpen, 1000, 700);
             */


            Console.ReadLine();
        }
Esempio n. 2
0
        /// <summary>
        /// Reads in wells from the shape, adds them to the model and rund the model.
        /// </summary>
        public void Run()
        {
            ReadWellsFromShape();
            Console.WriteLine(_wells.Count.ToString() + " wells read from: " + _config.WellShapeFile);
            InsertIrrigationWells();

            Console.WriteLine("Wells inserted in: " + _config.SheFile);

            //Make sure that i both preprocesses and runs
            _she.Input.MIKESHE_FLOWMODEL.ExecuteEngineFlagsPfs.PP = 1;
            _she.Input.MIKESHE_FLOWMODEL.ExecuteEngineFlagsPfs.WM = 1;

            SaveAs(_config.SheFile);

            Console.WriteLine(_config.SheFile + " saved");

            Console.WriteLine("Starting simulation now");
            _she.Run(false, true);
            Console.WriteLine("Simulation finished");
            if (_config.DeleteWellsAfterRun)
            {
                _she.Input.MIKESHE_FLOWMODEL.LandUse.CommandAreas.ClearCommandAreas();
                SaveAs(_config.SheFile);
                Console.WriteLine("Deleting irrigation wells from .she-file");
            }
            _she.Dispose();
        }
Esempio n. 3
0
        public void PreProcessTest()
        {
            Model m = new Model(@"..\..\..\TestData\TestModel.she");

            m.Run(false, true);
            Console.WriteLine("simulation finished");
            Thread.Sleep(2000);
        }
Esempio n. 4
0
        async void ExecuteRun()
        {
            var a = SelectedAnswer;
            await Model.Compile(a);

            if (a.ExecutableFilePath != null)
            {
                await Model.Run(a);
            }
        }
 public void ExecModel()
 {
     lock (_synch)
     {
         if (null == Model)
         {
             return;
         }
         Model.Run();
     }
 }
Esempio n. 6
0
		public static int Main(string[] args)
		{
			try {
				UI.TextWriter = Console.Out;

				Assembly assembly = Assembly.GetExecutingAssembly();
				VersionRelease versionRelease = new VersionRelease(assembly);
				UI.WriteLine("Landis-II {0}", versionRelease);
				UI.WriteLine("Copyright 2004-2005 University of Wisconsin");
				UI.WriteLine();
	
				if (args.Length == 0) {
					UI.WriteLine("Error: No scenario file specified.");
					return 1;
				}
				if (args.Length > 1) {
					UI.WriteLine("Error: Extra argument(s) on command line:");
					StringBuilder argsList = new StringBuilder();
					argsList.Append(" ");
					for (int i = 1; i < args.Length; ++i)
						argsList.AppendFormat(" {0}", args[i]);
					UI.WriteLine(argsList.ToString());
					return 1;
				}

				string appDir = Application.Directory;
				PlugIns.Dataset plugIns = new PlugIns.Dataset(Path.Combine(appDir, "plug-ins.xml"));
				RasterIO.DriverManager driverMgr = new RasterIO.DriverManager(Path.Combine(appDir, "raster-drivers.xml"));
				Model model = new Model(plugIns, driverMgr);
				model.Run(args[0]);
				return 0;
			}
			catch (ApplicationException exc) {
				UI.WriteLine(exc.Message);
				return 1;
			}
			catch (Exception exc) {
				UI.WriteLine("Internal error occurred within the program:");
				UI.WriteLine("  {0}", exc.Message);
				if (exc.InnerException != null) {
					UI.WriteLine("  {0}", exc.InnerException.Message);
				}
				UI.WriteLine();
				UI.WriteLine("Stack trace:");
				UI.WriteLine(exc.StackTrace);
				return 1;
			}
		}
Esempio n. 7
0
        //---------------------------------------------------------------------

        private void TryRun(string runFolder)
        {
            try {
                string runFolderPath = Data.MakeInputPath(Path.Combine("model-run",
                                                                       runFolder));
                Environment.CurrentDirectory = runFolderPath;
                Data.Output.WriteLine();
                Data.Output.WriteLine("Current directory: {0}",
                                      runFolderPath.Replace(Data.Directory, Data.DirPlaceholder));
                model.Run("scenario.txt");
            }
            catch (System.Exception e) {
                Data.Output.WriteLine(e.Message);
                throw;
            }
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            var cargoFile         = "CargoTest.csv";
            var locationCargoFile = "LocationCargoTest.csv";
            var reader            = new CSVReader(cargoFile, locationCargoFile);

            reader.Read();

            var cargoList    = reader.GetCargoList();
            var locationList = reader.GetLocationList();

            var model = new Model(cargoList, locationList);

            model.Run();

            Console.WriteLine("\nPress any key to exit!");
            Console.ReadKey();
        }
Esempio n. 9
0
        public async Task <IActionResult> Post([FromBody] SimulationConfig config)
        {
            await _hubContext.Clients.All.SendAsync("setClientMessage", "Run simulation");

            Model.Statics statics = MapConfig(config);

            List <Result> result = Enumerable.Range(0, 20).Select(seed =>
            {
                var sim = new Model(statics, seed);
                while (sim.Run(1))
                {
                    ;
                }
                return(sim.Result);
            }).ToList();

            return(Ok(result));
        }
Esempio n. 10
0
        public async Task <IActionResult> RunSimulation(int id, [FromBody] RunSimulationModel simulation)
        {
            //_queue.QueueAsyncTask(async () =>
            //{
            //    await Task.Run(async () =>
            //     {
            //         await _hubContext.Clients.Client(simulation.ConnectionId).SendAsync("setSimulationResults", "testing");
            //         Model.Statics scenario = MapConfig(simulation.Config);
            //         Model model = new Model(scenario, seed: id);
            //         model.WarmUp(TimeSpan.FromHours(scenario.OpeningHour));
            //         await  RunSimulationAsync(model, simulation.ConnectionId);
            //     });
            //});
            //await _hubContext.Clients.Client(simulation.ConnectionId).SendAsync("setSimulationResults", "testing");
            Model.Statics scenario = MapConfig(simulation.Config);
            Model         model    = new Model(scenario, seed: id);

            model.WarmUp(TimeSpan.FromHours(scenario.OpeningHour));
            Console.WriteLine("running sim for 10 seconds");
            //List<ResultModel> results = new List<ResultModel>();
            List <Result> results = new List <Result>();

            do
            {
                model.WriteToConsole();
                //ResultModel result = new ResultModel();
                //result.BarAvgCust = model.Result.BarAvgCust;
                //result.BarAvgDrinksPerCust = model.Result.BarAvgDrinksPerCust;
                //result.BarDrinksSold = model.Result.BarDrinksSold;
                results.Add(model.Result);
                await Task.Delay(500);;
            } while (model.Run(TimeSpan.FromHours(1)));
            //string messageString = JsonSerializer.Serialize(results);
            //Console.WriteLine(messageString);
            //await _hubContext.Clients.Client(simulation.ConnectionId).SendAsync("setSimulationResults", messageString);
            //Console.WriteLine("finished running sim");
            return(Ok(results));
        }
Esempio n. 11
0
        private async Task RunSimulationAsync(Model model, string connectionId)
        {
            Console.WriteLine("running sim for 10 seconds");
            List <ResultModel> results = new List <ResultModel>();

            do
            {
                model.WriteToConsole();
                ResultModel result = new ResultModel();
                result.BarAvgCust          = model.Result.BarAvgCust;
                result.BarAvgDrinksPerCust = model.Result.BarAvgDrinksPerCust;
                result.BarDrinksSold       = model.Result.BarDrinksSold;

                results.Add(result);
                await Task.Delay(1000);;
            } while (model.Run(TimeSpan.FromHours(1)));
            string messageString = JsonSerializer.Serialize(results);

            Console.WriteLine(messageString);
            await _hubContext.Clients.Client(connectionId).SendAsync("setSimulationResults", messageString);

            Console.WriteLine("finished running sim");
        }
Esempio n. 12
0
    // Update is called once per frame
    //void Update()
    //{
    //    if (unableToGen)
    //    {
    //        Debug.Log("Unable to generate map");
    //        unableToGen = false;
    //    }
    //    if (toutFini)
    //    {
    //        Debug.Log(displayText(finalOutput));
    //        toutFini = false;
    //    }
    //    if (showProgBar)
    //    {
    //        currentEntropy = (int)model.totalEntropy();
    //    }
    //}

    public int[,] startProcess(int lvl)
    {
        string         name   = "test";
        List <int[, ]> inputs = new List <int[, ]>();

        //Format d'ajout de type de niveau
        //inputs.Add(new int[,]{  });
        inputs.Add(new int[, ] {
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0 },
            { 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0 },
            { 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0 },
            { 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0 },
            { 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
        });
        inputs.Add(new int[, ] {
            { 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 },
            { 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1 },
            { 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1 },
            { 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1 },
            { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
            { 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 },
            { 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1 },
            { 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1 },
            { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1 },
            { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1 },
            { 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 },
            { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 },
            { 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1 },
            { 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1 },
            { 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 }
        });
        int lvlStep = 3;
        int index   = 0;

        for (int i = 0; i < 3; i++)
        {
            if (PlayerPrefs.GetInt("Level") < lvlStep)
            {
                index = i;
                break;
            }
            lvlStep += 3;
        }
        model = new OverlappingModel(inputs[index], name, 3, outputWidth, outputHeight, true, false, 8, 0);
        bool finished = false;
        int  attempts = 0;

        //maxEntropy = (int) model.totalEntropy();
        //currentEntropy = maxEntropy;
        //showProgBar = true;
        while (!finished && attempts < 10)
        {
            int seed = random.Next();
            finished = model.Run(seed, 0);
        }

        System.Drawing.Color[,] mapCouleur;
        if (finished)
        {
            mapCouleur  = model.GetMap();
            finalOutput = colorToInt(mapCouleur, outputHeight, outputWidth);
            toutFini    = true;
            return(finalOutput);
        }
        else
        {
            unableToGen = true;
            return(null);
        }
    }
Esempio n. 13
0
        private static async Task <bool> Run(XmlDocument ModelXml, TaskCompletionSource <bool> Done,
                                             string SnifferFolder, string SnifferTransformFileName, string MarkdownOutputFileName, string XmlOutputFileName,
                                             string CommandLine, IEnumerable <string> Master, IEnumerable <string> Css, bool EmitDots,
                                             string ProgramDataFolder, int BlockSize, int BlobBlockSize, Encoding Encoding, bool Encryption)
        {
            using (FilesProvider DB = await FilesProvider.CreateAsync(ProgramDataFolder, "Default", BlockSize, 10000, BlobBlockSize, Encoding, 3600000, Encryption, false))
            {
                try
                {
                    Console.Out.WriteLine("Starting database...");
                    Database.Register(DB);
                    await DB.RepairIfInproperShutdown(null);

                    await Database.Clear("EventLog");

                    Log.Register(new PersistedEventLog(int.MaxValue));

                    Console.Out.WriteLine("Starting modules...");
                    await Types.StartAllModules(60000);

                    Console.Out.WriteLine("Running simulation...");
                    Model Model = (Model)await Factory.Create(ModelXml.DocumentElement, null, null);

                    Model.CommandLine              = CommandLine;
                    Model.SnifferFolder            = SnifferFolder;
                    Model.SnifferTransformFileName = SnifferTransformFileName;
                    Model.OnGetKey         += Model_OnGetKey;
                    Model.OnGetThreadCount += Model_OnGetThreadCount;

                    bool Result = await Model.Run(Done, EmitDots);

                    if (!string.IsNullOrEmpty(MarkdownOutputFileName))
                    {
                        Console.Out.WriteLine("Generating Markdown report: " + MarkdownOutputFileName);

                        string Folder = Path.GetDirectoryName(MarkdownOutputFileName);
                        if (!string.IsNullOrEmpty(Folder) && !Directory.Exists(Folder))
                        {
                            Directory.CreateDirectory(Folder);
                        }

                        using (StreamWriter Output = File.CreateText(MarkdownOutputFileName))
                        {
                            foreach (string s in Master)
                            {
                                Output.Write("Master: ");
                                Output.WriteLine(s);
                            }

                            foreach (string s in Css)
                            {
                                Output.Write("CSS: ");
                                Output.WriteLine(s);
                            }

                            await Model.ExportMarkdown(Output);
                        }
                    }

                    if (!string.IsNullOrEmpty(XmlOutputFileName))
                    {
                        Console.Out.WriteLine("Generating XML report: " + XmlOutputFileName);

                        XmlWriterSettings Settings = new XmlWriterSettings()
                        {
                            Encoding                = Encoding.UTF8,
                            Indent                  = true,
                            IndentChars             = "\t",
                            NewLineChars            = "\r\n",
                            NewLineOnAttributes     = false,
                            WriteEndDocumentOnClose = true
                        };

                        string Folder = Path.GetDirectoryName(XmlOutputFileName);
                        if (!string.IsNullOrEmpty(Folder) && !Directory.Exists(Folder))
                        {
                            Directory.CreateDirectory(Folder);
                        }

                        using (XmlWriter Output = XmlWriter.Create(XmlOutputFileName, Settings))
                        {
                            Output.WriteStartDocument();
                            Output.WriteStartElement("Report", "http://trustanchorgroup.com/Schema/ComSimReport.xsd");

                            await Model.ExportXml(Output);

                            Output.WriteEndElement();
                        }
                    }

                    return(Result);
                }
                finally
                {
                    Console.Out.WriteLine("Stopping modules...");
                    await Types.StopAllModules();

                    await DB.Flush();

                    Log.Terminate();
                }
            }
        }
Esempio n. 14
0
        void runCalc(object sender, DoWorkEventArgs args)
        {
            try
            {
                if (rSimpleTiled.Checked)
                {
                    model = new SimpleTiledModel(sName.Text, stSubset.Text, (int)sWidth.Value, (int)sHeight.Value, sPeriodic.Checked, stBlack.Checked);
                }
                else if (rOverlapping.Checked)
                {
                    model = new OverlappingModel(sName.Text, (int)oN.Value, (int)sWidth.Value, (int)sHeight.Value, oPeriodicInput.Checked, sPeriodic.Checked, (int)oSymmetry.Value, (int)oGround.Value);
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            catch (Exception e)
            {
                log($"There was an error in your settings, aborting. ({e.ToString()})");
                return;
            }
            int seed = (int)numSeed.Value;

            for (int k = 0; k < sRetries.Value; k++)
            {
                bool finished = false;
                try
                {
                    finished = model.Run(seed, (int)sLimit.Value);
                }
                catch (Exception e)
                {
                    if (e is OutOfMemoryException)
                    {
                        log("Out of memory exception was thrown, try decreasing image size! Aborting.");
                        return;
                    }
                    else
                    {
                        log($"Exception was thrown, retrying. ({e.ToString()})");
                    }
                }

                if (finished)
                {
                    log("Finished");
                    img    = model.Graphics();
                    outstr = (model is SimpleTiledModel && sTextOutput.Checked) ? (model as SimpleTiledModel).TextOutput() : "";

                    break;
                }

                if (worker.CancellationPending)
                {
                    log("Cancelled");
                    return;
                }

                if (k + 1 == sRetries.Value)
                {
                    log("Contradiction, retry limit reached, aborting.");
                }
                else
                {
                    seed = random.Next();
                    log("Contradiction, retrying with random seed: " + seed);
                }
            }
        }
Esempio n. 15
0
        public static int Main(string[] args)
        {
            try {
                // The log4net section in the application's configuration file
                // requires the environment variable WORKING_DIR be set to the
                // current working directory.
                Environment.SetEnvironmentVariable("WORKING_DIR", Environment.CurrentDirectory);
                log4net.Config.XmlConfigurator.Configure();

                UI.TextWriter = Console.Out;

                string version = GetAppSetting("version");
                if (version == "")
                    throw new Exception("The application setting \"version\" is empty or blank");
                string release = GetAppSetting("release");
                if (release != "")
                    release = string.Format(" ({0})", release);
                UI.WriteLine("LANDIS-II {0}{1}", version, release);

                Assembly assembly = Assembly.GetExecutingAssembly();
                foreach (object attribute in assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false))
                    UI.WriteLine(((AssemblyCopyrightAttribute) attribute).Copyright);
                UI.WriteLine();

                if (args.Length == 0) {
                    UI.WriteLine("Error: No scenario file specified.");
                    return 1;
                }
                if (args.Length > 1) {
                    UI.WriteLine("Error: Extra argument(s) on command line:");
                    StringBuilder argsList = new StringBuilder();
                    argsList.Append(" ");
                    for (int i = 1; i < args.Length; ++i)
                        argsList.AppendFormat(" {0}", args[i]);
                    UI.WriteLine(argsList.ToString());
                    return 1;
                }

                string appDir = Application.Directory;
                PlugIns.IDataset plugIns = PlugIns.Admin.Dataset.LoadOrCreate(PlugIns.Admin.Dataset.DefaultPath);
                RasterIO.DriverManager driverMgr = new RasterIO.DriverManager(Path.Combine(appDir, "raster-drivers.xml"));
                Model model = new Model(plugIns, driverMgr);
                model.Run(args[0]);
                return 0;
            }
            catch (ApplicationException exc) {
                UI.WriteLine(exc.Message);
                return 1;
            }
            catch (Exception exc) {
                UI.WriteLine("Internal error occurred within the program:");
                UI.WriteLine("  {0}", exc.Message);
                if (exc.InnerException != null) {
                    UI.WriteLine("  {0}", exc.InnerException.Message);
                }
                UI.WriteLine();
                UI.WriteLine("Stack trace:");
                UI.WriteLine(exc.StackTrace);
                return 1;
            }
        }
Esempio n. 16
0
 public void Run()
 {
     Model.Run();
 }
Esempio n. 17
0
        private void modelBtn_Click(object sender, EventArgs e)
        {
            int modelTime = 500;

            _model = new Model(
                new ErlangGenerator(0.25d, 3),
                new PoissonGenerator(0.5d),
                new NormalGenerator(14d, 1.5d),
                new ExponentialGenerator(3d),
                new ModelTime()
            {
                Time = modelTime
            }
                );

            _model.Run();

            transactsBox.DataSource = _model.Drain.DrainedTransacts;

            var logs = _model.Drain.DrainedTransacts.SelectMany(dt => dt.GetJournal().Select(log => new ModelLog()
            {
                TransactId = dt.Id,
                Type       = dt.Type,
                Event      = log.Event,
                Time       = log.Time.Time
            })).ToList();

            logs.Sort((log1, log2) =>
            {
                int compare = log1.Time.CompareTo(log2.Time);
                if (compare == 0)
                {
                    return(((int)log1.Event).CompareTo((int)log2.Event));
                }
                return(compare);
            });
            modelLogsBox.DataSource = logs;

            transactCountLbl.Text = _model.Drain.DrainedTransacts.Count.ToString();
            avgLifeTimeLbl.Text   = (_model.Drain.DrainedTransacts.Sum(t => t.GetLifeTime())
                                     / _model.Drain.DrainedTransacts.Count).ToString();
            avgTimeInQueueLbl.Text = (_model.Drain.DrainedTransacts.Sum(t => t.GetTimeInQueue())
                                      / _model.Drain.DrainedTransacts.Count).ToString();
            avgTimeInServerLbl.Text = (_model.Drain.DrainedTransacts.Sum(t => t.GetTimeInServer())
                                       / _model.Drain.DrainedTransacts.Count).ToString();
            withoutQueueLbl.Text = ((double)_model.Drain.DrainedTransacts.Where(t => t.GetTimeInQueue() == 0).Count()
                                    / _model.Drain.DrainedTransacts.Count * 100).ToString() + "%";

            double prevTime   = 0;
            double freeTime   = 0;
            var    serverLogs = logs.Where(l => l.Event == EventTypeEnum.EnterServer || l.Event == EventTypeEnum.LeaveServer);

            foreach (var log in serverLogs)
            {
                if (log.Event == EventTypeEnum.EnterServer)
                {
                    freeTime = log.Time - prevTime;
                }
                if (log.Event == EventTypeEnum.LeaveServer)
                {
                    prevTime = log.Time;
                }
            }
            freeTimeCoefLbl.Text = (freeTime / modelTime).ToString();

            abChart.Series.FirstOrDefault().Points.Clear();
            abChart.Series.FirstOrDefault().IsValueShownAsLabel = false;
            int aCount = _model.Drain.DrainedTransacts.Where(t => t.Type == TransactTypeEnum.Atype).Count(),
                bCount = _model.Drain.DrainedTransacts.Where(t => t.Type == TransactTypeEnum.Btype).Count();

            abChart.Series.FirstOrDefault().Points.Add(new DataPoint()
            {
                Name       = "A",
                LegendText = "A " + ((double)aCount / _model.Drain.DrainedTransacts.Count).ToString("0.###") + " %",
                XValue     = aCount,
                Label      = "A",
                YValues    = new double[] { aCount }
            });
            abChart.Series.FirstOrDefault().Points.Add(new DataPoint()
            {
                Name       = "B",
                LegendText = "B " + ((double)bCount / _model.Drain.DrainedTransacts.Count).ToString("0.###") + " %",
                XValue     = bCount,
                Label      = "B",
                YValues    = new double[] { bCount }
            });

            exportBtn.Enabled = true;
        }
Esempio n. 18
0
        public static int Main(string[] args)
        {
            try {
                // The log4net section in the application's configuration file
                // requires the environment variable WORKING_DIR be set to the
                // current working directory.
                Environment.SetEnvironmentVariable("WORKING_DIR", Environment.CurrentDirectory);
                log4net.Config.XmlConfigurator.Configure();

                ConsoleInterface ci = new ConsoleInterface();

                ci.TextWriter = Console.Out;

                string version = GetAppSetting("version");
                if (version == "")
                    throw new Exception("The application setting \"version\" is empty or blank");
                string release = GetAppSetting("release");
                if (release != "")
                    release = string.Format(" ({0})", release);
                ci.WriteLine("LANDIS-II {0}{1}", version, release);

                Assembly assembly = Assembly.GetExecutingAssembly();
                foreach (object attribute in assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false))
                    ci.WriteLine(((AssemblyCopyrightAttribute) attribute).Copyright);
                ci.WriteLine();

                if (args.Length == 0) {
                    ci.WriteLine("Error: No scenario file specified.");
                    return 1;
                }
                if (args.Length > 1) {
                    ci.WriteLine("Error: Extra argument(s) on command line:");
                    StringBuilder argsList = new StringBuilder();
                    argsList.Append(" ");
                    for (int i = 1; i < args.Length; ++i)
                        argsList.AppendFormat(" {0}", args[i]);
                    ci.WriteLine(argsList.ToString());
                    return 1;
                }

                //Warn if user's computer is not using United States number format
                string decimal_separator = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
                string period = ".";
                if (decimal_separator != period)
                {
                    ci.WriteLine("Warning: The decimal separator of your system is '" + decimal_separator + "'. Most LANDIS-II");
                    ci.WriteLine("Warning: scenario files use '" + period + "' for the decimal separator. The scenario");
                    ci.WriteLine("Warning: files may not run or your results could be inaccurate.");
                    ci.WriteLine();
                }

                IExtensionDataset extensions = Landis.Extensions.Dataset.LoadOrCreate();
                //Pre-pending the GDAL directory is required to run the Console in debug mode
                //string path = Environment.GetEnvironmentVariable("PATH");
                //string newPath = "C:\\Program Files\\LANDIS-II\\GDAL\\1.9;" + path;
                //Environment.SetEnvironmentVariable("PATH", newPath);
                RasterFactory rasterFactory = new RasterFactory();
                LandscapeFactory landscapeFactory = new LandscapeFactory();
                Model model = new Model(extensions, rasterFactory, landscapeFactory);
                model.Run(args[0], ci);
                return 0;
            }
            catch (ApplicationException exc) {
                ConsoleInterface ci = new ConsoleInterface();
                ci.WriteLine(exc.Message);
                return 1;
            }
            catch (Exception exc) {

                ConsoleInterface ci = new ConsoleInterface();
                ci.WriteLine("Internal error occurred within the program:");
                ci.WriteLine("  {0}", exc.Message);
                if (exc.InnerException != null) {
                    ci.WriteLine("  {0}", exc.InnerException.Message);
                }
                ci.WriteLine();
                ci.WriteLine("Stack trace:");
                ci.WriteLine(exc.StackTrace);
                return 1;
            }
        }
Esempio n. 19
0
 public void RunTest()
 {
     mshe.Run(false, true);
 }