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