Пример #1
0
        public void Run(SimulationArgs args)
        {
            Random = new Random(args.Seed);

            ScheduleEvent(StartingEventType, 0, 0, ParseStartParameters(args.StartParameterValues));

            bool traceToConsole = !args.Silent;

            using StreamWriter outputWriter = args.OutputFile is not null ? new StreamWriter(new FileStream(args.OutputFile, FileMode.Create), Encoding.UTF8) : null;

            StartTraceHeader(traceToConsole, outputWriter);
            TraceExpressionHeaders(traceToConsole, outputWriter);
            EndTraceLine(traceToConsole, outputWriter);

            while (_schedule.Count > 0 && _clock < args.StopCondition.MaxTime)
            {
                var entry = _schedule[0];
                _schedule.RemoveAt(0);

                _clock = entry.Time;

                ProcessEvent(entry.EventType, entry.ParameterValues);

                StartTrace(traceToConsole, outputWriter, entry.EventType);
                TraceExpressionValues(traceToConsole, outputWriter);
                EndTraceLine(traceToConsole, outputWriter);
            }
        }
Пример #2
0
        static SimulationArgs ParseArgs(string[] args)
        {
            var simArgs     = new SimulationArgs();
            var startValues = new List <string>();

            for (int i = 0; i < args.Length - 1; i++)
            {
                switch (args[i].ToLower())
                {
                case "-o":
                case "--output-file":
                    simArgs.OutputFile = args[++i];
                    break;

                case "--seed":
                    simArgs.Seed = int.Parse(args[++i]);
                    break;

                case "--silent":
                    simArgs.Silent = true;
                    break;

                case "--start-parameter":
                    startValues.Add(args[++i]);
                    break;

                case "--stop-time":
                    simArgs.StopCondition.MaxTime = double.Parse(args[++i]);
                    break;

                default:
                    throw new Exception($"Did not recognize option \"{args[i]}\"");
                }
            }

            if (startValues.Count > 0)
            {
                simArgs.StartParameterValues = startValues.ToArray();
            }

            return(simArgs);
        }