[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;
|
---|
[6110] | 8 | using HeuristicLab.Clients.Hive.Jobs;
|
---|
[6000] | 9 | using HeuristicLab.Common;
|
---|
| 10 | using HeuristicLab.Core;
|
---|
[6110] | 11 | using HeuristicLab.Optimization;
|
---|
[6000] | 12 | using HeuristicLab.PluginInfrastructure;
|
---|
| 13 | using HeuristicLab.PluginInfrastructure.Manager;
|
---|
| 14 | using HeuristicLab.Problems.TestFunctions;
|
---|
| 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);
|
---|
[6110] | 42 |
|
---|
[6000] | 43 | #region Credentials
|
---|
| 44 | ServiceLocator.Instance.Username = "cneumuel";
|
---|
[6006] | 45 | ServiceLocator.Instance.Password = "YouWillNeverKnow";
|
---|
[6000] | 46 | #endregion
|
---|
| 47 |
|
---|
| 48 | GeneticAlgorithm ga = new GeneticAlgorithm();
|
---|
| 49 | ga.Problem = new SingleObjectiveTestFunctionProblem();
|
---|
[6178] | 50 | ga.Engine = new HiveEngine();
|
---|
| 51 | ga.Elites.Value = 0;
|
---|
| 52 | ga.PopulationSize.Value = 4;
|
---|
[6000] | 53 | ga.MaximumGenerations.Value = 3;
|
---|
| 54 |
|
---|
[6039] | 55 | //var plugins = new List<IPluginDescription>();
|
---|
| 56 | //IEnumerable<Type> types;
|
---|
| 57 | //PersistenceUtil.Serialize(ga, out types);
|
---|
| 58 | //PluginUtil.CollectDeclaringPlugins(plugins, types);
|
---|
| 59 |
|
---|
| 60 |
|
---|
[6000] | 61 | ga.Start();
|
---|
| 62 |
|
---|
| 63 | while (ga.ExecutionState != Core.ExecutionState.Stopped && ga.ExecutionState != Core.ExecutionState.Paused) {
|
---|
| 64 | Thread.Sleep(2000);
|
---|
| 65 | Console.Clear();
|
---|
| 66 | Console.WriteLine(string.Join(Environment.NewLine, ga.Results.Select(x => x.ToString()).ToArray()));
|
---|
| 67 | Console.WriteLine("---");
|
---|
| 68 | Console.WriteLine("Log:");
|
---|
| 69 | Console.WriteLine(string.Join(Environment.NewLine, ga.Engine.Log.Messages.ToArray()));
|
---|
| 70 | }
|
---|
| 71 | Console.WriteLine("finished: " + ga.ExecutionState);
|
---|
| 72 |
|
---|
| 73 | Console.WriteLine("Storing...");
|
---|
| 74 | ContentManager.Save((IStorableContent)ga, string.Format("result_{0}.hl", DateTime.Now.ToString("yy.MM.dd HH;mm;ss")), true);
|
---|
| 75 | Console.WriteLine("Finished");
|
---|
| 76 |
|
---|
| 77 | Console.ReadLine();
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 | }
|
---|