[16667] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.IO;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Reflection;
|
---|
| 26 | using CommandLine;
|
---|
| 27 | using HeuristicLab.Clients.Hive;
|
---|
| 28 | using HeuristicLab.Common;
|
---|
| 29 | using HeuristicLab.Core;
|
---|
| 30 | using HeuristicLab.Data;
|
---|
| 31 | using HeuristicLab.Optimization;
|
---|
| 32 | using HeuristicLab.PluginInfrastructure;
|
---|
| 33 | using HeuristicLab.PluginInfrastructure.Manager;
|
---|
| 34 |
|
---|
| 35 | namespace HiveIraceResult {
|
---|
| 36 | class Program {
|
---|
| 37 | private const int EXIT_OK = 0;
|
---|
| 38 | private const int EXIT_ERR = 1;
|
---|
| 39 |
|
---|
| 40 | static void Main(string[] args) {
|
---|
| 41 | //AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", "HiveIraceResult.exe.config");
|
---|
| 42 |
|
---|
| 43 | var result = Parser.Default.ParseArguments<Options>(args)
|
---|
| 44 | .WithParsed(x => {
|
---|
| 45 | try {
|
---|
| 46 | Environment.Exit(Initialize(x));
|
---|
| 47 | } catch (Exception e) {
|
---|
| 48 | Console.Error.WriteLine(e.Message + Environment.NewLine + e.StackTrace);
|
---|
| 49 | Environment.Exit(EXIT_ERR);
|
---|
| 50 | }
|
---|
| 51 | })
|
---|
| 52 | .WithNotParsed(x => Environment.Exit(EXIT_ERR));
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | private static int Initialize(Options opts) {
|
---|
| 56 | #if __DRY_RUN__
|
---|
| 57 | var random = new Random();
|
---|
| 58 | Console.WriteLine(random.Next(100000));
|
---|
| 59 | return EXIT_OK;
|
---|
| 60 | #endif
|
---|
| 61 |
|
---|
| 62 | var pluginManager = new PluginManager(Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]));
|
---|
| 63 | pluginManager.DiscoverAndCheckPlugins();
|
---|
| 64 |
|
---|
| 65 | var appManagerType = Assembly.GetAssembly(typeof(IPlugin)).DefinedTypes.Single(x => x.Name == "DefaultApplicationManager");
|
---|
| 66 | var appManager = Activator.CreateInstance(appManagerType, true);
|
---|
| 67 | var method = appManagerType.GetMethod("PrepareApplicationDomain", BindingFlags.NonPublic | BindingFlags.Instance);
|
---|
| 68 | method.Invoke(appManager, new object[] { pluginManager.Applications, pluginManager.Plugins });
|
---|
| 69 |
|
---|
| 70 | ContentManager.Initialize(new PersistenceContentManager());
|
---|
| 71 |
|
---|
| 72 | return Run(opts);
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | private static int Run(Options opts) {
|
---|
| 76 | HiveClient.Instance.Refresh();
|
---|
| 77 |
|
---|
| 78 | var jobName = Properties.Settings.Default.JobPrefix + " " + string.Join("-", opts.ConfigId, opts.InstanceId, opts.Seed);
|
---|
| 79 | var job = HiveClient.Instance.Jobs.SingleOrDefault(x => x.Job.Name == jobName);
|
---|
| 80 | if (job == null) return EXIT_ERR;
|
---|
| 81 |
|
---|
| 82 | HiveClient.LoadJob(job);
|
---|
| 83 | var task = job.HiveTasks.Single();
|
---|
| 84 | //var job = HiveServiceLocator.Instance.CallHiveService(x => x.GetJobs()).Single(x => x.Name == jobName);
|
---|
| 85 | //var task = HiveServiceLocator.Instance.CallHiveService(x => x.GetLightweightJobTasksWithoutStateLog(job.Id)).Single();
|
---|
| 86 | //var itemTask = HiveClient.LoadItemJob(task.Id);
|
---|
| 87 | var algorithm = task.ItemTask.Item as IAlgorithm;
|
---|
| 88 | var resultItem = algorithm.Runs.Last().Results[Properties.Settings.Default.ResultName];
|
---|
| 89 |
|
---|
| 90 | try {
|
---|
| 91 | if (resultItem is DoubleValue) {
|
---|
| 92 | Console.WriteLine(((DoubleValue)resultItem).Value);
|
---|
| 93 | } else if (resultItem is IntValue) {
|
---|
| 94 | Console.WriteLine(((IntValue)resultItem).Value);
|
---|
| 95 | } else throw new InvalidOperationException("Algorithm results does not contain " + Properties.Settings.Default.ResultName + " or is not (IntValue|DoubleValue).");
|
---|
| 96 | } finally {
|
---|
| 97 | #if !__NO_DELETE__
|
---|
| 98 | HiveClient.Delete(job);
|
---|
| 99 | #endif
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | return EXIT_OK;
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 | }
|
---|