[6000] | 1 | using System;
|
---|
| 2 | using System.IO;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Reflection;
|
---|
| 5 | using System.Threading;
|
---|
| 6 | using HeuristicLab.Algorithms.GeneticAlgorithm;
|
---|
| 7 | using HeuristicLab.Clients.Hive;
|
---|
| 8 | using HeuristicLab.Common;
|
---|
| 9 | using HeuristicLab.Core;
|
---|
| 10 | using HeuristicLab.PluginInfrastructure;
|
---|
| 11 | using HeuristicLab.PluginInfrastructure.Manager;
|
---|
| 12 | using HeuristicLab.Problems.TestFunctions;
|
---|
[6033] | 13 | using HeuristicLab.Clients.Hive.Jobs;
|
---|
| 14 | using HeuristicLab.Optimization;
|
---|
[6000] | 15 |
|
---|
| 16 | namespace HeuristicLab.HiveEngine.Test {
|
---|
| 17 | public class Program {
|
---|
| 18 | static void Main(string[] args) {
|
---|
| 19 | PluginManager pm = new PluginManager(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
|
---|
| 20 | pm.DiscoverAndCheckPlugins();
|
---|
| 21 | pm.Run(pm.Applications.Where(x => x.Name == "HeuristicLab.HiveEngine.Test").SingleOrDefault());
|
---|
| 22 | }
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | [Plugin("HeuristicLab.HiveEngine.Test", "1.0.0.0")]
|
---|
| 26 | [PluginFile("HeuristicLab.HiveEngine.Test.exe", PluginFileType.Assembly)]
|
---|
| 27 | public class TestPlugin : PluginBase { }
|
---|
| 28 |
|
---|
| 29 | [Application("HeuristicLab.HiveEngine.Test")]
|
---|
| 30 | public class TestApp : ApplicationBase {
|
---|
| 31 |
|
---|
| 32 | public override void Run() {
|
---|
| 33 | ContentManager.Initialize(new PersistenceContentManager());
|
---|
| 34 |
|
---|
[6033] | 35 |
|
---|
| 36 | OptimizerJob job = new OptimizerJob(new Experiment());
|
---|
| 37 | job.IndexInParentOptimizerList = 15;
|
---|
| 38 |
|
---|
| 39 | byte[] data = PersistenceUtil.Serialize(job);
|
---|
| 40 |
|
---|
| 41 | var job2 = PersistenceUtil.Deserialize<OptimizerJob>(data);
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 |
|
---|
[6000] | 45 | #region Credentials
|
---|
| 46 | ServiceLocator.Instance.Username = "cneumuel";
|
---|
[6006] | 47 | ServiceLocator.Instance.Password = "YouWillNeverKnow";
|
---|
[6000] | 48 | #endregion
|
---|
| 49 |
|
---|
| 50 | GeneticAlgorithm ga = new GeneticAlgorithm();
|
---|
| 51 | ga.Problem = new SingleObjectiveTestFunctionProblem();
|
---|
| 52 | ga.Engine = new HiveEngine();
|
---|
| 53 | ga.PopulationSize.Value = 3;
|
---|
| 54 | ga.MaximumGenerations.Value = 3;
|
---|
| 55 |
|
---|
[6039] | 56 | //var plugins = new List<IPluginDescription>();
|
---|
| 57 | //IEnumerable<Type> types;
|
---|
| 58 | //PersistenceUtil.Serialize(ga, out types);
|
---|
| 59 | //PluginUtil.CollectDeclaringPlugins(plugins, types);
|
---|
| 60 |
|
---|
| 61 |
|
---|
[6000] | 62 | ga.Start();
|
---|
| 63 |
|
---|
| 64 | while (ga.ExecutionState != Core.ExecutionState.Stopped && ga.ExecutionState != Core.ExecutionState.Paused) {
|
---|
| 65 | Thread.Sleep(2000);
|
---|
| 66 | Console.Clear();
|
---|
| 67 | Console.WriteLine(string.Join(Environment.NewLine, ga.Results.Select(x => x.ToString()).ToArray()));
|
---|
| 68 | Console.WriteLine("---");
|
---|
| 69 | Console.WriteLine("Log:");
|
---|
| 70 | Console.WriteLine(string.Join(Environment.NewLine, ga.Engine.Log.Messages.ToArray()));
|
---|
| 71 | }
|
---|
| 72 | Console.WriteLine("finished: " + ga.ExecutionState);
|
---|
| 73 |
|
---|
| 74 | Console.WriteLine("Storing...");
|
---|
| 75 | ContentManager.Save((IStorableContent)ga, string.Format("result_{0}.hl", DateTime.Now.ToString("yy.MM.dd HH;mm;ss")), true);
|
---|
| 76 | Console.WriteLine("Finished");
|
---|
| 77 |
|
---|
| 78 | Console.ReadLine();
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 | }
|
---|