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 | OptimizerJob job = new OptimizerJob(new Experiment());
|
---|
36 | job.IndexInParentOptimizerList = 15;
|
---|
37 |
|
---|
38 | //byte[] data = PersistenceUtil.Serialize(job);
|
---|
39 |
|
---|
40 | //var job2 = PersistenceUtil.Deserialize<OptimizerJob>(data);
|
---|
41 |
|
---|
42 | #region Credentials
|
---|
43 | ServiceLocator.Instance.Username = "cneumuel";
|
---|
44 | ServiceLocator.Instance.Password = "Stormlord105.";
|
---|
45 | #endregion
|
---|
46 |
|
---|
47 | GeneticAlgorithm alg = new GeneticAlgorithm();
|
---|
48 | alg.Problem = new SingleObjectiveTestFunctionProblem();
|
---|
49 | alg.Engine = new HiveEngine() { ResourceNames = "CHRISTOPH-PC" };
|
---|
50 | alg.Elites.Value = 0;
|
---|
51 | alg.PopulationSize.Value = 10;
|
---|
52 | alg.MaximumGenerations.Value = 3;
|
---|
53 |
|
---|
54 | //var alg = ContentManager.Load("Meta-GA - Meta Optimization Problem (Genetic Programming - Symbolic Regression 3.4 scaled)_small.hl") as GeneticAlgorithm;
|
---|
55 | //alg.Engine = new HiveEngine() { ResourceNames = "CHRISTOPH-PC" };
|
---|
56 | //alg.PopulationSize.Value = 2;
|
---|
57 | //((MetaOptimizationProblem)alg.Problem).Repetitions.Value = 5;
|
---|
58 |
|
---|
59 | alg.Start();
|
---|
60 |
|
---|
61 | while (alg.ExecutionState != Core.ExecutionState.Stopped && alg.ExecutionState != Core.ExecutionState.Paused) {
|
---|
62 | Thread.Sleep(2000);
|
---|
63 | Console.Clear();
|
---|
64 | Console.WriteLine(string.Join(Environment.NewLine, alg.Results.Select(x => x.ToString()).ToArray()));
|
---|
65 | Console.WriteLine("---");
|
---|
66 | Console.WriteLine("Log:");
|
---|
67 | Console.WriteLine(string.Join(Environment.NewLine, alg.Engine.Log.Messages.ToArray()));
|
---|
68 | var exps = ((HiveEngine)alg.Engine).HiveExperiments;
|
---|
69 | foreach (var exp in exps) {
|
---|
70 | Console.WriteLine("# " + exp.ToString());
|
---|
71 | Console.WriteLine(string.Join(Environment.NewLine, exp.Log.Messages.ToArray()));
|
---|
72 | }
|
---|
73 | }
|
---|
74 | Console.WriteLine("finished: " + alg.ExecutionState);
|
---|
75 |
|
---|
76 | Console.WriteLine("Storing...");
|
---|
77 | ContentManager.Save((IStorableContent)alg, string.Format("result_{0}.hl", DateTime.Now.ToString("yy.MM.dd HH;mm;ss")), true);
|
---|
78 | Console.WriteLine("Finished");
|
---|
79 |
|
---|
80 | Console.ReadLine();
|
---|
81 | }
|
---|
82 | }
|
---|
83 | }
|
---|