Ejemplo n.º 1
0
        public static void HandleJenkinsCall(string[] args)
        {
            // On invalid arguments show info
            if (args.Length != CliArgs.Length)
            {
                Console.WriteLine("Usage: RAWSimO.CLI.exe " + string.Join(" ", CliArgs.Select(a => "<" + a.Item1 + ">")));
                Console.WriteLine("Parameters:");
                foreach (var item in CliArgs)
                {
                    Console.WriteLine(item.Item1 + ": " + item.Item2);
                }
                Console.WriteLine("Actual call's arguments were: " + string.Join(" ", args));
                return;
            }

            // Say hello
            Console.WriteLine("<<< Welcome to the RAWSimO Jenkins Handler >>>");

            // Echo the arguments passed
            Console.WriteLine("Starting RAWSimO wrapper with the following arguments:");
            for (int i = 0; i < CliArgs.Length; i++)
            {
                Console.WriteLine(CliArgs[i].Item1 + ": " + args[i]);
            }

            // Setup instance
            Console.Write("Initializing ... ");
            int             seed        = int.Parse(args[4]);
            string          buildNumber = args[5];
            Action <string> logAction   = (string message) => { Console.WriteLine(message); };
            Instance        instance    = InstanceIO.ReadInstance(args[0], args[1], args[2], logAction: logAction);

            instance.SettingConfig.LogAction           = logAction;
            instance.SettingConfig.Seed                = seed;
            instance.SettingConfig.StatisticsDirectory = Path.Combine(args[3], instance.Name + "-" + instance.SettingConfig.Name + "-" + instance.ControllerConfig.Name + "-" + instance.SettingConfig.Seed.ToString());
            instance.Randomizer = new RandomizerSimple(seed);
            Console.WriteLine("Done!");
            // Deus ex machina
            Console.WriteLine("Executing ... ");
            DateTime before = DateTime.Now;

            SimulationExecutor.Execute(instance);
            TimeSpan executionTime = DateTime.Now - before;

            Console.WriteLine("Simulation finished.");
            // Write short statistics to output
            instance.PrintStatistics((string s) => Console.WriteLine(s));
            // Log the evaluation statistics
            AppendStatLine(instance, seed, buildNumber, executionTime);
            // Finished
            Console.WriteLine(".Fin. - SUCCESS");
        }
        private void Run()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            //define the problems to optimize
            ProblemSuite problemSuite = new ProblemSuite();

            problemSuite.AddFunction(() => new AbsoluteValue(), new Domain(-100, 100, dimensions), "Absolute Value");
            problemSuite.AddFunction(() => new Spherical(), new Domain(-5.12, 5.12, dimensions), "Spherical");
            problemSuite.AddFunction(() => new Rastrigin(), new Domain(-5.12, 5.12, dimensions), "Rastrigin");

            //we can also add shifted and rotated functions quite easily!
            //problemSuite.AddRotatedFunction(() => new Ackley(), RotationType.Orthonormal, new Domain(-32.768, 32.768, dimensions), "Rotated Ackley");
            //problemSuite.AddShiftedFunction(() => new Spherical(), new ConstantControlParameter(-450), new ConstantControlParameter(10), new Domain(-5.12, 5.12, dimensions), "Shifted Spherical")

            //define the measurement suite to use
            MeasurementSuite measurementSuite = new MeasurementSuite();

            measurementSuite.Add(new Fitness(), "Fitness");
            measurementSuite.Add(new Diversity(), "Diversity");
            measurementSuite.Add(new AverageParticleMovement(), "Average Particle Movement");
            measurementSuite.Add(new BoundViolations(), "Bound Violations");

            //create the executor and have it execute the simulations
            SimulationExecutor executor = new SimulationExecutor();

            //defining a Func<IProblem, IAlgorithm> is the simplest way to go as it allows directly passing your problem suite
            executor.Execute((p) => CreatePSO(p), problemSuite, measurementSuite, runs, "PSO", "Output");

            //alternatively, you can define a Func<IAlgorithm> and manually execute each simulation

            /*foreach (var kvp in problemSuite.Problems)
             * {
             *  run a simulation by explicitly creating a Func<IAlgorithm>
             *  executor.Execute(() => CreatePSO(kvp.Value), measurementSuite, sims, "PSO", Path.Combine("Output", kvp.Key));
             *
             *  alternatively, you can pass a Func<IAlgorithm> if you wish
             *  executor.Execute(CreatePSOFunc(problem), measurements, sims, "PSO", Path.Combine("Output", kvp.Key));
             * } */
            stopwatch.Stop();
            Console.WriteLine($"Elapsed Time: {stopwatch.Elapsed}");
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            // On invalid arguments show info
            if (args.Length < CliArgs.Length || args.Length > CliArgs.Length + 1)
            {
                LogLine("Usage: RAWSimO.CLI.exe " + string.Join(" ", CliArgs.Select(a => "<" + a.Item1 + ">")));
                LogLine("Parameters:");
                foreach (var item in CliArgs)
                {
                    LogLine(item.Item1 + ": " + item.Item2);
                }
                LogLine("Actual call's arguments were: " + string.Join(" ", args));
                LogLine("Note: you may add one additional and last argument as a tag");
                return;
            }

            // Say hello
            LogLine("<<< Welcome to the RAWSimO CLI >>>");
            LogLine("The time is: " + DateTime.Now.ToString(IOConstants.FORMATTER));

            // Echo the arguments passed
            LogLine("Starting RAWSimO wrapper with the following arguments:");
            for (int i = 0; i < CliArgs.Length; i++)
            {
                LogLine(CliArgs[i].Item1 + ": " + args[i]);
            }

            // Check for tag argument
            if (args.Length == CliArgs.Length + 1)
            {
                LogLine("Additionally the following tag was passed: " + args[CliArgs.Length]);
            }

            // Catch unhandled exceptions
            if (!AppDomain.CurrentDomain.FriendlyName.EndsWith("vshost.exe"))
            {
                LogLine("Adding handler for unhandled exceptions ...");
                var handler = new UnhandledExceptionHandler()
                {
                    Instance      = args[0],
                    SettingConfig = args[1],
                    ControlConfig = args[2],
                    Seed          = args[4],
                    LogAction     = LogLine,
                    Tag           = ((args.Length == CliArgs.Length + 1) ? args[CliArgs.Length] : null)
                };
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(handler.LogUnhandledException);
            }

            // Setup instance

            LogLine("Initializing ... ");
            int seed = int.Parse(args[4]);

            LogLine("Bug is here.");
            Action <string> logAction = (string message) => { LogLine(message); };

            Instance instance = InstanceIO.ReadInstance(args[0], args[1], args[2], logAction: logAction);

            instance.SettingConfig.LogAction = logAction;
            instance.SettingConfig.Seed      = seed;
            if (args.Length == CliArgs.Length + 1)
            {
                instance.Tag = args[CliArgs.Length];
            }
            string statisticsFolder = instance.Name + "-" + instance.SettingConfig.Name + "-" + instance.ControllerConfig.Name + "-" + instance.SettingConfig.Seed.ToString();

            instance.SettingConfig.StatisticsDirectory = Path.Combine(args[3], statisticsFolder);
            LogLine("StatisticsFolder: " + statisticsFolder);
            instance.Randomizer = new RandomizerSimple(seed);
            LogLine("Done!");
            // Setup log to disk
            if (!Directory.Exists(instance.SettingConfig.StatisticsDirectory))
            {
                Directory.CreateDirectory(instance.SettingConfig.StatisticsDirectory);
            }
            _logWriter = new StreamWriter(Path.Combine(instance.SettingConfig.StatisticsDirectory, IOConstants.LOG_FILE), false)
            {
                AutoFlush = true
            };
            // Deus ex machina
            LogLine("Executing ... ");
            SimulationExecutor.Execute(instance);
            LogLine("Simulation finished.");

            // Write short statistics to output
            instance.PrintStatistics((string s) => LogLine(s));
            // Mark tag as finished, if available
            if (instance.Tag != null)
            {
                MarkTagFinished(args[3], args[0], args[1], args[2], args[4], instance.Tag);
            }
            // Finished
            LogLine(".Fin. - SUCCESS");
        }
Ejemplo n.º 4
0
 public static void ExecuteInstance(Instance instance)
 {
     // Deus ex machina
     SimulationExecutor.Execute(instance);
 }