#region License Information /* HeuristicLab * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.IO; using System.Linq; using System.Reflection; using CommandLine; using HeuristicLab.Clients.Hive; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Optimization; using HeuristicLab.PluginInfrastructure; using HeuristicLab.PluginInfrastructure.Manager; namespace HiveIraceResult { class Program { private const int EXIT_OK = 0; private const int EXIT_ERR = 1; static void Main(string[] args) { //AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", "HiveIraceResult.exe.config"); var result = Parser.Default.ParseArguments(args) .WithParsed(x => { try { Environment.Exit(Initialize(x)); } catch (Exception e) { Console.Error.WriteLine(e.Message + Environment.NewLine + e.StackTrace); Environment.Exit(EXIT_ERR); } }) .WithNotParsed(x => Environment.Exit(EXIT_ERR)); } private static int Initialize(Options opts) { #if __DRY_RUN__ var random = new Random(); Console.WriteLine(random.Next(100000)); return EXIT_OK; #endif var pluginManager = new PluginManager(Path.GetDirectoryName(Environment.GetCommandLineArgs()[0])); pluginManager.DiscoverAndCheckPlugins(); var appManagerType = Assembly.GetAssembly(typeof(IPlugin)).DefinedTypes.Single(x => x.Name == "DefaultApplicationManager"); var appManager = Activator.CreateInstance(appManagerType, true); var method = appManagerType.GetMethod("PrepareApplicationDomain", BindingFlags.NonPublic | BindingFlags.Instance); method.Invoke(appManager, new object[] { pluginManager.Applications, pluginManager.Plugins }); ContentManager.Initialize(new PersistenceContentManager()); return Run(opts); } private static int Run(Options opts) { HiveClient.Instance.Refresh(); var jobName = Properties.Settings.Default.JobPrefix + " " + string.Join("-", opts.ConfigId, opts.InstanceId, opts.Seed); var job = HiveClient.Instance.Jobs.SingleOrDefault(x => x.Job.Name == jobName); if (job == null) return EXIT_ERR; HiveClient.LoadJob(job); var task = job.HiveTasks.Single(); //var job = HiveServiceLocator.Instance.CallHiveService(x => x.GetJobs()).Single(x => x.Name == jobName); //var task = HiveServiceLocator.Instance.CallHiveService(x => x.GetLightweightJobTasksWithoutStateLog(job.Id)).Single(); //var itemTask = HiveClient.LoadItemJob(task.Id); var algorithm = task.ItemTask.Item as IAlgorithm; var resultItem = algorithm.Runs.Last().Results[Properties.Settings.Default.ResultName]; try { if (resultItem is DoubleValue) { Console.WriteLine(((DoubleValue)resultItem).Value); } else if (resultItem is IntValue) { Console.WriteLine(((IntValue)resultItem).Value); } else throw new InvalidOperationException("Algorithm results does not contain " + Properties.Settings.Default.ResultName + " or is not (IntValue|DoubleValue)."); } finally { #if !__NO_DELETE__ HiveClient.Delete(job); #endif } return EXIT_OK; } } }